Analytics
4.9K members online now
4.9K 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

Custom dimension for variable populated by meta tag | GTM

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

 

I'm updating the GA tracking on our site to Universal Analytics using Google Tag Manager. In our current setup, we have 2 custom variables that get data from 2 meta tags from the site - these are dynamically populated depending on whether the user is signed in so gets their subscriber ID (subscriberid), and how many users are presented with the paywall on article pages (storyaccess).

 

// set custom variables
_gaq.push(['_setCustomVar', 1, 'Subscriber', getMeta('subscriberid',''),3]);
_gaq.push(['_setCustomVar', 2, 'StoryPageAccess', getMeta('storyaccess', ''),3]);

 

I believe Custom Dimensions need to be created for these, how can this be done for the dynamic data above?

 

Any help is greatly appreciated.

 

Regards,

 

Jankee

 

1 Expert replyverified_user

Re: Custom dimension for variable populated by meta tag | GTM

Rising Star
# 2
Rising Star
HI Jankee,

You are correct, custom dimensions would need to be created in the property settings. They are much more powerful than custom vars, so you will be pleased. Smiley Happy

In regards to what you're passing that looks like it's looked up from somewhere . You may be able to change that into a custom JavaScript variable and returning that from a function. That said, it's always best to just have your developers pass anything you need into the dataLayer and create a dataLayer variable to get it and pass it into the GA tag.

More on that here:

https://support.google.com/tagmanager/answer/6106899?hl=en

Hope that helps.

Best,

Theo Bennett


Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

Re: Custom dimension for variable populated by meta tag | GTM

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
Hi Theo,

Thank you for your reply.

You're right, what I'm trying to pass is the value's that dynamically get populated in the following meta tag in the <head> section of the site:
<meta name="subscriberid" content="" />
<meta name="storyaccess" content="" />

Would I be able to store the value of the above in variables, which I could then pass that into a DataLayer?

Apologies, this is my first GA project.

Thank you in advance.

Jankee

Re: Custom dimension for variable populated by meta tag | GTM

Rising Star
# 4
Rising Star
Jankee,

If it's not stored in a global JavaScript variable, and is not in the dataLayer (preferred method) then you would need custom code deployed via a custom html tag or a function in a custom JavaScript variable that would "scrape" the data you need. Either way you would need a developer. (You could play around with CSS selectors etc but I wouldn't consider any of these stable.)

The best thing to do would be to ask your developers to deploy those values to the dataLayer on page load.

Does that help?

Best,

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

Re: Custom dimension for variable populated by meta tag | GTM

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭
Hi Theo,

Many thanks for this.

I've created the dataLayer now, and the value is being passed, although "undefined" is being prepended to the value of the meta tag value.

"StoryPageAccess: 'undefinedaccessgranted'" ... should actually be "StoryPageAccess: 'accessgranted'"

Do you know how this can be resolved?

Thanks,

Jankee

Re: Custom dimension for variable populated by meta tag | GTM

Rising Star
# 6
Rising Star
Hi Jankee,

Is that how it looks in your dataLayer? Sounds like a JS problem but I have no idea as it's specific to your platform. Just make sure you create the dataLayer variable and pass them into the custom dimension (when you get it cleaned up) You could use a custom JavaScript variable to remove the prepended undefined but just because you CAN do something doesn't mean you SHOULD. Smiley Happy

Best,

Theo
Analytics Evangelist at MoreVisibility | Contact Me
Connect on LinkedIn

Re: Custom dimension for variable populated by meta tag | GTM

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭
Hi Theo,

Yes, that is how it looks in the dataLayer.

Funnily enough, I have set it up as you have said in your reply:
- Set up Data Layer Variable
- Added the following code to the site to get the value of the meta tag called "storyaccess"
var storyaccess = getMeta('storyaccess');
- Created a Custom Dimension in Google Analytics
- Added the Custom in Google Tag Manager

The value is getting picked up, it's just getting prepended.

Sorry for all the questions.

Thanks,

Jankee

Re: Custom dimension for variable populated by meta tag | GTM

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭
Just to add to this, the dataLayer code on the site looks like this:

&lt;script type="text/javascript">
var subscriber = getMeta('subscriberid');
var storyaccess = getMeta('storyaccess');
dataLayer=[{'subscriberStatus':subscriber,
'StoryPageAccess':storyaccess}];
&lt;/script&gt;