Created
February 18, 2011 00:56
-
-
Save tmahesh/833066 to your computer and use it in GitHub Desktop.
How fast is my site? integrate boomerang and google analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
BOOMR.init({ | |
beacon_url: "/boomerang.gif", | |
BW: { | |
enabled: false | |
} | |
}); | |
BOOMR.subscribe('before_beacon', trackInAnalytics); | |
var pageType = "homepage"; // customize this | |
var pageTitle = "Measuring pageSpeed in GA"; // customize this | |
function trackInAnalytics(beacon) { | |
try { | |
if (!beacon.t_done || beacon.t_done < 0) return; | |
var timeTaken = beacon.t_done; | |
_gaq.push(['_trackEvent', pageType + 'PageLoad', getBucket(timeTaken), pageTitle, timeTaken]); | |
} catch (e) {} | |
} | |
function getBucket(timeTaken) { | |
var bucketString; | |
var bucket = [1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000, 5500, 6000, 6500, 7000, 7500, 8000, 9000, 10000, 15000, 20000, 30000, 45000, 60000]; | |
for (var b = 0; b < bucket.length; b++) { | |
if (timeTaken < bucket[b]) { | |
bucketString = '< ' + bucket[b] / 1000 + 's'; | |
break; | |
} | |
} | |
if (!bucketString) bucketString = '> ' + bucket[bucket.length - 1] / 1000 + 's'; | |
return bucketString; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
... and after a little testing I noticed that bounce rate immediately went to 0% after sending these events .. NOT what I wanted!
If you send the event (using either the old ga.js or the new universal analytics), you'll notice that the bounce rate immediately goes close to 0%. Meaning that both
_gaq.push
andga("send", "event" ...)
will kill the bounce rate measurement.I didn't want to kill the bounce rate, I wanted to measure it (and other metrics) against the load time to get a baseline, then improve the load time and measure the effects.
Fortunately, you can instruct the event to NOT affect the bounce rate, as mentioned here: http://www.lunametrics.com/blog/2014/05/06/noninteraction-events-google-analytics/
Here is an updated version of the ga send and gaq push that will make sure GA won't change the bounce effects:
_gaq.push(['_trackEvent', pageType + 'PageLoad', getBucket(timeTaken), pageTitle, timeTaken], true);
ga("send", "event", pageType+"PageLoad", getBucket(timeTaken), pageTitle, timeTaken, {'nonInteraction': 1})
Hope this helps y'all :)