ReferenceError: google is not defined ... not loading ima3.js

3,119 views
Skip to first unread message

dubbya

unread,
Feb 13, 2016, 11:07:41 AM2/13/16
to Interactive Media Ads SDK
Hi All, 

Running into a really frustrating problem here and i'm wondering if anyone else has ran into this.  I load the following script:

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

and then in my code, I call the following:

var adDisplayContainer = new google.ima.AdDisplayContainer(elem[0], videoContent);

I end up getting this error:
ReferenceError: google is not defined

Which makes sense because my ima3.js isn't being loaded (maybe it's just not getting loaded fast enough).  But i don't see it in my developer tools sources tab.  This has happened to me before, then it started working again, and now I'm back to this not working.

Has anyone dealt with this issue before? Is there any way to load the ima3.js locally? 

dubbya

unread,
Feb 13, 2016, 11:26:18 AM2/13/16
to Interactive Media Ads SDK
One other thing I wanted to mention.  When I replace this:
<script type="text/javascript" src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>

with this:
    <script type='text/javascript'>
        console.log("loading IMA googletag");
        var script_tag = document.createElement('script');
        script_tag.setAttribute('type', 'text/javascript');
        script_tag.setAttribute('src', '//imasdk.googleapis.com/js/sdkloader/ima3.js');
        script_tag.onerror = function() { alert("Loading failed!"); }
        document.getElementsByTagName('head')[0].appendChild(script_tag);
    </script>

I see my onerror event firing
script_tag.onerror = function() { alert("Loading failed!"); }

There is something definitely going on.  Any ideas?

dubbya

unread,
Feb 15, 2016, 11:37:45 AM2/15/16
to Interactive Media Ads SDK
Just thought I'd follow up with this issue. I'm really hoping I'm not the only person in the world running into this.  Would anyone happen to know if any reasons why a .js script would fail to load on a page in the first place?


On Saturday, February 13, 2016 at 8:07:41 AM UTC-8, dubbya wrote:

Vu Chau (IMA SDK Team)

unread,
Feb 15, 2016, 8:10:52 PM2/15/16
to Interactive Media Ads SDK
Hi there,

Are you launching your implementation by opening your file directly with a web browser?  If so, it might not work as your browser might have security settings in place that might prevent the SDK from loading.  Make sure you are hosting your files on a web server.  There are many options, so do that and let us know if you continue seeing the issue.

Vu Chau
IMA SDK Team

Lucas Rancez

unread,
Jun 23, 2016, 5:47:25 PM6/23/16
to Interactive Media Ads SDK
Hi there,
This is happening to me too. Does ima require the website to run in https or something like that?

Best,

Lucas

Vu Chau (IMA SDK Team)

unread,
Jun 24, 2016, 9:19:40 AM6/24/16
to Interactive Media Ads SDK
Hi Lucas,

IMA doesn't require the website (where the user is actually on to watch the ad and content) to be on HTTPS.  In fact, you can navigate to our sample example on GitHub, and confirm that.
However, the browser may (or may not) require resources (IMA-affiliated, and third-party) to be served via HTTPS.  For this, IMA does not have control of, given each browser handles this HTTP/HTTPS mixed content issue differently.  The best that can be done here is to make sure all resources are fully available online, served via HTTPS, and have proper CORS header, among other criteria.

Those are some of the things I'd recommend checking with your implementation in order to rectify this issue.
Feel free to send us some information (a page URL, code snippets, screenshots, etc.) if necessary.

Vu Chau
IMA SDK Team

rahul...@vuclip.com

unread,
Jun 9, 2017, 3:30:39 PM6/9/17
to Interactive Media Ads SDK
i want to download ima3 locally..but throwing error

Chris Feldman (IMA SDK Team)

unread,
Jun 12, 2017, 10:14:42 AM6/12/17
to Interactive Media Ads SDK
Hi Rahul,

Our team does not recommend downloading the SDK for use locally. Making the call to the ima3.js script ensures that you're always loading the latest version of the SDK.

If you continue to have issues, or if you have any further questions, please open a new thread on the forum.

Regards,
Chris Feldman
IMA SDK Team

miguel isaac

unread,
Jul 21, 2017, 6:59:43 PM7/21/17
to Interactive Media Ads SDK
Check for adBlock, that was for me

Ken Guie

unread,
Mar 14, 2018, 6:17:59 PM3/14/18
to Interactive Media Ads SDK
Hi Chris, isn't it slower to run everything from the cloud though? 

We're really trying where i work to play the player within 2 seconds (supposedly the industry standard) so serving locally would work best? 

As an aside, I built a test page with video and the ima sdk and from online, it doesn't load fast enough i guess bc i need a timeout. Is there another way to do this? 
Also with this question, I used a time out because or some reason, an ad container was blocking the player but once i changed this to display none, it works fine. 

Why is this? 

setTimeout(function() {
var target = document.getElementById('content_video_ima-ad-container');
target.style.display = 'none';
}, 2000);

var googOptions = {
id: 'content_video',
'iu=/124319096/external/ad_rule_samples&ciu_szs=300x250&ad_rule=1&' +
'impl=s&gdfp_req=1&env=vp&output=xml_vmap1&unviewed_position_start=1&' +
'cust_params=sample_ar%3Dpremidpostpod%26deployment%3Dgmf-js&cmsid=496&' +
'vid=short_onecue&correlator='
};

canvas.ima(googOptions);

Thanks!

Chris Feldman (IMA SDK Team)

unread,
Mar 15, 2018, 11:43:31 AM3/15/18
to Interactive Media Ads SDK
Hi Ken,

We are unable to support locally hosted copies of the SDK and we do not recommend using one. We've found that dynamic serving provides for the best user experience as it guarantees that players are using the latest SDK version at all times.

With regard to your timeout question, can you clarify what exactly you're asking? If you'd like to implement a timeout for loading the SDK binary, you'll have to do that on your own. It's not possible to do this via the IMA SDK because before the binary is loaded, you won't have access to any SDK functions.

If you have any further questions, please open a new thread. Keeping new topics segregated makes it easier for our team to track responses and keep the forum organized.

Regards,
Chris Feldman
IMA SDK Team

Ken Guie

unread,
Mar 15, 2018, 11:54:23 AM3/15/18
to Interactive Media Ads SDK
Yep, thanks Chris, 

My Timeout question is basically because the libs don't seem to load in a timely manner. By the time I want to work with the sdk, all the elements are still not rendered to the page yet so I have to run time out code in order to wait for all the elements to load or perhaps run a set interval looking for the ima sdk elements. 

I think it's faster if served locally but i haven't tested. I thought it was a good question to ask here. 

Just wanted your opinion on that. 

Best!
Reply all
Reply to author
Forward
0 new messages