如何检测Google DFP广告管理系统DFP广告的加载状态? [英] How to detect loading state of a Google Doubleclick for Publishers DFP Ad?

查看:184
本文介绍了如何检测Google DFP广告管理系统DFP广告的加载状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在页面上有一系列DFP广告,每当用户单击图库查看器上的每个缩略图图标时,就会使用javascript refresh()调用自动刷新这些DFP广告:

We have a series of DFP ads on a page that get refreshed automatically using the javascript refresh() call each time a user clicks each thumbnail icon on a gallery viewer:

googletag.pubads().refresh();

问题是,如果用户快速浏览图库,每次点击都会使广告不断刷新

The problem is that if a user clicks through the gallery quickly, the ads keep refreshing for every click so that eventually blank ads can occur as the system is unable to keep up with the user clicks.

因此,我想仅在广告完全完成后才调用刷新,最终会出现空白广告。

Hence I'd like to only call refresh only if the ad has completely finished loading.

有没有办法检测广告位中广告的加载状态?

Is there any way of detecting the loaded state of an ad within a slot?

我们的广告的定义如下:

Our ads are defined using:

slot_header_lge = googletag.defineSlot('/XXX/Header-Home-Large', [945, 230], 'div-gpt-ad-Header-Large').addService(googletag.pubads());

googletag.pubads().enableAsyncRendering();
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();


推荐答案

我做了 jquery插件,它包装了DFP广告管理系统,不久前又提出了解决此问题的方法...内部有一个功能您可以将其插入名为renderEnded()的广告单元中,以检查广告单元何时已呈现。

I made a jquery plugin that wraps DFP and kind of came up with a solution to this problem a while back... there is an internal function on the ad unit called renderEnded() that you can hook into to check when the ad unit has been rendered.

根据我的经验,这只是意味着HTML代码已经放入页面...,并不一定意味着广告已完全加载完毕。您可以将一些timeOuts与之结合使用,从而获得一个相当健壮的系统。

In my experience this just means that the HTML code has been put into the page... and not necessarily that the ad has completely finished loading. You could combine some timeOuts with this to get a fairly robust system going though.

例如,对于我的插件,您可以尝试以下操作,但不应允许广告刷新直到页面上的最后一个广告呈现后5秒:

For example with my plugin you can try the following, it shouldn't allow ads to be refreshed until 5 seconds after the last ad on the page has rendered:

<!DOCTYPE html>
<html>
<head>
    <title>TEST</title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://coop182.github.io/jquery.dfp.js/jquery.dfp.js"></script>

</head>
<body>

Test DFP Ads.

<div class="adunit" id="buyingcars_ATF_728x90" data-dimensions="728x90"></div>

<script>

    var adsLoaded = true;

    function checkLoading() {

        console.log('Checking...');

        if (adsLoaded) {
            loadAds();
        }
    }

    function loadAds() {

        console.log('Loading...');

        adsLoaded = false;

        $.dfp({
            dfpID: '3853655',
            afterAllAdsLoaded: function() {
                setTimeout(function(){adsLoaded = true;}, 5000);
            }
        });
    }

    checkLoading();

</script>

<a href="#" onclick="checkLoading();">Refresh</a>

</body>
</html>

这篇关于如何检测Google DFP广告管理系统DFP广告的加载状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆