BOOMR.plugins. Backbone


The Backbone plugin allows you to automatically monitor Single Page App (SPA) navigations for Backbone.js websites.

Note: This plugins requires the BOOMR.plugins.SPA and BOOMR.plugins.AutoXHR plugins.

For details on how Boomerang Single Page App instrumentation works, see the BOOMR.plugins.SPA documentation.

For information on how to include this plugin, see the Building tutorial.

Compatibility

  • Backbone.js 1.x

Beacon Parameters

This plugin does not add any additional beacon parameters beyond the BOOMR.plugins.SPA plugin.

Usage

First, include the BOOMR.plugins.SPA, BOOMR.plugins.Backbone and BOOMR.plugins.AutoXHR plugins. See Building for details.

Next, you need to also "hook" Boomerang into the Backbone.js lifecycle events.

Before you call Backbone.history.start(), add the following code.

Substitute app.Router in the two places below with your Backbone.Router instance.

Example:

// ...Backbone startup..., eg. app.Router = Backbone.Router.extend({...});
var hadRouteChange = false;

app.Router.on("route", function() {
  hadRouteChange = true;
});

function hookBackboneBoomerang() {
  if (window.BOOMR && BOOMR.version) {
    if (BOOMR.plugins && BOOMR.plugins.Backbone) {
      BOOMR.plugins.Backbone.hook(app.Router, hadRouteChange);
    }
    return true;
  }
}

if (!hookBackboneBoomerang()) {
  if (document.addEventListener) {
    document.addEventListener("onBoomerangLoaded", hookBackboneBoomerang);
  } else if (document.attachEvent) {
    document.attachEvent("onpropertychange", function(e) {
      e = e || window.event;
      if (e && e.propertyName === "onBoomerangLoaded") {
        hookBackboneBoomerang();
      }
    });
  }
}]);

Methods


disable()

Disables the Backbone plugin

Returns:

BOOMR.plugins.Backbone The Backbone plugin for chaining


enable()

Enables the Backbone plugin

Returns:

BOOMR.plugins.Backbone The Backbone plugin for chaining


hook($rootScope [, hadRouteChange] [, options])

Hooks Boomerang into the Backbone lifecycle events

Parameters:

Name Type Argument Description
$rootScope object

Backbone router

hadRouteChange boolean <optional>

Whether or not there was a route change event prior to this hook() call

options object <optional>

Options

Returns:

BOOMR.plugins.Backbone The Backbone plugin for chaining


is_complete()

This plugin is always complete (ready to send a beacon)

Returns:

Type: boolean

true