Skip to content

Instantly share code, notes, and snippets.

@tmahesh
Created February 18, 2011 00:56
Show Gist options
  • Save tmahesh/833066 to your computer and use it in GitHub Desktop.
Save tmahesh/833066 to your computer and use it in GitHub Desktop.

Revisions

  1. tmahesh revised this gist Mar 7, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion measurePageloadTimes.js
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@
    try {
    if (!beacon.t_done || beacon.t_done < 0) return;
    var timeTaken = beacon.t_done;
    _gaq.push(['_trackEvent', pageType + 'PageLoad', getBucket(timeTaken), pageTitle, Math.round(timeTaken / 100)]);
    _gaq.push(['_trackEvent', pageType + 'PageLoad', getBucket(timeTaken), pageTitle, timeTaken]);
    } catch (e) {}
    }

  2. tmahesh created this gist Feb 18, 2011.
    32 changes: 32 additions & 0 deletions measurePageloadTimes.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <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, Math.round(timeTaken / 100)]);
    } 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>