Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Analytics Code Manipulation (G. Analytics)

for my job I am doing an research projekt on the validity of Google Analytics (mostly in regards to the verified reports on flippa) --> see if it is possible to completly fake G. Analytics (a simple Yes will not cut it)!

I modified the G. Analytics code as following:

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-19629541-5']);
_gaq.push(['_setAllowHash', false]);
_gaq.push(['b._setAccount', 'UA-19629541-5']);
_gaq.push(['b._setAllowHash', true]);

for (var i=0;i<=10;i++) {
  _gaq.push(['_trackPageview']);
  _gaq.push(['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);
  })();

It will now spawn multiple visits and visitors when you run it. You can see that the second number on __utma changes for every pageview, that number is the visitorId, when it changes it means you get a new visitor

The problem is that the stats I get now look like this:

  • Visits: 1,785
  • Unique Visitors: 1,781
  • Pageviews: 2,188
  • Pages / Visit: 1.23
  • Avg. Visit Duration: 00:00:03
  • Bounce Rate: 96.13% %
  • New Visits: 99.78%

Please not the extreme decrease in avg. visit duration!

before they were similar to this:

  • Visits: 135
  • Unique Visitors: 118
  • Pageviews: 383
  • Pages / Visit: 2.84
  • Avg. Visit Duration: 00:04:22
  • Bounce Rate: 57.78%
  • % New Visits: 68.89%

Now my question: How would I need to modify the G. Analytics Code (if at all posible) to make it look similar to this:

  • Visits: 135 * 10 = 1350
  • Unique Visitors: 118 * 10 = 1180
  • Pageviews: 383 * 10 = 3830
  • Pages / Visit: 2.84
  • Avg. Visit Duration: 00:04:22
  • Bounce Rate: 57.78%
  • % New Visits: 68.89%

so basically increase the amount of Visits, Unique Visitors, Pageviews 10 fold yet leave the other stats the same.

Examples on http://jsfiddle.net are greatly welcomed

PS: sorry for my bad English (not my mother tongue)

like image 229
Chriswede Avatar asked Jul 15 '12 13:07

Chriswede


2 Answers

Google Analytics defines timeOnPage and timeOnSite on server side, the code is based on the time elapsed between the pageviews you sent. Since all this is done server side there's no way to fake this unless you space out your pageviews by the amount of time you wish to fake.

You also need to send more than 1 pageview per tracker to get the correct amount of pages/visit. Currently everytime you switch between the 2 trackers you reset cookies and the previous visitorId is lost forever.

So you want to do something like this:

  • Create first tracker
  • Fire a pageview
  • wait something between 1 and 2 seconds
  • Fire another pageview
  • Maybe fire a third pageview after another 1 or 2 seconds 80% of the time to get closer to the right average.
  • Create a new tracker
  • rinse repeat

I would say that you probably want to introduce some more randomness still keeping the same average. For example in order to get the right BounceRate you'd need to have 57% of the visits firing a single pageview. And in order to get the right New Visitors metric you need to come back with one of those old ids but within a new visit to spawn a returning visitor. You can trigger a new visit by deleting the __utmb or __utmc cookies, or just waiting longer than 30min between a new pageview.

As you can see the closer you want to fake the numbers with the true the harder it might get.

This now becomes a little impractical to live in a single page script. Since it may take a couple seconds to complete and you probably want to emulate this thousands of times. So maybe it's better to create this use a headless browser like phantom.js that you can trigger multiple simultaneous instances of to get the results you want.

I wonder what kind of analysis you're planning to extract from these. Depending on the type of analysis what you already have is enough or maybe the effort to have a better emulation is not worth the insight.

like image 54
Eduardo Avatar answered Nov 15 '22 04:11

Eduardo


You're not going to be able to do this within one web page. The problem is that whenever you reset the hash it spawns a new session which will cause the first "visitor" to leave, lowering avg. visit of duration and increasing the bounce rate.

I believe you could accomplish everything except for the Unique Visitors * 10 requirement by doing the following:

  • Create a basic HTML page that just has the standard Google Analytics code in it, we'll call this ga.htm.
  • Create an include file that has 9 0x0 sized iFrames, each with the src of ga.htm, we'll call this include-ga.htm.
  • Inclue the include-ga.htm file at the bottom of all your pages.

This should artificially make GA think the user is viewing 10 pages at once which should multiply all your stats in unison, except for Unique Visitors.

like image 29
Shawn Steward Avatar answered Nov 15 '22 05:11

Shawn Steward