0
votes

I'm trying to send a custom JavaScript variable from Google Tag Manager (GTM) to Google Analytics (GA).

These are the steps that I've taken:

  1. I created the custom JavaScript variable in GTM as follows:

    function() {
    var metas = document.getElementsByTagName('meta'); 
        for (i=0; i<metas.length; i++) { 
            if (metas[i].getAttribute("id") == "ctl00_BDMeta_Username") { 
            return metas[i].getAttribute("content"); 
            } 
        }
    }
    

When I preview it in GTM, the content is being returned correctly (userName) in the preview mode and GA debugger (dimension1):

GTM Preview

GA Debugger

When I leave preview mode in GTM, and refresh the page and look at GA debugger, the dimension1 value is null.

Running command: ga("gtm1447092619110.set", "dimension1", null)

In GA, I created the custom dimension called User Name as a session and index 1.

In GTM, I went to the UA Tag, under configure tag and set the custom dimension to index 1 and the dimension value.

Dimension

I guess my question is, is it set up correctly? Why is null showing up when preview mode is on in GTM, it works and shows up correctly.

1
Did you published your updated container? - Jakub Kriz
Can you please clarify: you said "When I leave preview mode in GTM, and refresh the page and look at GA debugger, the dimension1 value is null.", but then you are asking "Why is null showing up when preview mode is on". If it's null when it's not in preview mode, then that is because the container has not been published yet, so any changes would not be applied to the site. - nyuen
Yeah, completely agree - you need to publish the container - Dmitry

1 Answers

1
votes

Everything appears to be setup correctly. Preview mode serves as a testing environment in GTM. So what you are describing is normal behavior. While preview mode is on your changes are live for your session so that you can test and debug. Once you're satisfied that everything is working as you intend it to you need to publish the container version you're working on. At that point all your changes will be pushed live for all users.