Socket
Socket
Sign inDemoInstall

backbone.analytics

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    backbone.analytics

A drop-in plugin that integrates Google's `trackEvent` directly into Backbone's `navigate` function.


Version published
Weekly downloads
66
decreased by-38.89%
Maintainers
1
Install size
5.26 kB
Created
Weekly downloads
 

Readme

Source

Backbone.Analytics

A drop-in plugin that integrates Google's trackEvent directly into Backbone's navigate function. Works best with pushState set to true. If pushState is turned off, it's possible Google will register visits twice on page load. You can mitigate that by removing the trackEvent from the Google code in your site.

Dependencies

  • Backbone.js (Tested in 1.0)

Traditional Install

Add the asynchronous Google Analytics code to your site.

Add these dependencies to your site's <head>, in order:

<script src="underscore.js"></script>
<script src="backbone.js"></script>
<script src="backbone.analytics.js"></script>

NPM Install

npm install backbone.analytics --save

Usage

Anywhere you call your router's navigate method with the trigger option set to true Backbone.Analytics will call _gaq.push(['_trackPageview', '/some-page']) after completing the Backbone route. This pushes the route to the Google Analytics tracking queue. Once this queue is processed by the Google Analytics script your urls will be tracked to the Google Analytics server.

var TestRouter = Backbone.Router.extend({
  routes: {
    'some-page': 'somePage'
  },

  somePage: function() {
    // Perform your route based logic, e.g. Replace the current view with a different one.
    return false;
  }
});

var router = new TestRouter();
Backbone.history.start();

Somewhere else in your application, change the view by doing:

router.navigate('some-page', { trigger: true });

Anywhere in your application where you want to update the URL but do not trigger the associated route, you will still need to manually track the action.

Keywords

FAQs

Last updated on 19 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc