Highlighted

Negative date range in load rule?

Silver Contributor
Silver Contributor

I'd like to automatically switch off a tag from date A to date B.

 

Is there a way to define a Date Range Condition that says "Load if not from date A to date B", in other words how can I negate a Date Range Condition?

3 REPLIES 3
Highlighted

Negative date range in load rule?

Employee Emeritus

That is a great question, @giacomo_ritucci. Let me ask someone here if they know the answer.

Remember to give me a kudo if you like my post! Accepting my post as a solution is even better! Also remember that search is your friend.
Highlighted

Negative date range in load rule?

Employee Emeritus

Hi @giacomo_ritucci,

 

You can define a Time-based Load Rule to fire a tag from Date/Time A to Date/Time B, but not the other way around.  Unfortunately, you cannot defined one to be the opposite (i.e. to not fire a tag from Date A to Date B)

Instead, you can create two copies of the tag: one to fire before Date A, and one to fire after Date B.  This way the tag never fires from in-between Date A to Date B.

Highlighted

Negative date range in load rule?

Employee Emeritus

@giacomo_ritucci you can also use some custom JavaScript. The code would look at a date range and compare it to the current date. Then, it will set a Boolean variable for the tag to load or not. The Boolean variable goes in a load rule and controls the loading of the tag. This code goes in an JavaScript Code extension scoped to pre-loader.

 

If you're interested in that approach, here's how to do it: 

 

  1. Add the Javascript Code extension from the extensions tab. The Javascript Code extension is under the Advanced tab. 
  2. Change the scope to Pre Loader and add the code (found below) to the extension.
  3. Add the variable name ( load_my_tag) into Tealium from the Data Layer tab.
  4. Create a new Load Rule that checks the value of load_my_tag and then assign it to the tag. date_control_lr.png
  5. Test the result

 

Here's the code for the JavaScript Extension

 

utag_data = utag_data || {}; // Storing the value in utag_data, making sure it was defined
utag_data.load_my_tag = "1"; // Variable to use in the load rule, will need to create the variable in the Data Layer in Tealium too, 1 is true
var firstDate = new Date(2017,04,20); // YYYY, MM, DD Months are 0 - 11, January is 0
var secondDate = new Date(2017,04,25);
var today = new Date(); // Today's date
if ( today.getTime() > firstDate.getTime() && today.getTime() < secondDate.getTime() ) {
  // If the variable today is past (greater than) the firstDate and before (less than) 
  // the secondDate do not load the tag
  utag_data.load_my_tag = "0"; // Set to false
}