Rich-text Reply

Create Dimension with dataLayer var

dombur 03-30-16

Create Dimension with dataLayer var

Hi everyone,

 

we want to be able to segment our test results by different segments (if user is logged in or not). To realize this we set up a variable in our GTM dataLayer (loggedIn = true; loggedIn = false). How can I create a dimension in Optimizely (dimensions tab) which checks the state of this variable and handles the different segments?

 

Many thanks for your help!

 

Best,
Dominik

Level 2

JasonDahlin 03-30-16
 

Re: Create Dimension with dataLayer var

[ Edited ]

@dombur -

Hi Dominik.

Have you tried the steps outlined in this article?

https://help.optimizely.com/hc/en-us/articles/200040865#custom_dimensions

 

 

Once the dimension is created, you will add code to every page of your site that pushes the dimension's value.  The value you push to Optimizely will be either the value you can get out of your GTM data layer or replicate the same logic you put into setting the GTM value into setting the value you send for this dimension.

 

Any goals that are met when a user is "logged out" will be reflected in the "logged out" segment.

Any goals that are met when a user is "logged in" will be reflected in the "logged in" segment.

 

Note - if you have "Page View" goals... the goal will be "met" before you send the dimension's value on that page.  For example... If you had a dimension that tracks purchase history and you set it on the Order Confirmation page which also has a Page View goal on it... when a user who has "no purchase history" completes a purchase, their value on the "Order Confirmation Page View" goal is "no purchase history", _then_ they are put into the "has previous purchase" segment.

 

Similarly, when a user logs in... if you have a goal set up for the page that a user sees after they log in (e.g., their Account Profile page) the segment's value for a user who just logged in will be "logged out".  If the user refreshes the page or otherwise navigates to the Account Profile again, the subsequent page hit will be reflected in the "logged in" segment.

--Jason Dahlin
Analytics and Testing Guru Smiley Happy
Experimentation Hero
dombur 03-30-16
 

Re: Create Dimension with dataLayer var

[ Edited ]

Hi,

 

thanks for getting back to me, Jason! We already have an existing variable (userLoggedIn) in our dataLayer which collects the login state of our users. I also set up the dimension (with the same API name as our variable) via the dimension tab in Optimizely. Now, we have to make Optimizely aware of the current userLoggedIn state (from the dataLayer) - But how (and where) to do that? Smiley Frustrated

 

I tried to write this line into the experiment JS:

 

optimizely.push(['setDimensionValue', 'userLoggedIn', 'yes', 'no']);

 

This enabled the segmention but I can only segment by "yes" even if I'm logged out. After that I tried to add the variable like this:

 

optimizely.push(['setDimensionValue', 'userLoggedIn', '{{userLoggedIn}}']);

 

But that also seems not to work. Probably it's better to write this into the variation code instead?

 

Do you have any ideas how to solve this? Many thanks!

 

Best,
Dominik

Level 2
JasonDahlin 03-30-16
 

Re: Create Dimension with dataLayer var

@dombur

 

It's a two step process.

 

Step 1 - set the dimension's value (presuming {{userLoggedIn}} is the actual yes/no value):

optimizely.push(['setDimensionValue', 'userLoggedIn', '{{userLoggedIn}}']);

Step 2 - send the dimension's value to Optimizely

window.optimizely.push(['trackEvent', "sendSegmentData"]);

I have always put this code into the actual page so that it is captured on EVERY page hit, not just ones that happen to be involved in an experiment.  For me, this means adding it as a "tag" in my tag management system or directly into a common JS file that is shared on all pages.

--Jason Dahlin
Analytics and Testing Guru Smiley Happy
Experimentation Hero