Roman Oleksiii
Roman Oleksiii

Reputation: 1

How can I set a key value in Google AdManager for tracking returning users?

I'd like to set up a key value like "returned_user" that has a true of false value indicating whether user visits the site for the first time in a month.

There is no such predefined targeting in Google Admanager, so

The logic I see at the moment is:

  1. To pass data in cookies about the user status (if he/she is a returning user)
  2. To get the user inf from cookies and pass it to Google Admanager through the key value

I can't seem to figure out how to do this and not sure if it is possible at all according to the Google terms.

Does anyone know how to achieve this? Maybe there is some documentation for the subject?

Thank you!

Upvotes: 0

Views: 27

Answers (1)

rabsom
rabsom

Reputation: 859

You could retrieve the cookie value and define a custom key/value targeting. Let's assume you dropped a 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>

Code sample and usage of setTargetings from here. Please note the followings :

  • only strings are allowed as values of keys.
  • in some areas, you are not allowed to drop and use cookies without the user's consent.

Upvotes: 0

Related Questions