-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
the adtag should be displayed automatically after loading the page, but it doesn't work. The adtag is only displayed when I click the refresh button. What could be the problem?
<?meta name="viewport" content="width=device-width, initial-scale=1"?>
<!-- Cookiebot -->
<?script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" data-cbid="xxx" data-framework="IAB" type="text/javascript"?>
<!-- Ad-Tags -->
<?script async type="text/javascript" src="//storage.googleapis.com/adtags/xxx.js"?>
<zk xmlns:x="xhtml">
<script>
zk.afterLoad(function() {
googletag.cmd.push(function() {
googletag.pubads().refresh([gptadslots[2]]);
});
});
</script>
<script>
var refreshSlot = function() {
googletag.cmd.push(function() {
googletag.pubads().refresh([gptadslots[2]]);
});
};
</script>
<!-- Beginning Async AdSlot 2 -->
<div style="text-align: center; padding: 10px 0">
<x:div id='div-gpt-xxx'>
<x:script type='text/javascript'>
try {
window.googletag.cmd.push(function() {
window.googletag.display('div-gpt-ad-xxx');
});
} catch(exc) {
console.log(exc.message);
}
</x:script>
</x:div>
</div>
<x:button onclick="refreshSlot();">Refresh AdSlot</x:button>
</zk>
First idea would be that the zk.afterLoad(function() {
could fire before the script has been fully loaded.
The zk.afterLoad() function will wait for a specific zk package to be loaded, or until all zk packages are loaded if not specified.
It doesn't wait for other scripts that are not part of the ZK framework client engine.
Since the adtags script hold the async attribute, it doesn't have a clear finish to load sequence compared to the rest of the page. (without async, the page will wait for the script to finish to load before executing, so it could be worth trying that out, if it doesn't affect loading time too much).
Do you get any error message in the browser's console? You could try to add console.log(googletag) to see the state of the object during zk.afterload(). (if console is not an option due to mobile, try zk.log(...)
to log to screen instead.
Which ZK version are you running?
Hi,
Unfortunately removing the async didn't help. The following information is displayed in the browser console:
[GPT] Invalid arguments: PubAdsService.refresh([undefined]).
I use ZK-Version 8.5.0. Is there any other way to fix the problem
Regards
Hi,
The error message here is pretty clear: [GPT] Invalid arguments: PubAdsService.refresh([undefined])
The [gptadslots[2]]
object passed to the refresh method is undefined at time of call.
Assuming these tags are defined by the content of
<!-- Ad-Tags -->
<?script async type="text/javascript" src="//storage.googleapis.com/adtags/xxx.js"?>
Then it would still point to a loading time issue.
You could try to add defer="true" to the init script to delay it's execution until after page rendering, and removing the zk.afterload (without a target package, it's not very relevant).
<script defer="true">
googletag.cmd.push(function() {
googletag.pubads().refresh([gptadslots[2]]);
});
</script>
If that still doesn't help, you will need ot look into why gptadslots[2] is undefined at that stage
Hi
unfortunately that didn't help either. I now set a timer to delay the refresh. This is how it works now.
<timer id="timer" delay="1000" repeats="false" >
<attribute name="onTimer">
Clients.evalJavaScript("refreshSlot();");
</attribute>
</timer>
Thank you for your help!
Asked: 2022-03-30 00:39:34 +0800
Seen: 13 times
Last updated: Apr 01 '22