Google analytics Report manipulation - javascript

I need a modified JavaScript which inflated the pageviews, unique visitors and visitor count!
For educational purposes because I want to see if there are certain patterns when artificaly altering the G. Analytics report
I coded this but it does not work:
<script type="text/javascript">
var i=0;
for (i=0;i<=10;i++) {
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19629541-9']);
_gaq.push(['_trackPageview']);
_gaq.push([_setDomainName, '.domain.com']);
_gaq.push([_setDomainName, 'domain.com']);
(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>​​​​
and this Code only alters the pageviews:
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
// Google Analytics
var pageTracker;
try {
pageTracker = _gat._getTracker("UA-15064357-1"); // pour dystroy.org
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
for (var i=10; i-->0;) pageTracker._trackPageview();
} catch(err) {console.log(err);}
</script>​
I am asking becasue I recenlty viewed an analytics report which did not quite mach up with all the underlaying data

An analytics report can only be trusted as long as you trust the site developers.
A developer can modify it to register the events and page views he wants to have. That's totally normal.
It's a tool for the developers and the site owners, not an independent proof of the popularity of a site.
EDIT : I just tried to add a loop on one of my sites (for which I really don't care about analytics) : http://dystroy.org/re7210/
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
// Google Analytics
var pageTracker;
try {
pageTracker = _gat._getTracker("UA-15064357-1"); // pour dystroy.org
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
for (var i=10; i-->0;) pageTracker._trackPageview();
} catch(err) {console.log(err);}
</script>
And it works :
Only multiples of 10.

Related

Google analytics double reporting

I am trying to determine if my google analytics are being reported twice based on the javascript below in my page. I dont have to have the second script in there to make it work as far as I know, but I am trying to determine if page views/sessions were being recorded twice based off of this configuration. If anyone can provide a test I can do to find this out myself i would appreciate that as well.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXXX-3']);
_gaq.push(['_setDomainName', 'mywebsite.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>
<script type="text/javascript" async="" src="http://www.google-analytics.com/ga.js"></script>

google analytics content experiment without redirect getting no visitors

I have implemented a GA experiment with no redirect
<script type="text/javascript">_udn = 'example.com'; _uhash='off';</script>
<script type="text/javascript" src="//www.google-analytics.com/cx/api.js?experiment=ExperimentID"></script>
<script type="text/javascript">var chosenVariation = cxApi.chooseVariation();</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'AccountID']);
_gaq.push(['_setDomainName', 'example.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://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
I don't seem to get any visits.
The instructions I followed are here experiments-client-side
I have followed the accepted answer at this similar question
Google still does not seem to be receiving my experiment visits.
I am wondering if it has something to do with using stats.g.doubleclick.net/dc.js instead of ga.js
Change the ga.src to ga.js experiments don't seem to work with stats.g.doubleclick.net/dc.js
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
was changed to
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
This solution is not optimal since it stops me from getting demographic data but I am at least getting experiment data now.

simple solution to run third party javascript-tags in paralell? ("asyncronously")?

is there any simple solution to run third party javascript-tags in paralell?
just a few scripts on a html page, which shall not load one after another/sequencial
i know for advertisments it works useing an adserver like doubleclick but that is not necessary here and its not only ads
some need to stay able to analyse the html content the user-agent, ip, referrer or more
examples, that you may very well know :
1.
<script src="http://another-ad-service.com/get-js.aspx?&cwadformat=728*90"</script>
2.
<script language="JavaScript" type="text/javascript">
var 1a_account = '12345';
var 1a_zonesize = '12345-5';
var 1a_adtype = 'js';
</script>
<script type="text/javascript" src="http://agency1a.somewhere/12345.js"></script>
3.
<script type='text/javascript'>
<!--//<![CDATA[
document.MAX_ct0 ='';
var m3_u = (location.protocol=='https:'?'https://an-advertisment-agency.honolulu...'
var m3_r = Math.floor(Math.random()*99999999999);
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("zoneid=12345");document.write("&nodis=1");
document.write ('&cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&exclude=" + document.MAX_used);
document.write (document.charset ? '&charset='+document.charset :
(document.characterSet ? '&charset='+document.characterSet : ''));
document.write ("&loc=" + escape(window.location));
if (document.referrer) document.write ("&referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if ((typeof(document.MAX_ct0) != 'undefined') &&
(document.MAX_ct0.substring(0,4) == 'http')) {
document.write ("&ct0=" + escape(document.MAX_ct0));
}
if (document.mmm_fo) document.write ("&mmm_fo=1");
document.write ("'></scr"+"ipt>");
//]]>--></script>
4.
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345-2']);
_gaq.push(['_setDomainName', 'website.edu']);
_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') + '.gooooogle-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript"> window.google_analytics_uacct = "UA-12345-2"; </script>
When load external JavaScript files, you can add the async attribute to your script tag.
<script src="http://another-ad-service.com/get-js.aspx?&cwadformat=728*90" async></script>
The script needs to be self-sufficient and not depend on other code you are loading before that script, though.

will it work if i put Google analytics code in an IF statement?

i want to only trigger a page hit once a function has been triggered. so can i do the following?
<script type="text/javascript">
function gaCodeParser(parseGAcode){
if(parseGAcode == 'triggerGAcode'){
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-xx']);
_gaq.push(['_trackPageview', '/success-page']);
(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);
})();
}
else{
//do nothing
}
}
</script>
Why do you want to capture that ? google analytics will anyway give you efficient metrics like unique views, unique visitors and so on, if you try to fiddle around thier code you will only loose metrics provided by GA. if you still want to go ahead and fork what is given by GA you can still do so but please dont expect GA to give you all metrics.

Google Analytics - Download link event tracking

I would like to count my downloads through Google Analytics events. Unfortunately nothing shows up in my statistics.
This is the GA code:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_setDomainName', 'example.com']);
_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>
And my link:
Download
Why it is not working?
According to Google Documentations :
<a href="http://www.example.com/files/map.pdf" onClick="javascript: _gaq.push(['_trackPageview', '/downloads/map']);">
To verify that _trackPageview is being called correctly, you can check your Top Content report 24-48 hours after the updated tracking code has been executed. You should be able to see the assigned pagename in your report.

Categories