Skip query string to google publisher tag
I need to pass a query string from the current url to a GPT (google publisher tag) that will call DFP on page load.
For example, if this is the url: http://example.net/article/100-days.html?c=xyz
I need to enter c = xyz as the key value. I have over 50 sets of these c = query strings and requires GPT to invoke a declaration targeting any string (be it c = xyz or c = abc, etc.):
<head>
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement("script");
gads.async = true;
gads.type = "text/javascript";
var useSSL = "https:" == document.location.protocol;
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js";
var node =document.getElementsByTagName("script")[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type="text/javascript">
googletag.cmd.push(function() {
googletag.defineSlot('/6355419/Travel/Europe/France/Paris',[300, 250], "banner1"); // adds the first slot with it own slot level custom targeting
googletag.pubads().setTargeting("c","xyz"); // adds custom targeting that applies to the entire page - i.e. all the slots on the page.
googletag.enableServices();
});
</script>
</head>
I think it requires a get function, but I'm not sure what is the most efficient way to do it in JS.
+3
source to share
1 answer
Try the answer here: How to get query string values ββin JavaScript?
Something like:
googletag.pubads().setTargeting( 'c', getParameterByName('c') );
+1
source to share