Last Updated: February 25, 2016
· benjaminclos

adding analytics to Chaplin.js application

Adding Google Analytics/Piwik/whatever to your front-end application can sometimes be tricky, with Chaplin.js it's a breeze though:

# The application object.
module.exports = class Application extends Chaplin.Application
  initialize: ->
    @subscribeEvent '!router:route', @analyticsHooks

  analyticsHooks: (route, params)->"Analytics")
    console.log route
    console.log params

This adds a subscriber on the application level for all route events and passes the route and route params to your Application#analyticsHooks.