【问题标题】:how can target specific URLs in my website with DFP (House)如何使用 DFP(内部)定位我网站中的特定网址
【发布时间】:2021-12-23 20:42:54
【问题描述】:

我在 AnguarJs 应用程序中实现并使用 Javascript,所以请帮助我如何在我们的代码中传递动态 url(页面名称)。

<script>
        window.googletag = window.googletag || { cmd: [] };
        googletag.cmd.push(function () {
            var pathname = window.parent.location.pathname;
            var length = 40;`enter code here`
            var url = pathname.substring(1, length).replace(/[!@#$%^&*/()_-]/g, "");
            googletag.defineSlot('/14616973/cbcs_dt_1_728x90_1', [728, 90], 'div-gpt-ad-1604917677506-1').addService(googletag.pubads());
            googletag.defineSlot('/14616973/cbcs_dt_2_728x90_2', [728, 90], 'div-gpt-ad-1604917677506-2').addService(googletag.pubads());
            googletag.defineSlot('/14616973/cbcs_dt_3_300x250_1', [300, 250], 'div-gpt-ad-1604917677506-3').addService(googletag.pubads());
            googletag.defineSlot('/14616973/cbcs_dt_4_300x600_1', [300, 600], 'div-gpt-ad-1604917677506-4').addService(googletag.pubads());
            googletag.defineSlot('/14616973/cbcs_mb_1_300x250_1', [300, 250], 'div-gpt-ad-1604918658528-1').addService(googletag.pubads());
            googletag.defineSlot('/14616973/cbcs_mb_1_300x250_2', [300, 250], 'div-gpt-ad-1604918658528-2').addService(googletag.pubads());
            googletag.defineSlot('/14616973/cbcs_mb_3_300x600_3', [300, 600], 'div-gpt-ad-1604918658528-3').addService(googletag.pubads());
            googletag.pubads().setTargeting('Sub_Category', []).setTargeting('Cat', []).setTargeting('url', [url]).setTargeting('search', []).setTargeting('Page', []);
            googletag.pubads().collapseEmptyDivs();
            googletag.enableServices();
        });
    </script>

【问题讨论】:

    标签: javascript dynamic ads


    【解决方案1】:

    详细here,如果你的键有一个值,你应该发送一个字符串:

    var pathname = window.parent.location.pathname;
    var length = 40;
    var url = pathname.substring(1, length).replace(/[!@#$%^&*/()_-]/g, "");
    
    ..
    googletag.pubads().setTargeting('url', url);
    

    为了能够定位特定页面,您还可以将页面或内容 ID 传递给 GPT:它可以避免重复,因为值的 40 个字符长度限制可能最终会导致不同页面的值相似...(它取决于您的页面 URL 的构建方式)。

    【讨论】:

      猜你喜欢
      • 2015-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多