- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
Hi,
can we get the tag id from a extension with a specific tag scope?
We stop tags using "return false" into extension (for example when we dont want to fire the tracking call), but we need to set the scope to each tag we want to stop (is it right?). Hence we also need to understand which tag is currently running that extension because the events managing could be different.
Thanks
Solved! Go to Solution.
Hi Jarno,
I would recommend if possible avoiding the "return false" trick if possible, as it can make the profile less easy to debug for non-technical users. You should be able to achieve the same effect by using load rules in most cases (and if you need to use the output from an extension in a load rule, make sure you use the "Before load rules" setting in your "All Tags" extension (see here for details: https://community.tealiumiq.com/t5/Tealium-iQ-Tag-Management/JavaScript-Code-Extension/ta-p/11925).
If you cannot do this with load rules, then the "return false" method may be the answer. By default, the tag ID is not available in extension scope. You could, however, make it available by editing the tag template and adding the tag UID to the "u" object, which would then be available in extensions, but be aware that if you upgrade your tag templates in future, you would need to merge this change in with the new template, or the change will be lost.
Here's an example for the Tealium Custom Container tag:
This will make the variable "u.tag_id" avaialable for you to use in a JavaScript extension:
Then, in an extension, you can check for "u.tag_id":
You are correct that in order to use the "return false;" trick, you need to scope the extension to the tag. "All Tags" scope will not work.
Let me know if anything is unclear.
Craig.
Hi @jarno_rossi
Just to expand on Craig's answer.
For the newer templates we have created, and slowly as we update the older ones, all of the templates will have a property
u.id
This is set in the template at the top, just like how Craig showed you using the code snippet.
var u = {"id" : id};
Adrian
Hi Craig.
I think we cannot use the load rule set because if you dont load a tag, you cannot use it later.
That's why we implemented a way to abort (cancel) or freeze (pause and keep it for later) tracking calls. It means, we load the tags but sometimes we need to say "stop, this is not a real event we need to track".
Thank you both for your quick and perferct reply :-)
Good to know! We will align our code to this feature in the earlier of 2017.
01-18-2017 02:58 AM - last edited on 01-18-2017 03:28 AM by adrian_browning
Hi @craig_rouse.
Some deeper questions.
return false;
inside and extension scoped to a tag then that will stop the tag from firing.Adrian
01-26-2017 09:39 AM - last edited on 01-26-2017 01:52 PM by kathleen_jo
Great @craig_rouse.
I'm about to complete this big change.... but, I notice the "b" is no more empty at the beginning, there is something we should know in the way you manage/reset "b" inside "All tags" scope? I mean, we use a variable "b.Abort" as a flag to stop tags firing. At the 1st call we set "b.Abort=1" avoid any tracking call. Then on 2nd call I dont set "b.Abort=1" so I expect to have "b.Abort<>1" but it's still "b.Abort==1". I hope I'm clear with my question...
@jarno_rossi What version of utag.js are you running? On some of the later versions (4.4 + ) the "b" object is going to be a copy of the data that you are firing for a specific event at that moment, meaning if you fire a utag.view() or a utag.link() call, the "b" object will only include the parameters that you pass in with that call and not the original variables from your data layer. This means that you would need to add in additional logic to include the b.Abort variable from a previous event on the page or re-setting it with the new call.
On older versions of utag.js (4.39 and earlier) the "b" object would include all parameters sent with a utag.view/link() call as well as any other original variables from your utag_data (data layer).
Hope that helps!
Chris
02-27-2018 01:19 AM - last edited on 02-27-2018 11:14 AM by kathleen_jo
I know I'm catastrophically late to this party, @jarno_rossi, but...
In theory, the variable "id" is in scope from the tag instantiation when tag-scoped extensions are run.
As such, while a and b are the only variables that are documented as available to tag scoped extensions, you can also access u, id and loader because they're also in scope.
So in theory, there's no need to update templates - if you're outside the tag, you can get the ID based on the key in the utag.sender object, and if you're inside the tag running extensions, you can refer to id straight up. But if you wanted, you could create a tag-scoped extension that runs:
u.tag_id = id;
u.tag_sender = sender;
And that would persistently store the profile and tag ID that were used to load the tag inside the tag object itself, for referencing anywhere.
02-28-2018 02:26 AM - last edited on 02-28-2018 05:14 AM by kathleen_jo
OOOOooooo!!! I'd accept @UnknownJ's response as a solution, @jarno_rossi! #hinthint #winkwink
TOODLES!!!
Copyright All Rights Reserved © 2008-2023