Skip to content
Permalink
Browse files

fix(metrics): accept camel-cased flow metrics query params

  • Loading branch information...
philbooth committed Oct 1, 2019
1 parent 743c09e commit 8c776aff8e36262d517c82fc264bab6f98aee7b4
@@ -47,6 +47,12 @@ var Model = Backbone.Model.extend({
// if the urlParams are set that means flow.begin was already logged on the server-side
// therefore we mark flow.begin logged
this.metrics.markEventLogged('flow.begin');
} else if (urlParams.flowBeginTime && urlParams.flowId) {
// Discrepancy between snake_case and camelCase has confused some reliers
// so we permissively accept both (it was only snake_case here originally)
this.set('flowBegin', urlParams.flowBeginTime);
this.set('flowId', urlParams.flowId);
this.metrics.markEventLogged('flow.begin');
} else {
this.populateFromDataAttribute('flowId');
this.populateFromDataAttribute('flowBegin');
@@ -55,6 +61,8 @@ var Model = Backbone.Model.extend({
if (!this.has('deviceId')) {
if (urlParams.device_id) {
this.set('deviceId', urlParams.device_id);
} else if (urlParams.deviceId) {
this.set('deviceId', urlParams.deviceId);
} else {
this.set('deviceId', uuid.v4().replace(/-/g, ''));
}
@@ -11,10 +11,13 @@ import sinon from 'sinon';
import Url from 'lib/url';
import WindowMock from '../../mocks/window';

var DEVICE_ID = '0123456789abcdef0123456789abcdef';
var BODY_FLOW_ID =
const DEVICE_ID = '0123456789abcdef0123456789abcdef';
const BODY_FLOW_ID =
'F1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF103';
var RESUME_FLOW_ID =
const QUERY_FLOW_BEGIN = '55';
const QUERY_FLOW_ID =
'A1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF103';
const RESUME_FLOW_ID =
'71031D71031D71031D71031D71031D71031D71031D71031D71031D71031D7103';

describe('models/flow', function() {
@@ -99,15 +102,14 @@ describe('models/flow', function() {
$(windowMock.document.body).attr('data-flow-id', BODY_FLOW_ID);
$(windowMock.document.body).attr('data-flow-begin', '42');

const QUERY_FLOW_BEGIN = '55';
const QUERY_FLOW_ID =
'A1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF1031DF103';

windowMock.location.search = Url.objToSearchString({
/*eslint-disable camelcase*/
device_id: DEVICE_ID,
deviceId: 'wibble',
flow_begin_time: QUERY_FLOW_BEGIN,
flow_id: QUERY_FLOW_ID,
flowBeginTime: '42',
flowId: BODY_FLOW_ID,
/*eslint-enable camelcase*/
});

@@ -119,6 +121,26 @@ describe('models/flow', function() {
assert.ok(metricsMock.markEventLogged.calledOnce);
});

it('falls back to camelCase query params', () => {
$(windowMock.document.body).attr('data-flow-id', BODY_FLOW_ID);
$(windowMock.document.body).attr('data-flow-begin', '42');

windowMock.location.search = Url.objToSearchString({
/*eslint-disable camelcase*/
device_id: DEVICE_ID,
flowBeginTime: QUERY_FLOW_BEGIN,
flowId: QUERY_FLOW_ID,
/*eslint-enable camelcase*/
});

createFlow();

assert.equal(flow.get('deviceId'), DEVICE_ID);
assert.equal(flow.get('flowId'), QUERY_FLOW_ID);
assert.equal(flow.get('flowBegin'), QUERY_FLOW_BEGIN);
assert.equal(metricsMock.markEventLogged.callCount, 1);
});

it('logs an error when the resume token contains `flowId` but not `flowBegin`', function() {
windowMock.location.search = Url.objToSearchString({
resume: ResumeToken.stringify({

0 comments on commit 8c776af

Please sign in to comment.
You can’t perform that action at this time.