Technologies:
Tolerim
a day ago
The implementation of Google Publisher Tag is not functioning properly.
googletag.cmd.push(function () {
advert.slot = googletag.defineSlot(advert.id, [advert.width,
advert.height], advert.elementId);
advert.slot.addService(googletag.pubads());
googletag.enableServices();
googletag.display(advert.elementId);
Logger.debug(advert);
Answers(1)
Tolerim
a day ago
Verified Answer
One potential reason for the ad not firing every time could be due to the timing of the Google Publisher Tag (GPT) code. Sometimes, the GPT code may not have fully loaded before the googletag.display method is called, causing the ad to not show up.
To ensure that the GPT code has fully loaded before displaying the ad, you can wrap the googletag.display method inside the googletag.pubads().addEventListener method, which listens for the 'impressionViewable' event. This event is triggered when the ad is guaranteed to be visible and safe to display, ensuring that the ad is displayed only when it is ready.
Here's an updated example of how you can modify the code to ensure that the ad always fires:
googletag.cmd.push(function () {
advert.slot = googletag.defineSlot(advert.id, [advert.width, advert.height], advert.elementId);
advert.slot.addService(googletag.pubads());
googletag.enableServices();
Logger.debug(advert);
googletag.pubads().addEventListener('impressionViewable', function() {
googletag.display(advert.elementId);
});
});
In this example, we are wrapping the googletag.display method inside the googletag.pubads().addEventListener method so that the ad is displayed only when the 'impressionViewable' event is triggered, ensuring that the ad is always visible and safe to display.