Reputation: 1
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:
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
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 :
Upvotes: 0