【发布时间】: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