- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
Hi All,
I'd like to have a JS Extension containing some useful functions to be used in other extensions.
Example:
(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
Solved! Go to Solution.
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.
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?
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
10-04-2017 07:27 AM - last edited on 10-04-2017 07:32 AM by kathleen_jo
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.)
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
Copyright All Rights Reserved © 2008-2023