how to get the tag-id from extension

Gold Contributor
Gold Contributor

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

 

14 REPLIES 14

how to get the tag-id from extension

Moderator
Moderator

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:

loader_id_orig.png

This will make the variable "u.tag_id" avaialable for you to use in a JavaScript extension:

modified_tag_id.png

Then, in an extension, you can check for "u.tag_id":

tag_uid_ext.png

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.

Check out our new Swift integration library for iOS, macOS, tvOS and watchOS: https://github.com/Tealium/tealium-swift with updated
documentation https://community.tealiumiq.com/t5/Swift/tkb-p/swift.

how to get the tag-id from extension

Tealium Employee

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

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

how to get the tag-id from extension

Gold Contributor
Gold Contributor

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". 

how to get the tag-id from extension

Gold Contributor
Gold Contributor

Thank you both for your quick and perferct reply :-)

 

how to get the tag-id from extension

Moderator
Moderator
Hi @jarno_rossi,

The load rules are re-evaluated on every event (utag link or view), so if a new event happens, but the tag is not yet loaded, it will be fired and downloaded from the CDN. Originally (before 2014) this was not the case, so the "return false" trick was necessary, but all utag.js versions after 4.26 support dynamic load rules.

You also have the option of calling explicit tag UIDs with utag.link or view like this, but be aware that this bypasses load rules completely:

utag.view({"page_name":"homepage"}, null, ['14', 23']); // pass an array of UIDs. This example will call tag number 14 and 23, bypassing load rules completely.

Craig.
Check out our new Swift integration library for iOS, macOS, tvOS and watchOS: https://github.com/Tealium/tealium-swift with updated
documentation https://community.tealiumiq.com/t5/Swift/tkb-p/swift.

how to get the tag-id from extension

Gold Contributor
Gold Contributor

Good to know! We will align our code to this feature in the earlier of 2017.

how to get the tag-id from extension

Gold Contributor
Gold Contributor

Hi @craig_rouse.

Some deeper questions.

  • if we decide to use "return false", can we place it into an extension? I mean, the extension is a function, so "return false" stops that extension and not the tag. Am I right?
  • if we decide to use "load rule" to manage the tracking firing: can we stop any event tracking just handling variable we use in load rule? So, let's assume we track any click using Google Analytics, and tha GA tag has a load rule based on the value of GA_flag = 1 or 0. With an extension, that we run before load rule, we can manage the value of that variable and decide whether to track or not the event 

how to get the tag-id from extension

Tealium Employee

@jarno_rossi

  • So if your extensions is scoped to "All Tags/DOM Ready/Preloader" then all the return false will do is exit the extension.
    However, if you return false; inside and extension scoped to a tag then that will stop the tag from firing.
  • You are correct, this would indeed do the trick

Adrian

 

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

how to get the tag-id from extension

Moderator
Moderator
@jarno_rossi You're correct that returning false terminates the function and of course you wouldn't normally expect this alone to affect anything other than the currently running extension/function, but in Tealium, each tag template contains explicit logic to check the return value from each extension, and if any extension returns false, tag execution is aborted. I hope this helps to explain things.
Check out our new Swift integration library for iOS, macOS, tvOS and watchOS: https://github.com/Tealium/tealium-swift with updated
documentation https://community.tealiumiq.com/t5/Swift/tkb-p/swift.

how to get the tag-id from extension

Gold Contributor
Gold Contributor

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... 

how to get the tag-id from extension

Employee Emeritus

@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

how to get the tag-id from extension

Tealium Expert
Tealium Expert

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 uid 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.

how to get the tag-id from extension

Gold Contributor
Gold Contributor

thank you so much, @UnknownJ!

how to get the tag-id from extension

Moderator
Moderator

OOOOooooo!!! I'd accept @UnknownJ's response as a solution, @jarno_rossi! #hinthint #winkwink

TOODLES!!! 

If you liked it then you should have put a kudo on it!
Public