Highlighted

How to edit utag.link

Bronze Contributor
Bronze Contributor

Suppose I have the following (existing) code in the header of a page:

 

utag.link ({
"order_total": 1000.0,
"order_tax": 150
};)

For convenience, I want to insert a new calculated variable, so it becomes:

 

utag.link ({
"order_total": 1000.0,
"order_tax": 150.0,
"order_subtotal": 850.0 //difference };)

This change should be made accessible to all tags.

Trouble is, I do not have the right to edit the source code and must do it in Tealium iQ. What is the way to achieve it?

 

 

4 REPLIES 4
Highlighted

How to edit utag.link

Silver Contributor
Silver Contributor

Hey @LongPun,

You can use a Set Data Values (or a JavaScript) extension where you substract order_tax from order_total whenever both are defined, and scope it to All Tags. 

Something like this should work:

if(b.order_total && b.order_tax) {
  b.order_subtotal = parseFloat(b.order_total) - parseFloat(b.order_tax);
  b.order_subtotal = b.order_subtotal.toFixed(2).toString();
}

Just double check the format is correct (dot or comma).

Highlighted

How to edit utag.link

Bronze Contributor
Bronze Contributor

Thanks @psanchez.

Trouble is, the data are hard-coded in a utag.link() call, and the variables inside (e.g. order_total) is not directly accessible with the b variable. So when I tried your code, since either b.order_total nor b.order_tax exist in b, it does not work for the case.

Any other suggestions?

Highlighted

How to edit utag.link

Tealium Expert
Tealium Expert

Hi @LongPun 

The variable within an All Tags extension running either Before Load Rules or After Load Rules will contain the event payload that was passed into the utag.link call, the solution above will definitely work. I think it's worth debugging your code using the information here to check what's happening.

Highlighted

How to edit utag.link

Community Manager
Community Manager

@LongPun It might be worth noting that the code you posted has syntax errors. The semicolon after the object is invalid. Are you sure it's executing correctly?

utag-link-error.png

The UTAG Monitor is another tool to help you diagnose event tracking issues: Universal Tag (UTAG) Debugger

 

Remember to "Accept as Solution" when your question has been answered and to give kudos to helpful replies.