Reputation: 163
Is there a way to know the type of ad(Native/Banner ad) being served in each ad slot from Google ad manager on a website? I am using a code snippet similar to what is provided in the gpt documentation:
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag
.defineSlot(
'/6355419/Travel/Europe/France/Paris', [300, 250], 'div-id')
.addService(googletag.pubads());
googletag.enableServices();
});
</script>
<div id="div-id" style="width: 300px; height: 250px;">
<script>
googletag.cmd.push(function() {
googletag.display('div-id');
});
</script>
</div>
Is there any event that I can listen to, in order to know the ad type?
Upvotes: 0
Views: 852
Reputation: 859
The Google Publisher Tag API enables you to retrieve the creativeTemplateId
used for each rendered slot.
As long as you know your templates ids, you should be able to do specific actions :
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag
.defineSlot('/6355419/Travel/Europe/France/Paris', [300, 250], 'div-id')
.addService(googletag.pubads().addEventListener('slotRenderEnded',function(event) {
var slot = event.slot;
console.group('Slot', slot.getSlotElementId(), 'finished rendering.')
// Log details of the rendered ad.
console.log('Creative Template ID:', event.creativeTemplateId);
console.groupEnd();
if(event.creativeTemplateId === yourIdentifiedTemplateId) {
//your specific action
}
}));
);
googletag.enableServices();
});
</script>
<div id="div-id" style="width: 300px; height: 250px;">
<script>
googletag.cmd.push(function() {
googletag.display('div-id');
});
</script>
</div>
Concerning yourIdentifiedTemplateId
:
Full documentation :
Hope this helps ;)
Upvotes: 1