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:

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.):


 <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:") + "//";
     var node =document.getElementsByTagName("script")[0];
     node.parentNode.insertBefore(gads, node);

 <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.



I think it requires a get function, but I'm not sure what is the most efficient way to do it in JS.


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') );




All Articles