I got the cookie method of excluding my traffic to work when I didn't specify the domain. Now that I have specified the domain, it no longer works. It appears to be setting two cookies, the exclude.html page I created is setting a cookie of "mydomain.com" and the google analytics is setting a cookie of "www.mydomain.com".
Here is the code for my exclude.html page.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Exclude Me</title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setVar', 'exclude_me']);
_gaq.push(['_setDomainName', 'www.mydomain.com']);
_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>
</head>
<body>
<p>
This computer now has a cookie placed on it to exclude it from any Google Analytics reports.</p>
<p>
If you delete your cookies, you will need to revisit/reload this page again.</p>
</body>
</html>
I added the _gaq.push(['_setDomainName', 'www.mydomain.com']); to try and get it to work which doesn't appear to be doing anything. That is the way I have it setup for all the other pages, using the www.mydomain.com.
As I was typing this it appeared to me that the '_gaq.push(['_setDomainName', 'www.mydomain.com']);' should probably be put in before '_gaq.push(['_setVar', 'exclude_me']);' So I switched them around and it is no longer creating two different cookies, so hopefully that works.
When setting a "setDomainName", you should exculde the www from .mydomain.com.
It's also important to notice that (.mydomain.com) and (mydomain.com) are two different domains and hence result two cookies (they are both valid, but you should stick with one of them).
Related
I am generating the Event tracking in Google analytic. but i can not see the event is generated with in Behavior link -> Events -> Overview.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-46891304-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);
})();
_gaq.push(['_trackEvent', 'ProfileMenu', 'MenuClick', '', 1]);
</script>
</head>
<body>
<h1>This is for Tracking Event..!!!</h1>
</body>
</html>
Regards
You need to attach the event tracking script on to a event listener.
Your event tracking code does not seem to be attached to anything.
For example if I wanted to track a button click this is how I would write it with jQuery.
html
<button id='button1'>Button<button>
JavaScript/jQuery
$('#button1').click(function(){
//fires the event tracking method when button is clicked.
_gaq.push(['_trackEvent', 'Category', 'Action', 'Opt Label', Opt Value, 'Opt non-interaction'])
})
Here is all the documentation https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
And here is a post that I went in more in depth into event tracking.
Let me know if you have any other questions.
It takes 24 hours for data to be processed. Before that time you should be able to see your events in the Real-time reports under
Real-time -> events.
after 24 hours has passed the data should show up under.
Behavior link -> Events -> Overview.
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.
Here is my problem:
We have page contained in iframe (url of iframe page - www.iframepage.com). That page has link UPGRADE on it. When user clicks on that link, he gets directed to billing page, which is located on different domain (www.billingsite.com/cc.html).
That page should be open on top (not in iframe).
If I use _link, GA cookie values will get passed to target page and cross domain tracking will work, BUT target page will open in iframe.
UPGRADE
https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._link
I would need a solution that will provide both: target page should open on top (not in iframe) and GA _utm parameters should be passed to target url so cross domain tracking could work.
Any help will be appreciated, thanks.
The _gaq.push(['_link', url]); function targets the current window with the 'url' you send it. It ignores target. What you need to do is call the Google function but then update the parent location.
Your page within the iFrame should look something link this
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-xx']);
_gaq.push(['_setDomainName', 'example.com']);
_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);
})();
</script>
</head>
<body>
Link
<script>
function your_GA_track_link(url){
_gaq.push(['_link', url]);
self.parent.location.href = url;
return false;
}
</script>
</body>
</html>
I think I have found solution. Here is code that should be put in body:
<script type="text/javascript">
function openWindow(link) {
_gaq.push(function() {
var tracker = _gaq._getAsyncTracker(); //add name param if needed
window.open(tracker._getLinkerUrl(link.href),"_parent");
});
return false;
}
</script>
UPGRADE</br>
I have created a webapp using backbone.js and I am trying to integrate google analytics in it. The thing is script execution always stops at some point inside ga.js. The code where the execution stops is like this (beautified version) ...
var o = e == "_gat" ? K : e == "_gaq" ? Tc : K.p(e);
o[f].apply(o, b[d][ha](1))
minified version (line 21)
new ActiveXObject(d),e=c.GetVariable("$version")}catch(o){}e&&(e=e[w](" ")[1][w](","),e=e[0]+"."+e[1]+" r"+e[2])}b=e?e:"-"}Pc=b;
I am logging the events like this:
_gaq.push('_trackEvent', '[header] login', 'click');
I am seeing the code being stopped at the live above in Firebug script tab. If I disable the debugging the google analytics request is not made. The app works fine.
What could be going wrong here? Has anybody else encountered such problem.
UPDATE
It seems like the problem is not related to backbone.js. Even created the simplest of page like this gave the same problem. I checked the Net tab in Firebug - the __utm.gif does load. ga.js also loads successfully. But the pressing the button again gives the same break in execution.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XX-XXXXXX-XX']);
_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>
<script type="text/javascript">
function check() {
alert("hi");
_gaq.push('_trackEvent', 'check');
}
</script>
</head>
<body>
<input type="button" value="abc" onclick="check();"/>
</body>
</html>
You're calling _trackEvent wrong. Note that the first 2 parameters to _trackEvent are required and the last 2 optional. Also it should be inside brackets.
Check the signature of the function.
You're call should be
_gaq.push(['_trackEvent', '[header] login', 'click']);
and
_gaq.push(['_trackEvent', 'check', 'something else']);
I have ecommerce tracking set up on my site and in google analytics. The problem is that sometimes it tracks the e-commerce sales but sometimes it doesn't.
Here is the code which is being output before my closing body tag:
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(["_setAccount", "UA-2795368-10"]);
_gaq.push(["_trackPageview", "/checkout/onepage/success/"]);
(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>
<!-- END GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
_gaq.push(["_addTrans","100000029","","10.0000","0.0000","0.0000","asa","","GB"]);
_gaq.push(["_addItem","100000029","12","Test Item","","10.0000","1.0000"]);
_gaq.push(["_trackTrans"]);
//]]></script></div>
One of the advantages of async Google Analytics is that you can put it at the top of the page.
Google recommends putting it at the top of the body, not the bottom. Your intermittent tracking may be due to people leaving the page before the tracking beacon has been sent. This could be fixed by putting the code higher in the page.
http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html#Installation
Your code looks good otherwise. It would be help if you posted the live URL though.