Google Analytics, Page views are not tracking correctly - google-analytics

I have installed the below google tracking code in my site
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);
})();
In my GA account under visitors -> page views are not showing correctly. After many visits to the site it is showing only page views as 2. The total number of page views doesn't seems correct.
Is there any problem in my tracking code. Please give me a solution on this.
The Code is placed just before the </body> closing tag as it was recommented as best practice of placing analytics code. We placed the code in all pages and the status in GA is "Receiving Data". It is a video sharing website where we also use Google Analytics Plugin of JW Player. Following is a url to a site page storybridge.tv/StoryBridge/freespirits/story/fightclub
I also checked and confirmed that there is no other script that use the variables _gat and _gaq.

Make sure that other scripts on your pages do not use the variables _gat and _gaq, since those are global variables used by the asynchronous tracking code. As long as those variables are not used by other scripts on your pages, there should be no other interference with the tracking code from your own scripts.

Related

Google Analytics - Custom iFrame Tracking

I made a small little Tic Tac Toe game that plays perfectly at http://tic.cwoebker.com.
The actual tic tac toe game is loaded from (/tic) and embedded in an iframe.
Therefore others could easily embed the game on their own site if they wanted.
I am doing some event tracking inside of the iframe.
Right now I have it setup so it fires a page view on both the main page
and the actual game code inside the iframe.
I was wondering whether I could somehow only fire the page view for the iframe if its not
embedded on http://tic.cwoebker.com but on another site.
So that everything thats tracked under root (/) is traffic on my site and everything tracked in the i frame (/tic) traffic generated by embedding on another site.
Right now my analytics code in the iframe looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxxx-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>
Thanks a lot in advance.
As you're in an iFrame on a separate domain, you can't access the parent window to get the location. Check out this demo and/or google it a bit: http://jsfiddle.net/TomFuertes/RRB52/2/
_gaq.push(['tictactoe._setAccount', 'UA-xxxxxxxxx-x']);
// Line below causes security issues, thus won't work
_gaq.push(['_setCustomVar', 1, 'Domain', window.parent.location.host, 3]);
_gaq.push(['tictactoe._trackPageview']);
You can pass the domain using a querystring on your iFrame page, you'd need to modify the include code to look like this: https://stackoverflow.com/a/5697801/94668
<script type="text/javascript">
document.write('<iframe src="//tic.cwoebker.com/?url=' + window.location + '"></iframe>');
</script>
Then you'd filter out your Google Analytics appropriately.
You can use Google Analytics campaigns to track the traffic. You will need to distribute the embed code that already has the campaign parameters as part of the embed iframes src.
Hope that helps.
Interested to hear from others.

Google Analytics Campaign tracking with external payment site

I have a webshop where users come from many different other sites and newsletters. To track where the people came from, we use campaigns in Google Analytics.
Now we are implementing our own external payment site.
After a user places an order, they will be redirected to our payment site. After a succesfull payment, they should be redirected back to the original site. On the original site the ecommerce values will be fired into Google Analytics.
When I do this like I described above, I lost the campaign when insterting the ecommerce data. How do I make sure this information isn't lost?
[edit]
I found adding 'utm_nooverride' should to the trick. However, I can't find it clearly in the Google Analytics documentation
To solve the above:
On both sites (yes, the payment site should have a GA too), you need to set _setAllowLinker to true, and the _setDomainName to 'none'.
IE:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-YY']);
_gaq.push(['_trackPageview']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setDomainName', 'none']);
(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>

Google analytics script on dev site

I'm setting up google analytis on my webpage using the standard script:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-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>
If I include this site on my UAT page (e.g. http://uatsite.com/) will google track any activity or will it only track activity on my main site (e.g. http://production-site.com).
thxs
The domain (or, as GA likes to call it, hostname) from which Google Analytics receives its info doesn't matter and really it's up to the client to define it (and is very much exploited, see this for just one example).
If you don't want to track activity on your UAT site, you can create a Hostname filter to prevent the data from being recorded. This filter can be of include type so that only your production site registers or exclude type so it excludes only your UAT site.
Alternatively, you can modify your analytics code to not track on the UAT site:
if (!/uatsite/.test(window.location.hostname)) _gaq.push(['_trackPageview']);
This will only collect analytics for the url you configured. This will not collect from any other domain.

Google Analytics reports to be receiving data, but none is showing up

Hi recently redesigned my site (http://bit.ly/gwrYwb) which was formerly tracking pageviews properly via Google Analytics. After the redesign, I inserted the exact same code right before the </head> tag:
<script type="text/javascript">
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);
})();
</script>
(The UA number is correct on the actual page.) However, GA is mysteriously reporting zero pageviews/visits, even though it claims to be receiving data. Has anyone experienced a problem like this before? The only other JS I'm using is including jQuery, as well as a widely-used jQuery plugin on one of my pages.
This is kind of lame, but have you checked your profile filters? You might still have old filters (for the former website) applied that filter all urls out.
We had this problem with another website and were debugging for weeks until we found this simple solution...

Using two separate accounts IDs for tracking

I have tracking code A on the main site www.example.com and tracking code B on www.example.com/blog which is a wordpress.com based blog (the site itself is plain PHP).
Not surprisingly, traffic from the blog is not shown on the main site and visa versa.
I would like to use tracking code A on the blog as well to create a "roll-up" profile while maintaining the profile I currently have with tracking code B.
I thought that the right way to do it is using the following code:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['t2._setAccount', 'UA-XXXXXX-2']);
_gaq.push(['t2._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);
})();
but I read here:
http://www.google.com/support/forum/p/Google%20Analytics/thread?tid=640080c650f67bd1&hl=en
that it causes a multiplication in visitor numbers and such.
What is the correct way to do this?
Should I explicitly specify the domain and use the _setAllowLinker() method as described in the linked post above despite the fact that it's the same domain?
Any help will be much appreciated.
Thanks,
Alexander
P.S
I read Google Analytics - async tracking with two accounts but I still don't have a definite answer.
The easiest way to achieve the results you're looking for is to use a single account/profile ID site wide and use profile filters to create a 'Blog Traffic Only' profile.
Sitewide you would call:
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-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, log in to Google Analytics, select your account (if you have more than one), add a new profile (for an existing domain) under the UA-XXXXXX-1 profile number, and call label it 'Blog Traffic'.
Once you create the profile, click to 'Edit' the profile you just created. Scroll to 'Filters Applied to Profile' and click 'Add Filter'. Google Analytics provides a pre-defined filter for traffic to a subdirectory (include only traffic to the subdirectories that are equal to '^/blog.*' or just '/blog').
Now, you'll have a profile that includes all traffic to your site and a second profile that includes traffic only to the blog subdirectory.
More information on using data filters:
http://www.google.com/support/analytics/bin/answer.py?answer=55496

Resources