DFP广告管理系统广告代码未使用动态DIV注入进行渲染

时间:2022-11-26 08:20:20

Loading the Dynamic Rotator Kind of Dynamic HTML Style appended into the body using the Ajax Call. The ADs DIV ID will be appended dynamically into the body of the Rotator in the Collapsed Mode.

加载动态旋转器使用Ajax调用附加到正文中的一种动态HTML样式。 ADs DIV ID将以折叠模式动态附加到Rotator的主体中。

Using DFP Iframe Ads with size 180x150

使用尺寸为180x150的DFP Iframe广告

On Initial Page Load Not Having the DIV ID in the Web Page Source.

在初始页面加载中没有Web页面源中的DIV ID。

I have an Scenario of Appending the DIV Id's Dynamically into the body of the web Page through Ajax Call.

我有一个方案,通过Ajax Call将DIV Id动态地附加到Web页面的主体中。

Code Flow:

Added the GPT Library Inclusion inside the HEAD Tag of the Web Page.

在网页的HEAD标记内添加了GPT库包含。

<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> 
</head>

AS well Defining the SLOT in the cmd.push() method in the HEAD Tag which will make the Call to the DFP Server. Disabled the Initial Load ,because the define slot will check for the DIV ID during the initial page load which throws error.

同样在HEAD标记中的cmd.push()方法中定义SLOT,该标记将调用DFP Server。禁用初始加载,因为定义槽将在初始页面加载期间检查DIV ID,从而引发错误。

<head>
<script type='text/javascript'>
var slot1 = '';
googletag.cmd.push(function() {
slot1 = googletag.defineSlot('/12638013/Connect_180x150', [180, 150], 'div-gpt-ad-  1389885200465-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.pubads().disableInitialLoad();
googletag.enableServices();
}); 
</script>
</head>

Once the Page get Loads with the above scripts in the HEAD Tag.Through Ajax Call appending the DIV ID into the body of the web page.

一旦页面获取加载HEAD标记中的上述脚本。通过Ajax调用将DIV ID附加到网页正文中。

jQuery('body').append('<div id="div-gpt-ad-1389885200465-0" style="width:180px;    height:150px;"><script type="text/javascript">googletag.cmd.push(function() { googletag.display("div-gpt-ad-1389885200465-0"); });</script></div>');

After the DIV ID is rendered Dynamically into the web page. Do an Refresh of the ads slot defined in the HEAD Tag.

将DIV ID动态呈现到网页中之后。刷新HEAD标记中定义的广告位。

googletag.pubads().refresh([slot1]);

End Result:

Verified the Above Page with the Google Debug Console.

使用Google调试控制台验证了以上页面。

The Page Request goes without any errors, states that Page Tagged Correctly.

页面请求没有任何错误,表明页面标记正确。

852 ms to render page 491 ms to fetch ads 0 ms to render ads

852毫秒呈现页面491毫秒来获取广告0毫秒来呈现广告

Status  Time    Description
Information Start   Created slot: /12638013/Connect_180x150_0
Information 1 ms    Google service JS loaded
Information 1 ms    Created service: publisher_ads
Information 1 ms    Associated service "publisher_ads" with slot   "/12638013/Connect_180x150".
Information 2 ms    Using single request mode to fetch ads.
Information 2 ms    Fetching GPT PubAds implementation
Information 2 ms    Invoked queued function. Total: 1. Errors: 0.
Information 57 ms   GPT implementation fetched.
Information 759 ms  Calling fillslot.
Information 773 ms  Invoked queued function. Total: 2. Errors: 0.
Information 852 ms  Page load complete
Information 7090 ms Refreshing ads.
Information 7135 ms Fetching ad for slot: /12638013/Connect_180x150
Information 7626 ms Receiving ad for slot: /12638013/Connect_180x150
Information 7626 ms Rendering ad for slot: /12638013/Connect_180x150
Information 7626 ms Completed rendering ad for slot: /12638013/Connect_180x150

But the Ads Not Rendered inside the rotator into which the DIV is dynamically injected.

但是在动态注入DIV的旋转器内部没有呈现的广告。

Anything I missing out ? Suggestions will be useful for me.

我错过了什么?建议对我有用。

1 个解决方案

#1


3  

Was having the same issue myself for ages.... then I found this: https://plugins.jquery.com/dfp/

自己多年来一直有同样的问题....然后我发现了这个问题:https://plugins.jquery.com/dfp/

You can basically drop all the Google JS and use the 2-3 line solution provided. The only obstacle I came up against was missing the "enableSingleRequest" option.... needed to set it to false if you're loading ads more than once on a page.

您基本上可以删除所有Google JS并使用提供的2-3行解决方案。我遇到的唯一障碍是缺少“enableSingleRequest”选项....如果您在页面上多次加载广告,则需要将其设置为false。

#1


3  

Was having the same issue myself for ages.... then I found this: https://plugins.jquery.com/dfp/

自己多年来一直有同样的问题....然后我发现了这个问题:https://plugins.jquery.com/dfp/

You can basically drop all the Google JS and use the 2-3 line solution provided. The only obstacle I came up against was missing the "enableSingleRequest" option.... needed to set it to false if you're loading ads more than once on a page.

您基本上可以删除所有Google JS并使用提供的2-3行解决方案。我遇到的唯一障碍是缺少“enableSingleRequest”选项....如果您在页面上多次加载广告,则需要将其设置为false。