Reputation: 2277
Hi i wrote theses lines to trace some custom variables but nothing appears on analytics:
<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', 'XXX', 'xxx');ga('send', 'pageview');
// My custom vars
ga('set', 'User type', 'User');
</script>
And when i try to execute ga('set', 'Page type', 'Profil'); it returns "undefined"
Any ideas
Upvotes: 0
Views: 96
Reputation: 32780
There are no custom variables in Universal Analytics. There are up to 20 custom dimensions and metrics.
To use a custom dimension/metric you first need to create it in the admin interface (property settings->custom definitions). Every custom metric/dimension has a numeric index. You use the following syntax to send a custom dimension alongside a pageview (you need an interaction hit to transmit custom dimensions/metrics):
ga('send', 'pageview', {
'dimension1': 'My Custom Dimension'
});
That is you pass an JSON object as the third parameter to the pageview call (if you want to set the cookie domain etc. that goes inside the configuration object, too). The key is (for custom dimensions) the word "dimension" followed by the numeric index for that dimension (a number from 1 to 20, you can see the numeric index in the admin interface where you have created the custom dimension).
Upvotes: 2