Last Updated: February 25, 2016
·
557
· 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
    super

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

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