【问题标题】:Pass query string into Google Publisher Tag将查询字符串传递到 Google 发布商代码
【发布时间】:2015-05-05 22:51:55
【问题描述】:

我需要将当前网址中的查询字符串传递到 GPT(Google 发布商代码)中,该 GPT(Google 发布商代码)将在页面加载时调用 DFP。

例如,如果这是 URL: http://example.net/article/100-days.html?c=xyz

我需要将 c=xyz 作为键值插入。我有超过 50 组这些 c= 查询字符串,并且需要 GPT 调用针对出现的任何字符串的广告(无论是 c=xyz 还是 c=abc,等):

<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's 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>

我认为这需要一个 get 函数,但我不确定在 JS 中最有效的方法是什么。

【问题讨论】:

    标签: javascript query-string key-value google-dfp


    【解决方案1】:

    从这里尝试答案: How can I get query string values in JavaScript?

    类似:

    googletag.pubads().setTargeting( 'c', getParameterByName('c') );
    

    【讨论】:

      猜你喜欢
      • 2011-03-13
      • 2016-05-22
      • 1970-01-01
      • 2017-05-15
      • 1970-01-01
      • 2019-10-18
      • 1970-01-01
      • 2016-07-29
      • 2020-07-31
      相关资源
      最近更新 更多