Fire a tag programmatically (by a JS call)

oscarmartinezm
Rookie Contributor
oscarmartinezm

Hi everyone, 

I'm trying to fire a tag based on a JavaScript interaction. I tried using utag.view() and utag.link() to get this, but the tag is not being fired.

This is what I did:

utag.link({}, function(){
    console.log('******* TAG LOADED ********');
}, [1754]);

In this case, I didn't configured a Load Rule for the Tag, for that reason it was configured "All Pages" by default. So, I was expecting to see the Tag fired twice, but I see it only one.

I also tried this:

utag.link({'attrib_01': 'oscar'}, function(){
    console.log('******* TAG LOADED ********');
}, [1754]);

tealium.png

In this case I expected to see it fired only once, but I get none.

One more thing, in all cases the callback function is always fired.

Best regards, 

4 REPLIES 4
Highlighted

Fire a tag programmatically (by a JS call)

Tealium Expert
Tealium Expert
Hello - have you reviewed this document on debugging Tealium?

https://docs.tealium.com/platforms/javascript/debugging/

it's a great place to start when debugging this kind of setup.

Fire a tag programmatically (by a JS call)

oscarmartinezm
Rookie Contributor
oscarmartinezm

Great tip!

This is what I'm getting:

Screen Shot 2019-11-02 at 9.47.26 AM.png

But I'm confused, I'm not sure if the message "called before tags loaded" is part of Tag 1754 or Tag 1597.

Also, I looked for a solutions to that message and I found this post: https://community.tealiumiq.com/t5/Tealium-iQ-Tag-Management/utag-view-not-firing-on-additional-page...

I tried the solutions they provided, but what I get is after several seconds "utag.handler.iflag" still having a 0 value.

This is the Tag configuration:

Screen Shot 2019-11-02 at 9.55.09 AM.pngScreen Shot 2019-11-02 at 9.52.27 AM.png

Thanks!

Fire a tag programmatically (by a JS call)

oscarmartinezm
Rookie Contributor
oscarmartinezm

Finally, I found a way to make the Tag work. What I found is the Tag was loading but "u.send()" was not being executed. So, the solution I found is to call it from the "utag.view" callback function:

setTimeout(function() {
    if (typeof utag_data.tag_id_onload !== 'undefined') {
        utag.view({}, function(){
            utag.o['my-profile'].sender['1755'].send('view');
        }, ['1755']);
    }
}, 200);

Is this the right way to make it work?

Thanks!

Fire a tag programmatically (by a JS call)

Tealium Employee

Hello @oscarmartinezm 

 

While this may work, it is circumventing an actual issue with your current setup, the error message "tag did not load" is suggesting that there is an issue with this tag file, typically a syntax error in the tag.

This error would likely be preventing all "utag view/link" calls being made on the page (ignoring the default page view when utag.js loads)
I would suggest looking in to the tag template for 1597, or looking at utag.1597.js when it is loaded in your webpage try to try and identify where the issue in this tag is coming from.

If you can fix the issue with this tag, it should allow for 1755 to fire when you are calling it