Brought to you by Use All Five, Inc.
Author: Justin Anastos <[email protected]>
Author URI: [http://www.useallfive.com](http://www.useallfive.com)
Repository: https://github.com/UseAllFive/marionette.googleAnalyticsEvents
Trigger Google Analytics event and route calls from Marionette views/routes.
Routes will automatically call a route navigate event like so:
ga('send', 'event', 'route', 'navigate', '/some/deep/link');
No configuration is necessary for the routing events to be sent.
Marionette views can have an extra parameter added to each trigger
object to
make it automatically track with Google Analytics.
For example:
var view = Marionette.ItemView.extend({
ui: {
someButton: '.someButton'
},
triggers: {
'click @ui.someButton': {
event: 'eventToPropogate',
googleAnalyticsConfig: {
category: 'some category',
event: 'some event',
label: 'optional. some label'
}
}
}
});
When the UI element is triggered, then the following will be called:
`ga('send', 'event', 'some category', 'some event', 'optional. some label');
The googleAnalyticsConfig
triggers option can also be a function that returns
an object like this:
var view = Marionette.ItemView.extend({
ui: {
someButton: '.someButton'
},
triggers: {
'click @ui.someButton': {
event: 'eventToPropogate',
googleAnalyticsConfig: function() {
return {
category: this.model.get('something'),
event: 'some event',
label: 'optional. some label'
};
}
}
}
});