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:
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):
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.
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.


