0

adtag from google are not displayed

asked 2022-03-30 00:39:34 +0800

andij62 gravatar image andij62
315 1 7

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>
delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted
0

answered 2022-03-30 09:55:35 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

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?

link publish delete flag offensive edit
0

answered 2022-03-30 18:00:41 +0800

andij62 gravatar image andij62
315 1 7

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

link publish delete flag offensive edit
0

answered 2022-04-01 10:56:15 +0800

MDuchemin gravatar image MDuchemin
2560 1 6
ZK Team

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

link publish delete flag offensive edit
0

answered 2022-04-01 23:19:10 +0800

andij62 gravatar image andij62
315 1 7

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!

link publish delete flag offensive edit

Comments

Sounds reasonable. It does confirm that the issue is tied to loading times. I think this could still fail under really slow network conditions (i.e. if the gptadslots variable doesn't get filled by the external resources until after that 1000ms)

MDuchemin ( 2022-04-06 16:36:44 +0800 )edit

But that would still be good enough for most use cases. If you wanted to, you could do a something with a setTimeout calling the init function recursively, untill there is some value into gptadslots[x]

MDuchemin ( 2022-04-06 16:37:37 +0800 )edit

something like (PSEUDOCODE) >>>> initIfReady: function(){if(gptadslots[x]){doActualInit()}else{setTimeout(initIfReady, 500)}}

MDuchemin ( 2022-04-06 16:39:02 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2022-03-30 00:39:34 +0800

Seen: 13 times

Last updated: Apr 01 '22

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More