-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug(settings): Backend events for login_reg and login_complete have g…
…one missing - Some back end events seemed to disappear - This is due to the entry point not being defined on the event - Fixes missing entrypoint glean data - Ensures entrypoint is sent in graphql requests if it is present in URL - Fixes typo in utm parameter. `utmContext` should have been `utmContent`. - Puts the `MetricContext` model in a shared place to reduce the chance this happens again.
- Loading branch information
Showing
13 changed files
with
118 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export * from './lib/metrics.context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
import { MetricsContext } from './metrics.context'; | ||
|
||
describe('metrics context', () => { | ||
it('creates', () => { | ||
// Note! The auth-server expects quite a few query params to be propagated during | ||
// graphql calls. These are commonly referred to as the metrics context. | ||
const queryParams = { | ||
flowId: 'test1', | ||
utmCampaign: 'test2', | ||
utmContent: 'test3', | ||
utmMedium: 'test4', | ||
utmSource: 'test5', | ||
utmTerm: 'test6', | ||
flowBeginTime: '100', | ||
foo: 'test7', | ||
}; | ||
const result = new MetricsContext(queryParams); | ||
expect(result.flowId).toEqual(queryParams.flowId); | ||
expect(result.utmCampaign).toEqual(queryParams.utmCampaign); | ||
expect(result.utmContent).toEqual(queryParams.utmContent); | ||
expect(result.utmMedium).toEqual(queryParams.utmMedium); | ||
expect(result.utmSource).toEqual(queryParams.utmSource); | ||
expect(result.utmTerm).toEqual(queryParams.utmTerm); | ||
expect(result.flowBeginTime).toEqual(Number(queryParams.flowBeginTime)); | ||
|
||
// Make sure type is legit | ||
expect((result as any).foo).toBeUndefined(); | ||
}); | ||
|
||
it('prunes empty fields', () => { | ||
const result = new MetricsContext({}); | ||
const pruned = MetricsContext.prune(result); | ||
expect(pruned).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
/** | ||
* Represents common metrics context for auth server glean events. This | ||
* is context that typically exists in query params on web pages, and | ||
* drives important metric dashboards | ||
*/ | ||
export class MetricsContext { | ||
/** Returns a partial object with empty fields removed. */ | ||
static prune(context: Partial<MetricsContext>): Partial<MetricsContext> { | ||
const pruned: any = Object.assign({}, context); | ||
Object.keys(pruned).forEach((x) => { | ||
if (pruned[x] === undefined) { | ||
delete pruned[x]; | ||
} | ||
}); | ||
return pruned; | ||
} | ||
|
||
deviceId?: string; | ||
entrypoint?: string; | ||
flowId?: string; | ||
flowBeginTime?: number; | ||
utmCampaign?: string; | ||
utmContent?: string; | ||
utmMedium?: string; | ||
utmSource?: string; | ||
utmTerm?: string; | ||
|
||
constructor(queryParams?: Record<string, string>) { | ||
queryParams = queryParams || {}; | ||
this.deviceId = queryParams['deviceId']; | ||
this.entrypoint = queryParams['entrypoint']; | ||
this.flowId = queryParams['flowId']; | ||
this.flowBeginTime = queryParams['flowBeginTime'] | ||
? Number(queryParams['flowBeginTime']) | ||
: undefined; | ||
this.utmCampaign = queryParams['utmCampaign']; | ||
this.utmContent = queryParams['utmContent']; | ||
this.utmMedium = queryParams['utmMedium']; | ||
this.utmSource = queryParams['utmSource']; | ||
this.utmTerm = queryParams['utmTerm']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters