- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
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?
That is a great question, @giacomo_ritucci. Let me ask someone here if they know the answer.
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.
@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:
load_my_tag
) into Tealium from the Data Layer tab.
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 }
Copyright All Rights Reserved © 2008-2023