How to add IMA SDK(s) in lightning js app

how to add ima sdk in lightning js app so that I can use that with shaka player to play ads
src=“//imasdk.googleapis.com/js/sdkloader/ima3.js

1 Like

You can follow the HTML instructions

You can use document.createElement inside the Lightning components to add the HTML you need

I tried to createElement inside _construct(), _setup() as well _init() but still getting below error:
ReferenceError: google is not defined

However, I can see google being added in window. It seems the script is being loaded later. Could you please suggest in which lifecycle event I should add the createElement method?

Hi @dngh30 . You’d need to do this at the boot route of your application, which is where everything is yet to load. You’ll need to use a promise that would need to resolve once your app detects that the IMA SDK has loaded correctly. Then you can allow the app to move to whatever route you need.

You can find documentation for this here: Lightning SDK

So using the splash screen is always a great place to load all these type of dependencies. Hope this helps.