如何在 Google AdManager 中设置键值来跟踪回访用户?

问题描述 投票:0回答:1

我想设置一个像“returned_user”这样的键值,它具有 true 或 false 值,指示用户是否在一个月内第一次访问该网站。

Google Admanager 中没有此类预定义定位,因此

我目前看到的逻辑是:

  1. 在 cookie 中传递有关用户状态的数据(如果他/她是回访用户)
  2. 从cookie中获取用户inf并通过键值传递给Google Admanager

我似乎不知道如何做到这一点,并且不确定根据 Google 条款是否可行。

有谁知道如何实现这一目标?也许有一些关于该主题的文档?

谢谢!

cookies google-ad-manager targeting
1个回答
0
投票

您可以检索 cookie 值并定义自定义键/值定位。 假设您删除了一个 cookie“userVisited=true”

 <script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
    <script>
    function getCookieValue(name) {
      const regex = new RegExp(`(^| )${name}=([^;]+)`)
      const match = document.cookie.match(regex)
      if (match) {
        return match[2]
      }
     }
     //retrieve user status based on the cookievalue
     var returnedUserValue = (getCookieValue("userVisited") === "true")? true : false ;
    
      window.googletag = window.googletag || { cmd: [] };
      
      // GPT slots
      let adSlots = [];
    
      googletag.cmd.push(() => {
        // Configure slot-level targeting.
        adSlots[0] = googletag
          .defineSlot("/6355419/Travel/Asia", [728, 90], "banner-ad-1")
          .addService(googletag.pubads())
          .setTargeting("position", "atf");
    
        // Configure page-level targeting.
        googletag.pubads().setTargeting("interests", "basketball");
    
        if(returnedUserValue) {
          googletag.pubads().setTargeting("returnedUser", "true");
        }
    
        // Enable SRA and services.
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
      });
    </script>

代码示例和 setTargetings 的用法来自此处。 请注意以下事项:

  • 仅允许字符串作为键的值。
  • 在某些地区,未经用户同意,您不得删除和使用cookie。
© www.soinside.com 2019 - 2024. All rights reserved.