- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
02-13-2023 03:20 AM
Hi there,
i've 2 variables set in mapping in GA4 tag, like this :
1)
custom value (if A == true return B else "" (empty string)) --> all_events.variable1
2)
custom value (if C == "D" return D else "" (empty string)) --> page_view.variable2
So, in the first case 1), the behaviour is correct. I don't see the variable in datalayer if the condition is false.
In the second case 2), when the condition is false i see the variable2 with empty string.
Why?
I would to see the variable in datalayer only if the condition is true.
Can you help me?
04-25-2023 06:21 AM
Hello There
To solve this issue we can use following steps:
- In Tealium iQ, navigate to the Data Layer tab and create two new variables, say variable1_condition and variable2_condition.
- In the Extensions tab, create a JavaScript Code extension with a "Before Load Rules" scope.
- Add the following code to the extension, replacing A, B, C, and D with the appropriate expressions or variables:
// Check condition for variable1
if (A == true) {
utag_data.variable1_condition = B;
} else {
utag_data.variable1_condition = '';
}
// Check condition for variable2
if (C == "D") {
utag_data.variable2_condition = D;
} else {
utag_data.variable2_condition = '';
}
In the GA4 tag mapping, map variable1_condition to all_events.variable1 and variable2_condition to page_view.variable2.
With this approach, the variables will only be set in the data layer when their conditions are true, and they will be empty strings when the conditions are false.
After implementing these changes, make sure to test the behavior on a development or staging environment before deploying it to production.
Copyright All Rights Reserved © 2008-2023