- TLC Home Home
- Discussions & Ideas Discussions & Ideas
- Product Guides Product Guides
- Knowledge Base Knowledge Base
- Developer Docs Developer Docs
- Education Education
- Blog TLC Blog
- Support Desk Support Desk
This article lists the conditional operators available for creating load rules and extension conditions. It also shows the JavaScript code that is generated when those configurations are built into utag.js.
In this article:
The Tealium iQ Tag Management interface was designed for developers and marketers alike and therefore it does not require JavaScript knowledge to use. However, it is important to understand that your configuration is eventually transformed into JavaScript code that runs on your website.
One example of this are the conditions used in load rules and extensions. Understanding the JavaScript code that is generated by these components can help prevent errors and improve your business logic.
The first thing to notice is that the order that conditions appear in the interface is the same order that they appear in the generated code.
In this example, notice that the order of the conditions in the UI matches the order in the JavaScript code.
Example of two extensions conditions in the interface:
Corresponding JavaScript code:
((typeof b['event_name'] != 'undefined' && b['event_name'].toString().toLowerCase().indexOf('add to cart'.toLowerCase()) > -1) ||
(typeof b['event_type'] != 'undefined' && /cart$/i.test(b['event_type'])))
The order of the conditions is critical for the extension or load rule to behave as expected. For example, if theis defined
condition checks for event_name
after the condition for contains (ignore case)
, the code would exit with an error and the condition would not evaluate as expected.
It is best practice to always add the is defined
condition in conjunction with other conditional options. This helps prevent any JavaScript errors and ensures the load rule works as intended.
This table lists the generated JavaScript code for each condition. In these examples, {{VALUE}}
represents the value from the text field in the extension or the load rule. The variable dom.title
is used for strings, cart_total_items
for numbers, and va.badges.42
for badges.
Condition | JavaScript code generated |
contains |
(b['dom.title'].toString().indexOf('{{VALUE}}') > - 1) |
contains (ignore case) |
(b['dom.title'].toString().toLowerCase().indexOf('{{VALUE}}'.toLowerCase()) > - 1) |
is defined |
(typeof b['dom.title'] != 'undefined') |
does not contain |
(b['dom.title'].toString().indexOf('{{VALUE}}') < 0) |
does not contain (ignore case) |
(b['dom.title'].toString().toLowerCase().indexOf('{{VALUE}}'.toLowerCase()) < 0) |
does not end with |
(!/{{VALUE}}$/.test(b['dom.title'])) |
does not end with (ignore case) |
(!/{{VALUE}}$/i.test(b['dom.title'])) |
does not equal |
(b['dom.title'] != '{{VALUE}}') |
does not equal (ignore case) |
(b['dom.title'].toString().toLowerCase() != '{{VALUE}}'.toLowerCase()) |
does not start with |
(!/^{{VALUE}}/.test(b['dom.title'])) |
does not start with (ignore case) |
(!/^{{VALUE}}/i.test(b['dom.title'])) |
ends with |
(/{{VALUE}}$/.test(b['dom.title'])) |
ends with (ignore case) |
(/{{VALUE}}$/i.test(b['dom.title'])) |
equals |
(b['dom.title'] == '{{VALUE}}') |
equals (ignore case) |
(b['dom.title'].toString().toLowerCase() == '{{VALUE}}'.toLowerCase()) |
greater than |
(parseFloat(b['cart_total_items']) > parseFloat({{VALUE}})) |
greater than or equal to |
(parseFloat(b['cart_total_items']) >= parseFloat({{VALUE}})) |
is badge assigned |
(typeof b['va.badges.42'] != 'undefined') |
is badge not assigned |
(typeof b['va.badges.42'] == 'undefined') |
less than |
(parseFloat(b['cart_total_items']) < parseFloat({{VALUE}})) |
less than or equal |
(parseFloat(b['cart_total_items']) <= parseFloat({{VALUE}})) |
is not defined |
(typeof b['dom.title'] == 'undefined') |
is not populated |
(typeof b['dom.title'] != 'undefined' && b['dom.title'] == '') |
is populated |
(typeof b['dom.title'] != 'undefined' && b['dom.title'] != '') |
regular expression |
(/{{VALUE}}/.test(b['dom.title'])) |
starts with |
(/^{{VALUE}}/.test(b['dom.title'])) |
starts with (ignore case) |
(/^{{VALUE}}/i.test(b['dom.title'])) |
Copyright All Rights Reserved © 2008-2021