Optimize
5.2K members online now
5.2K members online now
Everything you need to know about setting up Optimize including creating your account and container, linking to Google Analytics and how to tag your site.
Guide Me
star_border
Reply

dataLayer variable targeting not working

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi!

 

I am using GTM and Google Optimize to trigger A/B tests based on different dataLayer variables.

In my code, I'm pushing an object to the dataLayer and that variable is displayed in the Google Tag Manager Preview. 

I assume that this means that the object have been saved in the dataLayer.

 

However, when I am designing a rule where the A/B test should be triggered based on a certain property in my dataLayer object, it won't work properly.

Imagine this example: 

 

 

data {
 LoggedIn: true,
 IsConfirmed: false,
 Name: "John Smith",
 Company: {
  Name: "Company Name",
  IsActive: false"
 }
}

dataLayer.push('userData': this.data);

And in this case, I want to show an experiment to all users that have active companies.

 

How would I do that? I have tried using the snippet below, and evaluated if that condition is true.

 

userData.Company.IsActive

I have tried to fire events based on properties in my code, and evaluated based on that custom event. That method was successful, but I am aiming to solve it using less code. 

 

 

 

dataLayer variable targeting not working

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Solved the issue. The problem had to do with the order of statements.

At first you have to the object to the datalayer, and after that sending an event.

Not the opposite 

dataLayer variable targeting not working

Follower ✭ ✭ ✭
# 3
Follower ✭ ✭ ✭

Shouldn't your code read data = { on your first line? Also in Optimize, such a condition would need to be wrapped in a function in case you didn't do that. If you have done all this and it still doesn't work, I would see if there was a timing issue.