Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andreas-marschke
Created October 31, 2014 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreas-marschke/41d47c9cfeebbcee8fb2 to your computer and use it in GitHub Desktop.
Save andreas-marschke/41d47c9cfeebbcee8fb2 to your computer and use it in GitHub Desktop.
b.js - Boomerang Setup in around 500 bytes
/* b.js - Boomerang Setup in around 500 bytes
* ------------------------------------------
* Complete boomerang.js initialization with essential plugins in around 500 bytes
* It mimics "Google Analytics"-style script injection using document.createElement
* and document.head.appendChild().
*
* Beacon URL configuration + configuring Plugins as a variable to the beacon:
*
* http://boomerang.example.org/beacon/0000/dashboard/start?plugins=BW%7CRT%7Cnavtimin%7Crestiming&...
*
* Checkout the boomerang project at: github.com/lognormal/boomerang
* and my Boomerang reciever Server: github.com/andreas-marschke/boomerang-express
*/
(function(b,d){var a=["//boomerang.example.org/","0000/dashboard/start","plugins","BOOMR"],c=d.createElement("script");c.src="/js/boomerang.js";d.head.appendChild(c);c.onload=function(){b[a[5]].init({beacon_url:a[0]+"beacon/"+a[1],DNS:{base_url:a[0],strict_referrer:!1},BW:{base_url:a[0],cookie:"bandwidth",nruns:1},RT:{},ipv6:{},clicks:{click_url:a[0]+"click/"+a[1],onbeforeunload:!0}});b[a[3]].addVar(a[2],Object.keys(b[a[3]][a[2]]).join("|"))}})(this,this.document);
@bluesmoon
Copy link

Ok, a few comments:

  1. We should use the iframe loader rather than the direct script injection loader unless the site owner is also the owner of the script domain.
  2. We should not use c.onload to call init. I've seen cases where a script's onload event does not fire. Instead, subscribe to the custom event onBoomerangLoaded (or maybe do both)
  3. Call addVar before calling init. I've seen cases where init fires the beacon before addVar runs.
  4. strict_referrer is not part of the DNS plugin ;)

@bluesmoon
Copy link

And I sort of solve the init part by just calling it at the bottom of my combined & minified boomerang.js file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment