Skip to content

Instantly share code, notes, and snippets.

@Zatvobor
Last active August 29, 2015 14:16
Show Gist options
  • Save Zatvobor/e5b8266f8a5bedeb50d3 to your computer and use it in GitHub Desktop.
Save Zatvobor/e5b8266f8a5bedeb50d3 to your computer and use it in GitHub Desktop.
Ember-Insights.js: Task Success metrics
// The Example App is abstract implementation as a show case of getting the 'Task Success' metric.
// The Task Success: this includes traditional behavioral metrics of user experience,
// such as efficiency (e.g. time to complete a task), effectiveness (e.g. percent of tasks completed), and error rate.
// This category is most applicable to areas of your product that are very task-focused, such as search or an upload flow.
App = Ember.Application.create({rootElement: applicationContainer});
App.Router.map(function() {
this.resource('index', { path: '/' });
this.resource('execution', { path: '/execution' });
this.resource('result', { path: '/result' });
});
// disables update URL
App.Router.reopen({ location: 'none' });
App.Task = Ember.Object.extend({
validateInput: Ember.computed.equal('taskID', 'Mnemonics'),
validateRadio: Ember.computed.equal('selectedRadio', 'should'),
validateCheckbox: Ember.computed.and('checkedOptions.s', 'checkedOptions.l'),
isValid: Ember.computed.and('validateInput', 'validateRadio', 'validateCheckbox'),
firstAttempt: Ember.computed.equal('attempts', 1)
});
App.ExecutionRoute = Ember.Route.extend({
model: function(){
return App.Task.create({
attempts: 0,
taskID: '',
selectedRadio: 'must',
checkedOptions: { s:false, o:false, l:false, i:false, d:false }
});
}
});
App.ResultRoute = Ember.Route.extend({
model: function(){ return this.modelFor('execution'); }
});
App.IndexController = Ember.Controller.extend({
actions: {
proceed: function(){ this.transitionTo('execution'); }
}
});
App.ExecutionController = Ember.ObjectController.extend({
submitted: false,
radioButtons: { must: 'must', should: 'should', could: 'could', wont: 'wont' },
actions: {
submit: function(){
this.incrementProperty('model.attempts');
if(this.get('model.isValid') || this.get('model.attempts') > 1){
this.transitionTo('result');
}
}
}
});
App.ResultController = Ember.Controller.extend({
actions: {
tryAgain: function(){ this.transitionTo('index'); }
}
});
App.RadioButtonComponent = Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'disabled', 'checked:checked', 'name', 'type', 'value' ],
checked: function () {
return this.get('value') === this.get('selectedRadio');
}.property('value', 'selectedRadio'),
change: function () {
this.set('selectedRadio', this.get('value'));
}
});
var EmberInsights = require('ember-insights')['default'];
Ember.Application.initializer({
name: 'Ember-Insights.js - tracking Task-Success application',
initialize: function (container, application) {
EmberInsights.configure('task-success-tracking', {
// Sends insights to the right panel.
trackerFactory: BrowserTrackerFactory,
// Disables setting a 'location' each time after transitions.
updateDocumentLocationOnTransitions: false,
}).track({
// Sets insights for transitions between 'Task' and 'Execution' tabs.
insights: {
TRANSITIONS: ['index', 'execution'], ALL_ACTIONS: { except: ['tryAgain'] }
}
}).track({
// Sets insights mappings for transition to 'Result' tab.
insights: {
TRANSITIONS: ['result']
},
// A `dispatch` is responsible for sending custom insight as a final result of task success
dispatch: function(type, context, tracker) {
var model = context.route.get('controller.model');
// this kind of final insight which depends from model state
var label = (model.get('isValid') ? 'successful' : 'failed')
// sends report
tracker.sendEvent('result', 'status', label);
tracker.trackPageView('/result');
}
});
// Start engine!
EmberInsights.start('task-success-tracking');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment