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.
Related
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.
On the GA admin page, you have to check the section Use enhanced link attribution to activate Google Analytic's Enhanced Link Attribution.
But how does the code look like? Even if the feature is new, many sources seem to be dated. Is the code Google publishes on their doumentation page correct and complete, or should it be something else?
var _gaq = _gaq || [];
var pluginUrl =
'//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-XXXXXX-Y']);
_gaq.push(['_trackPageview']);
Yes that is correct, my full code looks like this
var _gaq = _gaq || [];
var pluginUrl ='//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-xxxxxxxx-1']);
_gaq.push(['_setDomainName', 'domainname.com']);
_gaq.push(['_setAllowAnchor',true]);
_gaq.push(['_setCustomVar',5,'CusVarName','CusVarNameValue',3]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
But if your setup is basic and according to the example you have given above it should work just fine. As long as you add the pluginUrl variable above the setAccount it should work.
I have set up cross browser tracking in google analytics in order to track goals. However at Goal Flow I only see my domain (mysite.com) listed at Visits by Source. I have set up tracking in the following way:
All non secure pages of my website contain the following code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', '.mysite.com']);
_gaq.push(['_setAllowHash', false])
_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 secure pages of my website, where the goals are realized, contain the following code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', '.my-securesite.com']);
_gaq.push(['_setAllowHash', false]);
_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 form that pushes data from the non-secure page to the secure page contains the following data:
<form id="21343" method="post" action="https://my-securesite.com" onsubmit="return _gaq.push(["_linkByPost", this]);">
Looking at the source of the page I do see all the utmx data being posted:
action="https://my-securesite.com/confirm.php?__utma=XXXXXXXXXXX" onsubmit="return _gaq.push(["_linkByPost", this]);">
Once I access mysite.com via for example a search on Google I do see the following utmx definition when posting data to my-securesite.com:
utmcsr=google|utmccn=(organic)|utmcmd=organic|
So apparently the code posts the right source....
What am I doing wrong here?
I discovered the reason why GA didn't display the right source for my goals:
I used this tracking code:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', '.mysite.com']);
_gaq.push(['_setAllowHash', false])
_gaq.push(['_trackPageview']);
I was informed that the right tracking code now looks like:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
_gaq.push(['_setDomainName', '.mysite.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
As _gaq.push(['_setAllowHash', false]) is no longer used.
Besides that I used GA's option to track additional pageviews at the checkout page. I used to work with this code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
_gaq.push(['_trackPageview','/funnel/G1/Page-name']);
</script>
However the right code is:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-Y']);
_gaq.push(['_setDomainName', '.my-securesite.com']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview','/funnel/G1/Page-name']);
</script>
Since I implemented these changes GA tracks the source of my goals correctly.
I have multiple accounts on some pages - I am trying to track some events - they fire beautifully when I test them on Fiddler - but they are not coming into my analytics - the code is below - what am I doing wrong? Three days later any help would be GREAT.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
//tracking for first
['_setAccount', 'UA-XXXXXX-1'],
['_trackPageview'],
//tracking for second
['b._setAccount', 'UA-XXXXXX-16'],
['b._trackPageview'],
['b._trackEvent'],
['b._trackPageLoadTime']
);
(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';
(document.getElementsByTagName('head')[0] ||
document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
<li><a href="#anchor_2" class="gray"
onClick="_gaq.push(['b._trackEvent', 'button3', 'menu', 'clicked']);">link</a></li>
Note that _trackPageLoadTime is deprecated now. You don't need that anymore. Also the event on the top doesn't make sense. Events must have at least two string parameters and they have optional 3rd string parameter and 4th integer parameter.
So your code on the top should look like this:
var _gaq = _gaq || [];
_gaq.push(
//tracking for first
['_setAccount', 'UA-XXXXXX-1'],
['_trackPageview'],
//tracking for second
['b._setAccount', 'UA-XXXXXX-16'],
['b._trackPageview']
Then when you're firing the event you are only sending this to your b account and I believe you want to send to both. So for that reason you should do something like this:
<li>take me somewhere</li>
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.