-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Mixpanel to track load performance (#2049)
* Fire action when editor is ready * Add Mixpanel client * Instrument Environment Ready in Mixpanel * Add Experimental Mode property to all Mixpanel events
- Loading branch information
Showing
18 changed files
with
163 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
init: jest.fn(), | ||
register: jest.fn(), | ||
track: jest.fn(), | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {createAction} from 'redux-actions'; | ||
|
||
export const editorReady = createAction( | ||
'EDITOR_READY', | ||
(language, timestamp) => ({ | ||
language, | ||
timestamp, | ||
}), | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {mixpanelToken} from '../config'; | ||
|
||
export async function loadMixpanel() { | ||
const {default: mixpanel} = await import( | ||
/* webpackChunkName: "mainAsync" */ | ||
'mixpanel-browser' | ||
); | ||
return mixpanel; | ||
} | ||
export async function initMixpanel() { | ||
const mixpanel = await loadMixpanel(); | ||
mixpanel.init(mixpanelToken); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import mixpanel from 'mixpanel-browser'; | ||
|
||
import instrumentApplicationLoaded from '../instrumentApplicationLoaded'; | ||
import {applicationLoaded} from '../../actions'; | ||
|
||
import {makeTestLogic} from './helpers'; | ||
|
||
const testLogic = makeTestLogic(instrumentApplicationLoaded); | ||
|
||
it('should register no experimental mode', async () => { | ||
await testLogic(applicationLoaded()); | ||
expect(mixpanel.register).toHaveBeenCalledWith({'Experimental Mode': false}); | ||
}); | ||
|
||
it('should register experimental mode', async () => { | ||
await testLogic(applicationLoaded({isExperimental: true})); | ||
expect(mixpanel.register).toHaveBeenCalledWith({'Experimental Mode': true}); | ||
}); |
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,23 @@ | ||
import mixpanel from 'mixpanel-browser'; | ||
|
||
import {makeInstrumentEnvironmentReady} from '../instrumentEnvironmentReady'; | ||
import {editorReady} from '../../actions/instrumentation'; | ||
|
||
import {makeTestLogic} from './helpers'; | ||
|
||
test('dispatches to mixpanel on the first editor ready action', async () => { | ||
const testLogic = makeTestLogic(makeInstrumentEnvironmentReady()); | ||
const timestamp = 12345; | ||
await testLogic(editorReady('html', timestamp)); | ||
expect(mixpanel.track).toHaveBeenCalledWith('Environment Ready', { | ||
Timestamp: timestamp, | ||
}); | ||
}); | ||
|
||
test('does not send additional events to mixpanel', async () => { | ||
const testLogic = makeTestLogic(makeInstrumentEnvironmentReady()); | ||
await testLogic(editorReady('html', 0)); | ||
mixpanel.track.mockClear(); | ||
await testLogic(editorReady('css', 0)); | ||
expect(mixpanel.track).not.toHaveBeenCalled(); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {createLogic} from 'redux-logic'; | ||
|
||
import {applicationLoaded} from '../actions'; | ||
import {loadMixpanel} from '../clients/mixpanel'; | ||
|
||
export default createLogic({ | ||
type: applicationLoaded, | ||
|
||
async process({action: {payload: {isExperimental} = {}}}) { | ||
const mixpanel = await loadMixpanel(); | ||
mixpanel.register({ | ||
'Experimental Mode': Boolean(isExperimental), | ||
}); | ||
}, | ||
}); |
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,32 @@ | ||
import {createLogic} from 'redux-logic'; | ||
|
||
import {editorReady} from '../actions/instrumentation'; | ||
import {loadMixpanel} from '../clients/mixpanel'; | ||
|
||
export function makeInstrumentEnvironmentReady() { | ||
let hasTracked = false; | ||
|
||
return createLogic({ | ||
type: editorReady, | ||
|
||
validate(_, allow, reject) { | ||
if (hasTracked) { | ||
reject(); | ||
} else { | ||
hasTracked = true; | ||
allow(); | ||
} | ||
}, | ||
|
||
async process({ | ||
action: { | ||
payload: {timestamp}, | ||
}, | ||
}) { | ||
const mixpanel = await loadMixpanel(); | ||
mixpanel.track('Environment Ready', {Timestamp: timestamp}); | ||
}, | ||
}); | ||
} | ||
|
||
export default makeInstrumentEnvironmentReady(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7231,7 +7231,7 @@ inflight@^1.0.4: | |
once "^1.3.0" | ||
wrappy "1" | ||
|
||
inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4: | ||
inherits@2, inherits@2.0.4, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.1, inherits@~2.0.3, inherits@~2.0.4: | ||
version "2.0.4" | ||
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" | ||
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== | ||
|
@@ -9593,6 +9593,11 @@ mixin-deep@^1.2.0: | |
for-in "^1.0.2" | ||
is-extendable "^1.0.1" | ||
|
||
[email protected]: | ||
version "2.32.0" | ||
resolved "https://registry.yarnpkg.com/mixpanel-browser/-/mixpanel-browser-2.32.0.tgz#cbd7b3dd9ccf62082496096ac7090fd396b642fb" | ||
integrity sha512-BLfwtGLjq6KSW3ZlRuq4/KCOcGm2PlQlAhPmt9ZjM//ksNfuYfvfQNJ8Vz+7Tw5/cVxLd6/bIrRLA6IBZaUjfA== | ||
|
||
[email protected], mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.1: | ||
version "0.5.1" | ||
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" | ||
|