Load Rules as Extension Conditions

rebman
Employee Emeritus

As we all know, although the functionality of Load Rules is similar to Conditions, we can't manage extensions using Load Rules or use those Load Rules to replace Extension Conditions.

Load Rules are always in the same location in the UI and can be applied more than once which makes them easy to maintain. They also have the bonus ability to manage timeframes as conditions as well.

TealiumIQ_Loadrule.png

We often have the problem of needing to maintain multiple extensions with the same Conditions which could be leveraged by a Load Rule instead.

Here is my take on how we can take advantage of Load Rules within Extensions, and perhaps simplify some implementation and maintenance.

The first method generates a copy of the load rules and re-evaluates them on each event. It works both before and after Load Rules.

The second works only after Load Rules and does not re-evaluate the load rules on each event.

These extensions will have to sit as first 2 extensions before any of the extensions that take advantage of this logic.

Advantages of this Implementation:

  1. Re-use load rules multiple times in as many conditions as needed.
  2. Easier to manage date ranges via Load Rules UI.
  3. Manage different combinations of Load Rules. Default options are "All" or "Any". With this implementation, you can manage any number of conditions instead. See step 3 below.

Method 1 - Works Before and After Load Rules

This method involved re-evaluating the load rules at each event.

The data is stored in utag object under lr_eval.

Step 1 - Create New Variables

Create a new variable for each of the Load Rules you want to reference.

To keep it simple, let's say we are working with Load Rule UID 1 which checks if Visitor Known badge (5885) is assigned.

We can call it loadrule_id1.

You could also give it a more descriptive name in the Alias: Load Rule - Visitor Badge Assigned.

Step 2 - Javascript Code extension

Scope to Before Load Rules

var key;
utag.lr_eval = {};

// Make copy of load rule object and default to false for (key in utag.loader.GV(utag.cond)) { utag.lr_eval[key] = false; }

// Update lr_eval values with load rule conditions
utag.loader.loadrules(b, utag.lr_eval);

// Add the load rules evals to the data layer
for (key in utag.lr_eval) { var val = utag.lr_eval[key];
b["loadrule_id" + key] = (val == 1 || val == true || val == 4) ? "true" : "false"; } 

Step 3 - Capture the Load Rule conditions

Create a Set Data extension. 

Title: Load Rules as Conditions

Scope: All Tags Before Load Rules

Assign values for each load rule you wish to use in the Set Data extension to the value from the utag.lr_eval object. The value returned will usually be 1/true or 0/false. Tealium IQ 2019-10-01 13-42-27.png

For matching ALL:

utag.lr_eval[1] && utag.lr_eval[2]

For matching ANY

utag.lr_eval[1] || utag.lr_eval[2]

You can also take advantage of multiple load rules using AND/OR/NOT conditions  (&&, ||, !).

(utag.lr_eval[1] && utag.lr_eval[2]) || (utag.lr_eval[3] && !utag.lr_eval[4])

Step 4 - Add Dummy Tag

Add a new Tealium Custom Container and remove everything inside the template. We don't need the tag to fire, but we do need the Load Rule to be associated with a tag for it to be evaluated.

Add each of the load rules to the tag, and publish to all environments.

Step 5 - Use it in extension conditions

In the conditions, select loadrule_id# and check if it equals true or false

Tealium IQ 2019-10-01 11-44-32.png



Method 2 - Works Only After Load Rules

Step 1 - Create New Variables

Create a new variable for each of the Load Rules you want to reference.

To keep it simple, let's say we are working with Load Rule UID 1 which checks if Visitor Known badge (5885) is assigned.

We can call it loadrule_id1

You could also give it a more descriptive name in the Alias: Load Rule - Visitor Badge assigned

Step 2 - Capture the Load Rule Conditions

Create a Set Data extension.

Title Load Rules as Conditions
Scope: All Tags After Load Rules

Assign values for each load rule you wish to use in the Set Data extension to the value from the utag.cond object. The value returned will usually be 1/true or 0/false.Tealium IQ 2019-10-01 11-30-22.png

For matching ALL:

utag.lr_eval[1] && utag.lr_eval[2]

For matching ANY

utag.lr_eval[1] || utag.lr_eval[2]

You can also take advantage of multiple load rules using AND/OR/NOT conditions  (&&, ||, !).

(utag.lr_eval[1] && utag.lr_eval[2]) || (utag.lr_eval[3] && !utag.lr_eval[4])

Step 3 - JavaScript Code Extension

We will use this to assign all the Load Rule values as a string of "true" or "false" for consistency.

for (var key in b) {
if (key.indexOf("loadrule_id") > -1) {
var val = b[key];
// Set to "true" if 1 or true or 4 (bundled)
b[key] = (val == 1 || val == true || val == 4) ? "true" : "false";
}
}

Step 4 - Add Dummy Tag

Add a new Tealium Custom Container and remove everything inside the template. We don't need the tag to fire, but we do need the Load Rule to be associated with a tag for it to be evaluated.

Add each of the load rules to the tag, and publish to all environments.

Step 5 - Use it in Extension Conditions

In the conditions, select loadrule_id# and check if it equals true or false.

Tealium IQ 2019-10-01 11-44-32.png

That is it. Hope you get lots of use out of it! Please share your feedback in the comments.

11 Kudos
Public