DFP:获取当前点击后到达网址

问题描述 投票:0回答:3

我正在为多个网站设置 DFP 广告管理系统,我们有一组订单项,对于其中的每个广告素材,当前点击将前往

example.com
(我们自己的
.com
网站),但由于我们正在运行多个TLD,我们还希望点击后到达 URL 能够相应更改。例如,当广告在
.jp
中展示时,点击应该转到
.jp

在 DFP API 参考中,有一个更改点击后到达网址的函数: http://support.google.com/dfp_premium/bin/answer.py?hl=en&answer=1650154&expand=adslot_details#setClickUrl

但是为了更改我们的点击 URL,我们还需要知道当前 URL 是什么。示例:我们需要从 DFP

http://www.example.com/products/1
获取
adSlot
才能将其更改为
http://www.example.jp/products/1

我使用 chrome web JS 控制台进行了反复试验,发现

getClickUrl()
类中有一个
adSlot
函数,但它一直返回空字符串,例如:

googletag.defineSlot("/1234/Test_300x250", [300, 250], 'div-1').getClickUrl();
googletag.defineSlot("/1234/Test_300x250", [300, 250], 'div-1').addService(googletag.pubads()).getClickUrl();

有人有这方面的经验吗?

google-dfp
3个回答
2
投票

如果您可以控制广告素材,我认为通过传递自定义变量会容易得多。您可以使用 setTargeting 方法传递自定义变量。因此,用于显示广告的客户端代码将如下所示:

googletag.defineSlot("/1234/Test_300x250", [300, 250], 'div-1').setTargeting('region','jp');

然后在 HTML 广告素材中使用模式宏来替换部分点击后到达网址。

<a href="http://www.example.%%PATTERN:region%%">
<img src="http://www.example.%%PATTERN:region%%/image.jpeg">
</a>

DFP 广告管理系统会将宏替换为您通过 setTargeting 传递的任何值。


0
投票

我还没有找到一种超级简单的方法来做到这一点 - 但这是可能的。

基本上,您可以覆盖 DFP 广告管理系统中的内部函数,并通过进入 iframe 的 DOM 来捕获广告内容(和网址)。

这里是一个应该提醒广告网址的示例(我只在 Chrome 中测试过这个,因此可能需要调整才能在多个浏览器中工作)

<html>
<head>
    <title>DFP test</title>

    <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() {
            var slot1 = googletag.defineSlot('/12345678/Test_300x250', [300, 250], 'div-gpt-ad-1340819095858-0').addService(googletag.pubads());

            slot1.oldRenderEnded = slot1.renderEnded;
            slot1.renderEnded = function(){
                alert(document.getElementById('div-gpt-ad-1340819095858-0').getElementsByTagName('iframe')[0].contentWindow.document.getElementsByTagName('a')[0].href.replace(/^.*&adurl=/,''));
                slot1.oldRenderEnded();
            };

            googletag.pubads().enableSingleRequest();
            googletag.enableServices();
        });
    </script>

</head>
<body>

    <div id='div-gpt-ad-1340819095858-0' style='width:266px; height:115px;'>
        <script type='text/javascript'>
            googletag.cmd.push(function() {
                googletag.display('div-gpt-ad-1340819095858-0');
            });
        </script>
    </div>

</body>
</html>

如果你使用 jQuery,使用类似以下的东西会更好:

$(adUnit).find('iframe:first').contents().find('a')

有任何问题请告诉我。


0
投票

欲了解最新和突发新闻,请关注https://dailymagazine.com.pk/

© www.soinside.com 2019 - 2024. All rights reserved.