Permalink
Browse files

fix(metrics): generate an amplitude deviceId in GET /metrics-flow

The amplitude import needs a device id (or a user id) on each event,
otherwise they're treated as invalid. We have code on the client side
for generating it in lib/app-start.js, but the events generated on the
server are not currently making it to Amplitude. This change adds an
equivalent device id for those events too.
  • Loading branch information...
philbooth committed Nov 6, 2018
1 parent b232843 commit 2ddfd6375a52fa6df477cf4828a50ec18c1302de
Showing with 8 additions and 35 deletions.
  1. +5 −0 server/lib/routes/get-metrics-flow.js
  2. +3 −0 tests/server/routes/get-metrics-flow.js
  3. +0 −35 tests/tests_server.js
@@ -8,6 +8,7 @@ const amplitude = require('../amplitude');
const flowMetrics = require('../flow-metrics');
const logFlowEvent = require('../flow-event').logFlowEvent;
const logger = require('../logging/log')('server.get-metrics-flow');
const uuid = require('node-uuid');

module.exports = function (config) {
const FLOW_ID_KEY = config.get('flow_id_key');
@@ -46,6 +47,10 @@ module.exports = function (config) {
};

metricsData.flowId = flowId;
// Amplitude-specific device id, like the client-side equivalent
// created in app/scripts/lib/app-start.js. Transient for now,
// but will become persistent in due course.
metricsData.deviceId = uuid.v4().replace(/-/g, '');

amplitude(beginEvent, req, metricsData);
logFlowEvent(beginEvent, metricsData, req);
@@ -92,6 +92,8 @@ registerSuite('routes/get-metrics-flow', {
assert.equal(args[0].type, 'flow.begin');
assert.equal(args[2].entrypoint, 'zoo');
assert.ok(args[2].flowId);
assert.ok(args[2].deviceId);
assert.notEqual(args[2].deviceId, args[2].flowId);

assert.equal(mocks.flowEvent.logFlowEvent.callCount, 1);
args = mocks.flowEvent.logFlowEvent.args[0];
@@ -102,6 +104,7 @@ registerSuite('routes/get-metrics-flow', {
assert.equal(eventData.type, 'flow.begin');
assert.equal(metricsData.entrypoint, 'zoo');
assert.ok(metricsData.flowId);
assert.ok(metricsData.deviceId);
},

'logs enter-email.view amplitude and flow events if form_type email is set': function () {
@@ -3,40 +3,5 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

module.exports = [
'tests/server/routes.js',
'tests/server/l10n-entrained.js',
'tests/server/ver.json.js',
'tests/server/amplitude.js',
'tests/server/csp.js',
'tests/server/flow-event.js',
'tests/server/flow-metrics.js',
'tests/server/frame-guard.js',
'tests/server/geo-locate.js',
'tests/server/hpkp.js',
'tests/server/html-middleware.js',
'tests/server/l10n.js',
'tests/server/lang.js',
'tests/server/metrics.js',
'tests/server/metrics-collector-stderr.js',
'tests/server/metrics-errors.js',
'tests/server/metrics-unit.js',
'tests/server/noindex.js',
'tests/server/configuration.js',
'tests/server/raven.js',
'tests/server/remote-address.js',
'tests/server/routes/get-apple-app-site-association.js',
'tests/server/routes/get-config.js',
'tests/server/routes/get-fxa-client-configuration.js',
'tests/server/routes/get-lbheartbeat.js',
'tests/server/routes/get-metrics-flow.js',
'tests/server/routes/get-openid-configuration.js',
'tests/server/routes/get-verify-email.js',
'tests/server/routes/get-index.js',
'tests/server/routes/get-well-known-change-password.js',
'tests/server/routes/post-csp.js',
'tests/server/routes/post-metrics.js',
'tests/server/routes/redirect-m-to-adjust.js',
'tests/server/logging/route_logging.js',
'tests/server/user-agent.js',
'tests/server/validation.js'
];

0 comments on commit 2ddfd63

Please sign in to comment.