- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
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?
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).
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?
Hi @LongPun
The b 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.
@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?
The UTAG Monitor is another tool to help you diagnose event tracking issues: Universal Tag (UTAG) Debugger
Copyright All Rights Reserved © 2008-2023