Highlighted

Global function in a JS extension

Silver Contributor
Silver Contributor

Hi All,

 

I'd like to have a JS Extension containing some useful functions to be used in other extensions.

Example:

2017-09-28_16h17_18.png

 

(there is a similar forum discussion here: https://community.tealiumiq.com/t5/Tealium-iQ-Tag-Management/How-do-define-a-function-in-JS-extensio... but it doesn't apply in this case exactly + is a bit old).

 

(And just in case: yes I'm aware of the Persist Data Value extension - the above would have a lightly different use case).

 

Thanks,

Florian

5 REPLIES 5

Global function in a JS extension

Tealium Expert
Tealium Expert

Hi @florian_perl, I don't know of a way to create a specific 'extension' scoped function set, so you will probably still need to make it global. Because most implementations are async, controlling when the functions are available is tricky and subjective to when they load. One thing you could try is to set the Execution to 'Run Once before Load Rules' and as high up in the load order as possible.

 

When I have put in cookie functions before I have just taken the easy road and put them in all the extensions that call for them, not optimal I know, but it guarantees they are available when needed. 

Steve Terjeson | Director | Analytics | WUNDERMAN THOMPSON DATA | t: 972-664-3532 c: 214-929-3960
Highlighted

Global function in a JS extension

Silver Contributor
Silver Contributor

Hi @STerjeson,

Thanks. I had it set to that already, plus I added the functions in another extension that would be using them. Still no luck. The extension fires correctly, logs messages to utag.DB but the functions are blocked for some reason.

 

Team Tealium, any insights? 

Highlighted

Global function in a JS extension

Tealium Employee

@florian_perl

 

My first thought would be to use a JavaScript Extension with blr setting enabled and run once.

Once this is done you can assign the new functions you have created to utag.ext. So you would have something like:

 

utag.ext = {};
utag.ext.someFunction = function(){/*....*/};

This way they will only be defined once, and you can reference them inside any extension (or tag) you wanted. 

 

Adrian

Ask me anything Tealium related or Javascript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.
Highlighted

Global function in a JS extension

Silver Contributor
Silver Contributor

Thanks @adrian_browning, it works. Do all global objects have to be declared through utag.ext?

 

(Btw if anyone is interested in this - the functions have to be called through utag.ext.function_name() now.)

Highlighted

Global function in a JS extension

Tealium Employee

@florian_perl

 

If you want to make it truly global you can use the window object. then you can just use the function name to call it.

 

Adrian

Ask me anything Tealium related or Javascript, or NodeJS.
Please remember to mark solutions as accepted for future searchers.