How to avoid "google object is not defined" error

27 views
Skip to first unread message

Urko Dorronsoro

unread,
Jun 25, 2024, 7:25:33 AM (4 days ago) Jun 25
to Interactive Media Ads SDK

Hello


We have advertising on an online gaming website (static ads and in-stream videos).


For video ads, we use the IMA SDK HTML5 library. We include the IMA SDK script in DEFER mode:

<script defer="" type="text/javascript" src="https://imasdk.googleapis.com/js/sdkloader/ima3.js"></script>


The video ad is shown after the user plays a game, just when decides to return to the main game area (clicks to leave the current page and goes to another URL).


We have been showing advertising for more than a year. Taking a few days' inventory as a sample, which is approximately 40,000 requests to show an in-stream video ad, approximately 50% of the inventory does not show the video ad due to the following error: google object is not defined (window.google object).


As far as I know, this window.google object is created by the ima3.js library.


Assuming that the object was not defined because the ima3.js file was not downloaded, we thought that this high error rate corresponded to users who had ad blockers installed in their browsers. But since we have activated Google AdManager ad blocking recovery messages service, we see that, according to the GAM report, the number of users who have these ad blockers installed is a much lower.


Additionally, after adding some log messages, we have verified that the script is not deleted when this error occurs. If the adblocker was causing the problem, it would removed it. 


Also, we have obtained the following information:

When the DOMContentLoaded event is fired, the ima3.js script exists but the google object is not defined.

When the ad request is made, a few minutes later, after the page loads, the ima3.js script exists but the google object is not defined.


Therefore, we do not know the cause of this error, nor, obviously, how to avoid it.


IMA SDK

unread,
Jun 25, 2024, 11:19:08 AM (4 days ago) Jun 25
to urko.j...@gmail.com, ima...@googlegroups.com
Hi,

Thank you for contacting IMA SDK support team.

Could you share any sample project with us in which you are facing this issue with defer. I've tried in Advance Sample Code but unable to replicate any issue with that.
Just wanted to see your approach of ads loading.

You can utilize this link for providing sample project and kindly reply back once you are done with submission.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02tJSlj:ref" (ADR-00243782)

Thanks,
 
Google Logo IMA SDK Team





 

Urko Dorronsoro

unread,
Jun 26, 2024, 2:25:38 PM (3 days ago) Jun 26
to Interactive Media Ads SDK
Hi,

We have replicated this error using a browser with an ad blocker. But having such a large number of errors, we decided to ask the question in this forum.

The line where the error occurs is:
    adDisplayContainer = new google.ima.AdDisplayContainer(document.getElementById(adContainer));

The function that contains that line is the one that performs the Setup of IMA:

const setUpIMA=function(){
    if (!window.google){
        sendToLog("Google Object is not defined");
        return;
    }
    if (adsLoader==null) {
        adDisplayContainer = new google.ima.AdDisplayContainer(document.getElementById(adContainer));
        adsLoader = new google.ima.AdsLoader(adDisplayContainer);
        adsLoader.addEventListener(google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,onAdsManagerLoaded,false);
        adsLoader.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR,onAdLoadError,false);
        adDisplayContainer.initialize();
    }
};


Thanks for helping

IMA SDK

unread,
Jun 26, 2024, 6:04:10 PM (3 days ago) Jun 26
to urko.j...@gmail.com, ima...@googlegroups.com

Hi,

Thank you for sending the code snippet.

After looking at the code snippet, I searched for the "Google Object is not defined" and could not find any results related to the mentioned error in the Google Advanced example. This error might be your log message to understand.  However, It would help us to investigate in detail and find the root cause of the issue and make some progress if a minimal sample project is provided from your end. I'm afraid that we'll need detailed debug information from a sample project where it's observed to make any progress in diagnosing this. The only way for us to investigate further is by creating a project where the issue is reproducible.

You can provide the following details via reply privately to the author option or directly provide it to the link below.

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to

https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=IMA+SDK&entry.460850823=5004Q00002tJSljQAG&entry.80707362=00243782

2. Fill out all fields, and attach your file(s).

3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link. 

Reply all
Reply to author
Forward
0 new messages