Reputation: 853
I'm trying to fire an event when one of my DFP ads has been loaded. The ad is loaded in an iframe and so I've been trying to fire an event on iframe load however it seems to only work some of the time and not every time and is therefore not reliable. I've even tried to put the iframe on load inside a iframe ready as the iframe ready seems to always fire in the case that when the on load watcher is initiated the iframe might not be there.
$("#my_id iframe").on("load", function() {
console.log('LOADED!');
});
$("#my_id iframe").ready(function() {
console.log("READY!");
$("#my_id iframe").on("load", function() {
console.log('LOADED!');
});
});
the DFP add is triggered through:
<div id="my_id">
<script type="text/javascript">
googletag.display("some-ad");
</script>
</div>
double click injects the iframe into the div above which will load the image ad.
Any thoughts?
Thanks!
Upvotes: 3
Views: 2567
Reputation: 853
seems like you can add an event listener to dfp https://developers.google.com/doubleclick-gpt/reference#googletag.Service_addEventListener
googletag.pubads().addEventListener('impressionViewable', function(event) {
console.log(event.slot)
});
Upvotes: 4