Google Analytics _setCustomVar - strange data in my dashboard - javascript

I have set up the _setCustomVar for my website, like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX']);
_gaq.push(['_setDomainName', '.blog4ever.com']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, 'B4E_Type_Pub', 'Silver_ou_Gold', 3]);
_gaq.push(['_setCustomVar', 2, 'B4E_Etat_Blog', 'normal', 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>
In my dashboard, when I go in: Visitors -> Custom variables, I see my 2 variables but the numbers are really strange (like 40 pages views although I have many thousands pages views).
I have it installed for 2 days now.
Did somebody face the same problem?

You're lucky even 40 pageviews recorded these variables.
You need to call _setCustomVar before _trackPageview. Otherwise, the _trackPageview call sends the data to Google Analytics, and only after that are the custom variables set. If you set the _setCustomVar after the _trackPageview, the custom variable data doesn't attach, and if no other __utm.gif hits are set during that pageview, the data is basically gone forever.
(Those 40 pageviews that recorded probably were tracked via some other on-page GA calls that are sending data after the pageview loads).

Related

Why isnt my Google Analytics code tracking data across all domains?

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', 'example.com']);
_gaq.push(['_setLocalRemoteServerMode']);
_gaq.push(['_setLocalGifPath', 'http://www.example.com/__utm.gif']);
_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);
})();
I cannot display the actual websites and content so I changed the websites to random.com and the two websites that are not being tracked to example1 and example2.com Also the main website is example.com
This is a external js file that has GA tracking code. That is in the head tag of example.com It also has the cross tracking section with it. In var domains[ example1.com and example2.com] dont actually get tracked via google analytics.
I do not have access to external js file. So what I am wondering if there is a error in the way it was written.
I believe the problem could be one of three things or I am completely wrong ;
1.) example1 and example2 are actually within the website so subdomains not different domains.
2.) Or that it is not running through the whole array. Because all domains in var domains have push data into google analytics except example1.com and example2.com.
3.) Or gaq.push(['_setAllowLinker', true] needs to be gaq.push(['_setAllowLinker', [here the domains] true]
Edit: Removed irrelevant pieces of code
Found the solution. So i needed to ignore most of the code.
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_setDomainName', 'example.com']);
_gaq.push(['_setLocalRemoteServerMode']);
_gaq.push(['_setLocalGifPath', 'http://www.example.com/__utm.gif']);
_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);
})();
This is the only relevant part. I needed to delete
_gaq.push(['_setLocalRemoteServerMode']); //Pulls remote GA code for Urchin
_gaq.push(['_setLocalGifPath', 'http://www.example.com/__utm.gif']);
It seems this is outdated classic GA code after that the websites worked fine.

Google Analytics report to multiple profiles at the same time on different domains

I have two different GA profiles that I want to report to all the time. This HTML that will have the tracking code will also be run from different top-level domains.
Reading these links:
https://developers.google.com/analytics/devguides/collection/gajs/#MultipleCommands
https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#multipleDomains
I created this sample code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var parts = location.hostname.split('.');
var subdomain = parts.shift();
var topleveldomain = parts.join('.');
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-12345-5'],
['_setDomainName', topleveldomain],
['_setAllowLinker', true]
['_trackPageview'],
['b._setAccount', 'UA-12345-2'],
['b._setDomainName', topleveldomain],
['b._setAllowLinker', true]
['b._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>
<body>
Play
</body>
I used JavaScript to determine the top-level domain of the site hosting the tracking code, so it sets the command of _setDomainName to the value of the current domain.
I also added a link with a onclick event to send _trackPageview to GA for testing purposes.
The problem I'm having is that when the page loads, it doesn't sends the request to GA (should send page views request to a different profile each). This is not happening.
It just sends the request to one profile (the first in the array) when I do the onclick event, the normal page view is not firing up.
However, it does sends the page view requests if I remove the: ['_setAllowLinker', true] from both items of the array. But I need that if I'm going to be hosting the tracking code under different top-level domains, right?
Any ideas?
Thanks!
You're missing a couple of commas in your _gaq.push() parameters:
_gaq.push(
['_setAccount', 'UA-12345-5'],
['_setDomainName', topleveldomain],
['_setAllowLinker', true], <===
['_trackPageview'],
['b._setAccount', 'UA-12345-2'],
['b._setDomainName', topleveldomain],
['b._setAllowLinker', true], <===
['b._trackPageview']
);

Track Subdirectory Redirect link To PDF

I have a DotNetNuke website (hosted on IIS server), and most of my urls are very long. We have PDFs posted of our products, and we set up some shortcut urls for convenience that redirect using a meta refresh redirect. I recently read that these links will not be added to Google's index and can be considered "spammy". Also, these redirects are preventing Google Analytics from tracking these page views.
An example shortcut url we have set up is: mysite.com/awesomesauce
This would redirect to the PDF brochure of that product: mysite.com/products/sauces/awesome_sauce.pdf
I would like to add Google Analytics tracking to track when people access or click on the shortcut url link (mysite.com/awesomesauce). Is there a way to track access to this shortcut link that also avoids the "spammy" meta refresh method?
I considered putting some JavaScript at the bottom of the page:
<script>
// Google Analytics tracking code, etc.
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-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);
})();
// Redirect code (after tracking events fire)
window.location = "http://mysite.com/products/sauces/awesome_sauce.pdf";
</script>

Google-analytics _trackEvent doesn't get called from linked JS file

I have the asynchronous JavaScript from Google added to my HTMl page which adds the tracker:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_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);
})();
Then in an external JS file which is definitely loaded after ga.js I have the following:
function activateAnalyticsTracking(href) {
_gaq.push(['trackEvent', "test", "tester"]);
console.log("_gaq.push called");
}
Now my console outputs "_gaq.push called", and I don't have any other vars on the page called _gaq, so I don't understand why, when I use a HTTP logging tool like Fiddler2 I don't see a call made to Google-analytics.
I do see a call though when I simply run _gaq.push(['_trackEvent', "test", "tester"]) from the console, so the code for that call is definitely right.
I have this function used specifically because I run other events when I link is clicked, so I'd like to use it, can anyone help me understand why this wouldn't work?
TIA
Cheers,
Blaise.
Seems like you're missing one underscore in _trackEvent. It should look like this:
_gaq.push(['_trackEvent', "test", "tester"]);

Google Analytics Async Event Tracking

Wonder if somebody is able to clarify the following;
Using the aysnc google analytics code placed in the head of the document as follows
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-1']);
_gaq.push(['_setDomainName', '.somedomain.co.uk']);
_gaq.push(['_trackPageview', pageUrl]);
(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);
})();
On some the pages I am tracking I also use custom events to track video plays and which forms are used. These events use a further _gaq.push() call at various points on the page.
My question is should the final section of the initial analytics code (the section that calls ga.js be split and placed at the end of the page code or will any calls made once the script has loaded still be passed to Analytics regardless of the position on the page.
Thanks in advance.
No, the final section of the initial analytics code need not be placed lower down. You can call as many _gaq.push() calls as you like throughout the page, they'll still successfully pass to analytics.
The _gaq.push() event calls will send new requests to Google Analytics in addition to the first one you make (_trackPageview). You can check those event calls my inspecting how many requests your page makes for _utm.gif in a tool like Firebug.

Categories

Resources