chobo
chobo

Reputation: 32301

My Custom Variables are not showing up in Google Analytics

I have been trying to setup a custom variable for the past few days and it hasn't been working.

My Google tracking code is part of a master page (asp.net concept) so I can't set the custom variable inside the second script block labeled "Async Google Code" because it is shared by many other sections.

Below is my code and the order it appears in my page. Is there any way I can set it outside the "Async Google Code" script?

<head>

<!-- Setting Custom Var -->
<script type="text/javascript">
     $(function () {
        _gaq.push(['_setCustomVar', 1, 'Account', 'UserType', 2]);
     }
</script>

<!-- Async Google Code -->
<script type="text/javascript">
     var _gaq = _gaq || [];
     _gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
     _gaq.push(['_trackPageview']);

     (function () {
         var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
         ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
         var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     })();
    </script>

</head>

Upvotes: 2

Views: 2660

Answers (3)

Mike_K
Mike_K

Reputation: 9576

You need to set the custom variable before track pageview. You have the custom var in the jQuery document ready shortcut, making it so that it happens after the trackpageview.

Upvotes: 1

bozdoz
bozdoz

Reputation: 12890

Your "setting custom var" code is missing an end bracket.

Upvotes: 2

CrayonViolent
CrayonViolent

Reputation: 32537

wrap your custom variable stuff in a function to be called and insert a call to that function between the var _gaq... and _trackPageview lines in the bottom piece.

Upvotes: 3

Related Questions