Skip to content

Commit

Permalink
feat(metrics): emit view, engage and submit events for CWTS
Browse files Browse the repository at this point in the history
  • Loading branch information
philbooth committed Jun 4, 2019
1 parent b5165d8 commit e14d749
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 3 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{{/isTrailhead}} {{/isTrailhead}}
</div> </div>
<div class="links"> <div class="links">
<a href="#" id="back">{{#t}}Back{{/t}}</a> <a href="#" id="back" data-flow-event="back">{{#t}}Back{{/t}}</a>
</div> </div>
</form> </form>
</section> </section>
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import _ from 'underscore';
import $ from 'jquery'; import $ from 'jquery';
import BackMixin from './mixins/back-mixin'; import BackMixin from './mixins/back-mixin';
import Cocktail from 'cocktail'; import Cocktail from 'cocktail';
import FlowEventsMixin from './mixins/flow-events-mixin';
import FormView from './form'; import FormView from './form';
import SessionVerificationPollMixin from './mixins/session-verification-poll-mixin'; import SessionVerificationPollMixin from './mixins/session-verification-poll-mixin';
import Template from 'templates/choose_what_to_sync.mustache'; import Template from 'templates/choose_what_to_sync.mustache';
Expand Down Expand Up @@ -154,6 +155,7 @@ const View = FormView.extend({
Cocktail.mixin( Cocktail.mixin(
View, View,
BackMixin, BackMixin,
FlowEventsMixin,
SessionVerificationPollMixin SessionVerificationPollMixin
); );


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import Account from 'models/account';
import { assert } from 'chai'; import { assert } from 'chai';
import Backbone from 'backbone'; import Backbone from 'backbone';
import Broker from 'models/auth_brokers/base'; import Broker from 'models/auth_brokers/base';
import { CHOOSE_WHAT_TO_SYNC } from '../../../../tests/functional/lib/selectors';
import Metrics from 'lib/metrics'; import Metrics from 'lib/metrics';
import Notifier from 'lib/channels/notifier'; import Notifier from 'lib/channels/notifier';
import sinon from 'sinon'; import sinon from 'sinon';
import { CHOOSE_WHAT_TO_SYNC } from '../../../../tests/functional/lib/selectors'; import SentryMetrics from 'lib/sentry';
import SessionVerificationPoll from 'models/polls/session-verification'; import SessionVerificationPoll from 'models/polls/session-verification';
import SyncEngines from 'models/sync-engines'; import SyncEngines from 'models/sync-engines';
import TestHelpers from '../../lib/helpers'; import TestHelpers from '../../lib/helpers';
Expand Down Expand Up @@ -58,7 +59,7 @@ describe('views/choose_what_to_sync', () => {
email = TestHelpers.createEmail(); email = TestHelpers.createEmail();
model = new Backbone.Model(); model = new Backbone.Model();
notifier = new Notifier(); notifier = new Notifier();
metrics = new Metrics({ notifier }); metrics = new Metrics({ notifier, sentryMetrics: new SentryMetrics() });
onSubmitComplete = sinon.spy(); onSubmitComplete = sinon.spy();
user = new User({}); user = new User({});


Expand Down Expand Up @@ -107,6 +108,17 @@ describe('views/choose_what_to_sync', () => {
return view.render(); return view.render();
} }


it('registers for the expected events', () => {
return initView()
.then(() => {
assert.isFunction(view.events['click a']);
assert.isFunction(view.events['click input']);
assert.isFunction(view.events['input input']);
assert.isFunction(view.events['keyup input']);
assert.isFunction(view.events['submit']);
});
});

describe('renders', () => { describe('renders', () => {
it('coming from sign up, redirects to /signup when email accound data missing', () => { it('coming from sign up, redirects to /signup when email accound data missing', () => {
account.clear('email'); account.clear('email');
Expand Down
16 changes: 16 additions & 0 deletions packages/fxa-content-server/server/lib/amplitude.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ const EVENTS = {
group: GROUPS.login, group: GROUPS.login,
event: 'forgot_submit' event: 'forgot_submit'
}, },
'flow.choose-what-to-sync.back': {
group: GROUPS.registration,
event: 'cwts_back'
},
'flow.choose-what-to-sync.engage': {
group: GROUPS.registration,
event: 'cwts_engage'
},
'flow.choose-what-to-sync.submit': {
group: GROUPS.registration,
event: 'cwts_submit'
},
'flow.update-firefox.engage': { 'flow.update-firefox.engage': {
group: GROUPS.notify, group: GROUPS.notify,
event: 'update_firefox_engage' event: 'update_firefox_engage'
Expand All @@ -42,6 +54,10 @@ const EVENTS = {
group: GROUPS.notify, group: GROUPS.notify,
event: 'update_firefox_view' event: 'update_firefox_view'
}, },
'screen.choose-what-to-sync': {
group: GROUPS.registration,
event: 'cwts_view'
},
'settings.change-password.success': { 'settings.change-password.success': {
group: GROUPS.settings, group: GROUPS.settings,
event: 'password' event: 'password'
Expand Down
77 changes: 77 additions & 0 deletions packages/fxa-content-server/tests/server/amplitude.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -375,6 +375,25 @@ registerSuite('amplitude', {
assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - password_blocked'); assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - password_blocked');
}, },


'flow.choose-what-to-sync.engage': () => {
amplitude({
time: 'a',
type: 'flow.choose-what-to-sync.engage'
}, {
connection: {},
headers: {
'x-forwarded-for': '63.245.221.32'
}
}, {
flowBeginTime: 'b',
flowId: 'c',
uid: 'd'
});

assert.equal(logger.info.callCount, 1);
assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - cwts_engage');
},

'flow.enter-email.engage': () => { 'flow.enter-email.engage': () => {
amplitude({ amplitude({
time: 'a', time: 'a',
Expand Down Expand Up @@ -615,6 +634,26 @@ registerSuite('amplitude', {
assert.equal(arg.event_properties.connect_device_os, 'foo'); assert.equal(arg.event_properties.connect_device_os, 'foo');
}, },


'flow.choose-what-to-sync.back': () => {
amplitude({
time: 'a',
type: 'flow.choose-what-to-sync.back'
}, {
connection: {},
headers: {
'x-forwarded-for': '63.245.221.32'
}
}, {
flowBeginTime: 'b',
flowId: 'c',
uid: 'd'
});

assert.equal(logger.info.callCount, 1);
const arg = logger.info.args[0][1];
assert.equal(arg.event_type, 'fxa_reg - cwts_back');
},

'flow.signin.forgot-password': () => { 'flow.signin.forgot-password': () => {
amplitude({ amplitude({
time: 'a', time: 'a',
Expand Down Expand Up @@ -653,6 +692,25 @@ registerSuite('amplitude', {
assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - have_account'); assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - have_account');
}, },


'flow.choose-what-to-sync.submit': () => {
amplitude({
time: 'a',
type: 'flow.choose-what-to-sync.submit'
}, {
connection: {},
headers: {
'x-forwarded-for': '63.245.221.32'
}
}, {
flowBeginTime: 'b',
flowId: 'c',
uid: 'd'
});

assert.equal(logger.info.callCount, 1);
assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - cwts_submit');
},

'flow.enter-email.submit': () => { 'flow.enter-email.submit': () => {
amplitude({ amplitude({
time: 'a', time: 'a',
Expand Down Expand Up @@ -787,6 +845,25 @@ registerSuite('amplitude', {
assert.equal(logger.info.callCount, 0); assert.equal(logger.info.callCount, 0);
}, },


'screen.choose-what-to-sync': () => {
amplitude({
time: 'a',
type: 'screen.choose-what-to-sync'
}, {
connection: {},
headers: {
'x-forwarded-for': '63.245.221.32'
}
}, {
flowBeginTime: 'b',
flowId: 'c',
uid: 'd'
});

assert.equal(logger.info.callCount, 1);
assert.equal(logger.info.args[0][1].event_type, 'fxa_reg - cwts_view');
},

'screen.enter-email': () => { 'screen.enter-email': () => {
amplitude({ amplitude({
time: 'a', time: 'a',
Expand Down

0 comments on commit e14d749

Please sign in to comment.