how to use utag.view function on Modal page

Gold Contributor
Gold Contributor
which method is correct? a href="#" onClick="utag.view({ brand:"abc", page_category_id:"XX", event_type: "conversion" }); or which method is correct? a href="#" onClick="utag.view({ brand:"abc", page_category_id:"XX", event_type: "conversion" }); or On modal page place the below script (<> no added with script) script utag.view ({ brand:"abc", category_id: "asdf", event_type: "conversion" /script script tealium script (utag.js file) })(); /script
7 REPLIES 7

how to use utag.view function on Modal page

Moderator
Moderator
Hi Manish, That looks fine to me, although you need to make sure you use the opposite style of quotes inside the utag.view call to the ones enclosing the onClick event (i.e. single quotes in the case above.) Not sure what your "or" case is because it looks like your question didn't save correctly... Cheers, 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 use utag.view function on Modal page

Gold Contributor
Gold Contributor
Thanks Craig, i have updated my question. now u can see "or" section

how to use utag.view function on Modal page

Moderator
Moderator
Sorry, the update doesn't really make sense to me, but the first example is fine. It's best practice not to use the onClick handler on anchor tags (it's a bit Y2K style), but it works fine for demo purposes. Best practice would be to assign click handlers using jQuery or similar.
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 use utag.view function on Modal page

Moderator
Moderator
Sorry... I was too quick :-) It depends what you want to achieve - does the view event need to happen onClick, or does it just need to fire somewhere on the page? If you don't need the click event, then the "or" bit would work fine.
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 use utag.view function on Modal page

Gold Contributor
Gold Contributor

this is a product quick view page (modal page), i want to fire a page view tag on load of quick view modal page.

should i use the below script or above method - (<> no added with script)

 

script

utag.view ({

brand:"abc",

category_id: "asdf",

event_type: "conversion"

/script

 

script

 

tealium script (utag.js file)

})();

/script

when i am using the above script it is showing utag is not defined.

how to use utag.view function on Modal page

Gold Contributor
Gold Contributor
Thanks Craig, Can you please share one sample code how this code will look like, when i am trying to add above code it display an error - "utag is not deifined"

how to use utag.view function on Modal page

Moderator
Moderator

You would need to make sure that Tealium is higher up on the page than your script tag. Utag only gets defined inside utag.js, so if your script is running before Tealium, this won't work.

 

It would also be sensible to check if utag is defined before trying to call it. If not, you could use setTimeout to wait until utag is defined on the page. Something like:

--script--

(tealium utag.js)

--/script--

 

--script--

window.callTealiumView = function(){

if (typeof utag !=="undefined" && typeof utag.view==="function"){

utag.view({

"brand":"abc",

"category_id":"askjdasd",

"event_type":"conversion"

});

} else {

window.setTimeout(callTealiumView, 300);

}

}

--/script--

--script -- window.callTealiumView();//initiate the function --/script--

 

This will keep attempting to call utag.view until it exists on the page. The code above is not production ready!!! I only mocked it up quickly to demonstrate a possible solution. Please don't use it without reviewing it first.

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