Reply
Highlighted
Visitor
Posts: 53
Registered: ‎09-22-2015

how to get the tag-id from extension

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

 

Reply
0 Kudos
Tealium Employee
Posts: 289
Registered: ‎09-01-2015

Re: how to get the tag-id from extension

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.

Tealium Employee
Posts: 210
Registered: ‎09-01-2015

Re: how to get the tag-id from extension

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

Visitor
Posts: 53
Registered: ‎09-22-2015

Re: how to get the tag-id from extension

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

Reply
0 Kudos
Visitor
Posts: 53
Registered: ‎09-22-2015

Re: how to get the tag-id from extension

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

 

Tealium Employee
Posts: 289
Registered: ‎09-01-2015

Re: how to get the tag-id from extension

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.
Reply
0 Kudos
Visitor
Posts: 53
Registered: ‎09-22-2015

Re: how to get the tag-id from extension

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

Visitor
Posts: 53
Registered: ‎09-22-2015

Re: how to get the tag-id from extension

[ Edited ]

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 
Reply
0 Kudos
Tealium Employee
Posts: 210
Registered: ‎09-01-2015

Re: how to get the tag-id from extension

@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

 

Tealium Employee
Posts: 289
Registered: ‎09-01-2015

Re: how to get the tag-id from extension

@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.
Reply
0 Kudos
Visitor
Posts: 53
Registered: ‎09-22-2015

Re: how to get the tag-id from extension

[ Edited ]

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

Reply
0 Kudos
Tealium Employee
Posts: 19
Registered: ‎09-01-2015

Re: how to get the tag-id from extension

@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

Reply
0 Kudos