AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
5K members online now
5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Using an array in dataLayer to create custom dimensions via GTM

Follower ✭ ☆ ☆
# 1
Follower ✭ ☆ ☆

I`m using some custom javascript to get optimizely experiment data in google analytics via Google Tag Manager.

For those interested, I`m using this script.

 

The dataLayer content generated by this looks like this:

 

Optimizely_exps: '{"Experiment 1":"Variation 1","Experiment 2":"Control"}' 

As you can see there can multiple experiments in the array.

 

From this post I know how to do this without GTM, but I`m currently trying to figure out how to set this up using GTM. I know how to do this with a datalayer that has no array but just one name and value, by creating a user defined variable and use this as value for the custom dimension in the standard analytics page view tag.

 

How do I go about this when I have an array as shown above? I know I can read this out by using something like Optimizely_exps.1, but I wouldn't know at what point to do this nor how to use the multiple results as multiple custom dimensions.

1 Expert replyverified_user

Re: Using an array in dataLayer to create custom dimensions via GTM

Rising Star
# 2
Rising Star
Hey Auke,

So Optimizely_exps is passed to the dataLayer? How do you know if it's the variation or the original? Do you have two firing rules that are URL based or based on the value of the dataLayer?

You use . notation (instead of normal JavaScript [ ] notation) to access the dataLayer variables when you have an array that said, these variables should be available as either Experiment 2 or Experiement 1.

Best,

Theo Bennett


Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

Re: Using an array in dataLayer to create custom dimensions via GTM

Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆
Hi Theo, thank you for replying. Optimizely_exps is passed to the dataLayer correctly yes. In the tag manager preview it looks like in my example.
Control and variation are identifiable by the value. The name is the experiment name and the value is control or variation name.

I guess my problem is that I don't know at which point to use the . notation to access the variables. How can I loop through them to get both set as custom dimensions upon a pageview?

Re: Using an array in dataLayer to create custom dimensions via GTM

Rising Star
# 4
Rising Star
Hey Auke,

Simo Ahava is the king of GTM coding and has some great code samples.

Start here:

http://www.simoahava.com/gtm-tips/access-array-members-in-the-data-layer/

Best,

Theo Bennett
Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn