Reputation: 1382
I'm trying to use GA custom variables to do some a/b testing, but I think the way I've implemented it is not working properly. I started with the following code GA code, provided by Google:
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js',
'ga');
ga('create', 'UA-9541894-2', 'auto');
ga('send', 'pageview');
</script>
Then I did some reading about how to set the custom variable, so I added a few lines of code. That gave me the following:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9541894-2']);
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1. Required parameter.
'Show Footer', // The name of the custom variable. Required parameter.
'show', //
2 // Sets the scope to session-level. Optional parameter.
]);
_gaq.push(['_trackPageview']);
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js',
'ga');
ga('create', 'UA-9541894-2', 'auto');
ga('send', 'pageview');
</script>
With this code, i don't get an js errors in console, but I also see nothing showing up in Analytics. Also, I've read that you should see a request for an image called _utm.gif?blahblahblah and I'm not seeing that, so something has to wrong.
Anyone know how to fix this? Thanks!
Upvotes: 1
Views: 116
Reputation: 163
The _gaq
variable and Custom Variables are both from Classic Analytics, and you are using the Universal Analytics as you can see in www.google-analytics.com/analytics.js
In Universal Analytics, you'll have to use Custom Dimensions and Custom Metrics, that are much better.
Here is the Google Developer docs: https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
Upvotes: 1