Google Analytics custom variables not showing up - google-analytics

I have been running this code for some time now on all pages. This custom variable has never shown up.
Sorry to ask this again, I don't see another post that solves my case. This has to be the simplest case in the world, this is the same code with only the UA changed:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, 'User', 'jc', 3]);
(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>
I did not modify the (function()...) .. Do you see the problem? I'm using slot 1 with the page level (3) scope. The same code appears on each page for a given user.

_setCustomVar does not trigger a request to GA. _trackPageview does. You have to move the _setCustomVar above the _trackPageview.

Related

Google analytics _trackEvent not functioning

I have used _trackEvent for several links. But in google analytics it shows as 0 events and no tracking data are displayed.
Below is the code I used. Do I have to wait 24 hours to view the tracking data? or anything wrong with this?
<a href="https://sites.google.com/site/example/"
onClick="_gaq.push(['_trackEvent', 'Links', 'Bags', 'Mainlinkbags']);"
target="_parent">
tracking code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-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)
();
Sometimes it is good practice to use "onmousedown" event instead of "onclick" because "onmousedown" is fired sooner, so GA script has more time to execute event tracking (it's only a few milliseconds difference, but can help). Try it.
http://www.w3schools.com/jsref/event_onmousedown.asp

Google Analytics Tracker not working in ASP.NET website

I've got a client with about 6 websites that are all the same framework in VB.NET. I've tried to add Google Analytics Tracker inside each of them with no success. I've many clients with WordPress website or with my custom CMS (in JavaServer Faces) that are working perfectly. I'm pretty sure I'm doing something wront in VB.NET which I almost never use.
Here is the code in VB.NET I'm currently using :
<head>
...
<!-- Google Analytics -->
<asp:ContentPlaceHolder ID="GoogleAnalyticsTracker" runat="server">
<script type="text/javascript">
alert('ga-start');
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= m_sIDGoogle %>']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_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);
alert('ga-stop');
}
)();
</script>
</asp:ContentPlaceHolder>
</head>
Note : I've tried just before the </body> too, as described in Google Analytics.
Here is the rendered result :
<script type="text/javascript">
alert('ga-start');
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA–29119317–1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_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);
alert('ga-stop');
}
)();
</script>
Also note that the two alert('') are working, Firebug tell me that the ga.js is loaded too.
After all that, nothing is tracked in Google Analytics. Someone have an idea of what I'm doing wrong?
You can also visit the test website : http://mouk-mouk.amiesterre.com
Finally fixed, I don't know why, but the codes were wrong :
UA–29119317–1 > UA-29119317-1
UA–29119317–1 > UA-29119317-1
Visually we see nothing in Courier New...

Google Analytics Custom Variables not working

I am trying to log the username of users who are using my system. Unfortunately, I couldn't track by using custom variables. I could track the page visit, but custom variable tracking is not working. Could you please help me? Thanks.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxx-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setCustomVar',1,'UserName','JohnPaul',2]);
_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>
The code is correct and it does track the users now. I just used the similar codes as above and it works now. But I needed to wait 2 days to track the custom variables and it appears in my reports now.
For more than one user, you'll have to use PHP to output user names.
_gaq.push(['_setCustomVar', 1, 'UserName', '<?php get_usernames(); ?>',2]);
***Substitute "get_usernames" with the function for your site that retrieves the usernames.

Analytics custom variables

I'm trying to make a custom report.
I've just put some test code on my main page:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12323748-3']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar',
2, // This custom var is set to slot #1
'Test_var', // The name acts as a kind of category for the user activity
'Yes', // This value of the custom variable
2 // Sets the scope to session-level
]);
(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>
My custom report setup looks like this:
http://updo.nl/file/ed351e11.png
However, it just comes up as empty (I let it gather data for 2 days before checking the report)
Any help would be appreciated
I've asked much the same question. I've been told that you have to put the setCustomVar line above the trackPageView line and below the var _gaq line. Like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12323748-3']);
_gaq.push(['_setCustomVar', 2, 'Test_var', 'Yes', 2]);
_gaq.push(['_trackPageview']);
_trackPageview sends all of the information to Google Analytics, so you can't add information after its already sent.

Google Analytics _setCustomVar issue

I'm trying to set a custom variable in my Google Analytics tracking for a very rough form of split testing.
The code I'm using at the end of my 'head' section is
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-xxxxxx-xx'],
['_setCustomVar', 1, 'split', '1', 2],
['_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);
})();
The page view is tracking fine but I'm not seeing anything other than "(not set)" under the User-defined sub-section of the Visitors section.
Can anyone spot anything wrong? I've had this working before using the older ga.js before the Asynchronous stuff came along.
Thanks.
_setCustomVar data shows up in the Visitors "Custom Variables" report. Only data from _setVar shows up in the "User Defined" report.

Resources