Can I set an eVar in one rule and use it in another rule | Community
Skip to main content
New Participant
Feb 16, 2024 9:07 PM UTC
Solved

Can I set an eVar in one rule and use it in another rule

Can I set an eVar in one rule and use it in another rule?

 

Rule 1: 

set eVar1 = something

 

Rule 2:

if (eVar1 = something) {

return true 

} else {

return false

}

 

How do I do this?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Jennifer_Dungan
Jennifer_DunganAccepted solution
Level 2
Feb 17, 2024 12:25 AM UTC

Or, are you talking about in Launch? Actually tagging the site based on values that have been set?

 

This is actually easy, but you wouldn't do it at the "eVar" level, but at the "Data Element" level...

 

 

Data Element "X"

set the value to something

 

Data Element "Y"

(Custom Code)

var myVariable = false; if (_satellite.getVar('X') === "something"){ myVariable = true; } return myVariable;

 

I just shortened the code by setting the default value to false, so I didn't need all the "else" code.

3 replies

Level 3
Feb 20, 2024 1:12 PM UTC

Hi @sanjanakaranam 

 

Yes, you can set an eVar (variable) in one rule and then use it in another rule, but you need to ensure that the variable has been set before you try to use it in the second rule. Here's how you can do it:

Rule 1:

javascript

// Set eVar1 to something s.eVar1 = "something"; In the above code, s is typically an object representing your analytics tracking instance, and eVar1 is the variable you want to set.

 

Rule 2:

javascript

// Check if eVar1 has been set to "something" if (s.eVar1 === "something") { return true; } else { return false; }

 

In Rule 2, you're checking if eVar1 has been set to "something". If it has, the rule returns true; otherwise, it returns false.

Make sure that these rules are executed in the correct order, with Rule 1 executing before Rule 2. This ensures that eVar1 has been set before you try to use it in Rule 2.

Translate
Jennifer_Dungan
Jennifer_DunganAccepted solution
Level 2
Feb 17, 2024 12:25 AM UTC

Or, are you talking about in Launch? Actually tagging the site based on values that have been set?

 

This is actually easy, but you wouldn't do it at the "eVar" level, but at the "Data Element" level...

 

 

Data Element "X"

set the value to something

 

Data Element "Y"

(Custom Code)

var myVariable = false; if (_satellite.getVar('X') === "something"){ myVariable = true; } return myVariable;

 

I just shortened the code by setting the default value to false, so I didn't need all the "else" code.

Translate
Jennifer_Dungan
Level 2
Feb 16, 2024 11:56 PM UTC

You can sort of do this.. but it's only available in calculated metrics....

 

So you can use an IF statement:

 

IF ]

    [  Dimension X = something

           metric (likely occurrences in this case)

    ]

    [  Value If True

          metric OR static value

    ]

    [  Value If False

          metric OR static value

    ]

]

 

 

So you can look for the dimension value and return "1" for true, and "0" for false (using Static Number)

 

But this may not be exactly what you need... 

Translate