- Criteria
- Data layer
- Targeting
- Google Ad Manager set-up
- Testing
- Debugging
- Demo
- Documentation
- Target using information from data layer
- Target by navcode, storycode, url anything else
- Use custom functions to get data and use
googletag
setTargeting
method to pass to GAM
We output the dataLayer
object which contains the data needed from stories / navigation, logged in / out. This is then picked up by various functions and then passed down to GAM for targeting.
- Two-step
- data has to come from site and passed to GAM
- GAM matches line-item with criteria and serves ad-unit
In WebVision CMS add the below functions to Global_JavaScript Head page text.
<script> function getDataLayerVal(keyVal) { for (var i = 0; i < window.dataLayer.length; i++) { if (dataLayer[i][keyVal] !== undefined) { return dataLayer[i][keyVal]; } } } function getFullNavPath() { if(getArrayVal('FullNavPath') !== undefined) { getArrayVal('FullNavPath').split('|').join(' ').trim(); } } function isMicrosite() { return document.body.classList.contains('microsite') } </script>
Targeting can be done by calling getDataLayerVal
function and passing a value of what to look for in the data layer e.g. getDataLayerVal('LoggedIn')
which will return either 'True'
or 'False'
. This data can then be used in GAM to target specific line-items.
The same process can be used for other items needing to be targeted with the data layer.
googletag.pubads().setTargeting('navcode', getDataLayerVal('NavCode'));
The data passed to GAM will be the type of string
and will be numerical e.g. "13609"
googletag.pubads().setTargeting('storycode', getDataLayerVal('StoryID'));
If you are on a story page the data passed to GAM will be the type of string
and will be numerical e.g. "1003404"
. Otherwise, the value will be undefined
.
googletag.pubads().setTargeting('slug', document.location.pathname.substr(document.location.pathname.lastIndexOf('/')));
This will return a string that will be the value from the last forward slash from the url e.g. "/1051.bio". This is useful for non-spin and non-article related pages for example, biography and contacts.
googletag.pubads().setTargeting('FullNavPath', getFullNavPath());
This requires a custom function to pass the value in a transformed way that Ad manager can then consume. GAM should then use this with a match filter using the tilde symbol ~.
googletag.pubads().setTargeting('isMicrosite', isMicrosite());
This function checks and returns a Boolean (true or false) if the page being viewed is a microsite. This can be used in combination with navcode or event fullnavpath to apply targeting.
Terminology
- Ad-unit
- Line-items
- Creatives
- Creative template
Once targeting has been set we need to create a new key
in GAM, collect the value passed i.e. 'True'
or 'False'
and add that as a targeting criteria to the line-item
Often you may need to debug why some targeting insn't working. For that we can use the debugger. Using this will allow you to see why a certain line-tem that you've targeted ins't working.
You will only need to follow the below steps if a new targeting criteria is going to be set-up. Often the default NavCode
, StoryID
and LoggedIn
are more than sufficient to target articles / spin pages in GAM
- create a new function to pass the information to
googletag
- use
setTargeting
to pass the data to GAM with a key - in GAM create a new key that matches in step 2 above
- add the key to the line-item using the targeting criteria
- Help center
- Jira
- How ad selection works