लोड स्क्रिप्ट देखें अपने पेज के अनुभाग:
// can be moved as well in the body
// if using async mode, wrap all the javascript into googletag.cmd.push!
googletag.cmd.push(function() {
// set page-level attributes for ad slots that serve AdSense
googletag.pubads().set("adsense_background_color", "FFFFFF");
googletag.pubads().setTargeting("topic","basketball");
// enables Single Request Architecture (SRA)
googletag.pubads().enableSingleRequest();
// Disable initial load, we will use refresh() to fetch ads.
// Calling this function means that display() calls just
// register the slot as ready, but do not fetch ads for it.
googletag.pubads().disableInitialLoad();
// Collapses empty div elements on a page when there is no ad content to display.
googletag.pubads().collapseEmptyDivs();
// Enables all GPT services that have been defined for ad slots on the page.
googletag.enableServices();
});
रजिस्टर स्लॉट्स व्यक्तिगत रूप से (एक foreach पाश के साथ उत्पन्न किया जा सकता) और उन्हें प्रस्तुत करना। घटना श्रोता स्लॉट प्रति के साथ-साथ पंजीकृत किया जा सकता। यहाँ महत्वपूर्ण हिस्सा: यह सुनिश्चित करें कि आप उन्हें एक साथ ताज़ा दोनों स्लॉट पर एक ही विज्ञापन के साथ समाप्त => googletag.pubads() (यदि विज्ञापन दोनों स्लॉट को सौंपते हैं) से बचने के लिए बनाने के ताज़ा ([slot1, slot2]]।);
// this code can be moved externally to improve performance
googletag.cmd.push(function() {
// define slot1
slot1 = googletag.defineSlot(
"/1234/travel/asia/food",
[728, 90],
"banner1"
)
.addService(googletag.pubads())
.setTargeting(
"interests",
["sports", "music", "movies"]
);
// prerender the slot but don't display it because of disableInitialLoad()
googletag.display("banner1");
// define slot2
slot2 = googletag.defineSlot(
"/1234/travel/asia/food",
[[468, 60], [728, 90], [300, 250]],
"banner2"
)
.addService(googletag.pubads())
.setTargeting("gender", "male")
.setTargeting("age", "20-30");
// prerender the slot but don't display it because of disableInitialLoad()
googletag.display("banner2");
// add event to sign the slot as redered or not
googletag.pubads().addEventListener('slotRenderEnded', function(event) {
if (event.slot === slot1 || event.slot === slot2) {
// do something related to the slot
}
});
// refresh all container ads and show them
// very important to call refresh with an array to avoid
// multiple callback to the registered event
googletag.pubads().refresh([slot1, slot2]);
});
<div id="banner1" style="width:300px; height:250px;"></div>
<div id="banner2" style="width:300px; height:250px;"></div>
के बाद विज्ञापन गाया गया है, कॉलबैक ट्रिगर किया जाता है।
अधिक जानकारी के लिए इस फ़ाइल पर एक नजर है: https://github.com/davidecantoni/googletag
इस के साथ कोई भाग्य? – alexp
आप किस दिशा में जा रहे हैं? समस्या का मानना था कि आप collapseEmptyDivs के कारण खाली विज्ञापन स्थान के फ्लैश को रोकने की कोशिश कर रहे थे? –
मुझे पहले बताई गई समस्या का समाधान मिला: http://stackoverflow.com/a/17931853/105061 –