Skip to content

Commit cec250f

Browse files
ref(analytics): Replace amplitude with analytics:track-event (#13536)
1 parent 430e11d commit cec250f

File tree

4 files changed

+72
-35
lines changed

4 files changed

+72
-35
lines changed

src/sentry/static/sentry/app/stores/hookStore.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ const validHookNames = new Set([
1111
'routes:organization-root',
1212

1313
// Analytics and tracking hooks
14-
'amplitude:event',
15-
'analytics:event',
1614
'analytics:init-user',
15+
'analytics:track-event',
16+
'analytics:track-adhoc-event',
17+
18+
// TODO(epurkhser): This is deprecated and should be replaced
19+
'analytics:event',
1720

1821
// Operational metrics
1922
'metrics:event',

src/sentry/static/sentry/app/utils/analytics.jsx

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,70 @@
11
import HookStore from 'app/stores/hookStore';
22

33
/**
4-
* If the backend for `analytics` is reload, you will need to add the event `name`
5-
* to the inclusion list in https://github.com/getsentry/reload/blob/master/reload_app/events.py
4+
* Analytics and metric tracking functionality.
65
*
6+
* These are primarily driven through hooks provided through the hookstore. For
7+
* sentry.io these are currently mapped to our in-house analytics backend
8+
* 'Reload' and the Amplitude service.
79
*
8-
* If you are using `gauge` or `increment`, the metric names need to be added to
9-
* https://github.com/getsentry/reload/blob/master/reload_app/metrics/__init__.py
10+
* NOTE: sentry.io contributors, you will need to nesure that the eventKey
11+
* passed exists as an event key in the Reload events.py configuration:
12+
*
13+
* https://github.com/getsentry/reload/blob/master/reload_app/events.py
14+
*
15+
* NOTE: sentry.io contributors, if you are using `gauge` or `increment` the
16+
* name must be added to the Reload metrics module:
17+
*
18+
* https://github.com/getsentry/reload/blob/master/reload_app/metrics/__init__.py
19+
*/
20+
21+
/**
22+
* This should be primarily used for product events. In that case where you
23+
* want to track some one-off Adhoc events, use the `trackAdhocEvent` function.
24+
*
25+
* Generally this is the function you will want to use for event tracking.
26+
*
27+
* Refer for the backend implementation provided through HookStore for more
28+
* details.
29+
*
30+
* @param {Object} options Event tracking options
31+
* @param {String} options.eventKey The string key of the event to track
32+
* @param {String} options.name The human readable string name of the event
33+
* @param {...Object} options.data The parameters of the event to track
34+
*/
35+
export const trackAnalyticsEvent = options =>
36+
HookStore.get('analytics:track-event').forEach(cb => cb(options));
37+
38+
/**
39+
* This should be used for adhoc analytics tracking.
40+
*
41+
* This is used for high volume events, and events with unbounded parameters,
42+
* such as tracking search queries.
43+
*
44+
* Refer for the backend implementation provided through HookStore for a more
45+
* thorough explanation of when to use this.
46+
*
47+
* @param {Object} options Event tracking options
48+
* @param {String} options.eventKey The string key of the event to track
49+
* @param {...Object} options.data The parameters of the event to track
1050
*/
51+
export const trackAdhocEvent = options =>
52+
HookStore.get('analytics:track-adhoc-event').forEach(cb => cb(options));
1153

1254
/**
1355
* @param {String} name The name of the event
1456
* @param {Object} data Additional event data to record
1557
*/
16-
export function analytics(name, data) {
58+
export const analytics = (name, data) =>
1759
HookStore.get('analytics:event').forEach(cb => cb(name, data));
18-
}
19-
20-
export function amplitude(name, organization_id, data) {
21-
HookStore.get('amplitude:event').forEach(cb => cb(name, organization_id, data));
22-
}
2360

2461
/**
2562
* @param {String} name Metric name
2663
* @param {Number} value Value to record for this metric
2764
* @param {Object} tags An additional tags object
2865
*/
29-
export function metric(name, value, tags) {
66+
export const metric = (name, value, tags) =>
3067
HookStore.get('metrics:event').forEach(cb => cb(name, value, tags));
31-
}
3268

3369
// JSDOM implements window.performance but not window.performance.mark
3470
const CAN_MARK =

src/sentry/static/sentry/app/views/onboarding/configure.jsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {browserHistory} from 'react-router';
22
import React from 'react';
33
import styled from 'react-emotion';
44

5-
import {analytics, amplitude} from 'app/utils/analytics';
65
import {t} from 'app/locale';
6+
import {trackAnalyticsEvent} from 'app/utils/analytics';
77
import Button from 'app/components/button';
88
import ProjectContext from 'app/views/projects/projectContext';
99
import ProjectInstallPlatform from 'app/views/projectInstall/platform';
@@ -23,19 +23,15 @@ class Configure extends React.Component {
2323

2424
componentDidMount() {
2525
const {organization, params} = this.props;
26-
const data = {
26+
27+
trackAnalyticsEvent({
28+
eventKey: 'onboarding.configure_viewed',
29+
eventName: 'Viewed Onboarding Installation Instructions',
30+
organization_id: organization.id,
2731
project: params.projectId,
2832
platform: params.platform,
29-
};
30-
31-
amplitude(
32-
'Viewed Onboarding Installation Instructions',
33-
parseInt(organization.id, 10),
34-
data
35-
);
33+
});
3634

37-
data.org_id = parseInt(organization.id, 10);
38-
analytics('onboarding.configure_viewed', data);
3935
this.sentRealEvent();
4036
}
4137

@@ -64,12 +60,13 @@ class Configure extends React.Component {
6460
submit = () => {
6561
const {organization} = this.props;
6662
const {projectId} = this.props.params;
67-
analytics('onboarding.complete', {project: projectId});
68-
amplitude(
69-
'Completed Onboarding Installation Instructions',
70-
parseInt(organization.id, 10),
71-
{projectId}
72-
);
63+
64+
trackAnalyticsEvent({
65+
eventKey: 'onboarding.complete',
66+
eventName: 'Completed Onboarding Installation Instructions',
67+
organization_id: organization.id,
68+
projectId,
69+
});
7370
this.redirectUrl();
7471
};
7572

src/sentry/static/sentry/app/views/onboarding/progress.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import React from 'react';
33
import createReactClass from 'create-react-class';
44
import styled from 'react-emotion';
55

6-
import {analytics, amplitude} from 'app/utils/analytics';
76
import {onboardingSteps, stepDescriptions} from 'app/views/onboarding/utils';
7+
import {trackAnalyticsEvent} from 'app/utils/analytics';
88
import ConfigStore from 'app/stores/configStore';
99
import HookStore from 'app/stores/hookStore';
1010
import InlineSvg from 'app/components/inlineSvg';
@@ -27,10 +27,11 @@ const ProgressNodes = createReactClass({
2727
const step = this.inferStep();
2828

2929
if (step === 1) {
30-
analytics('onboarding.create_project_viewed', {
31-
org_id: parseInt(organization.id, 10),
30+
trackAnalyticsEvent({
31+
eventKey: 'onboarding.create_project_viewed',
32+
eventName: 'Viewed Onboarding Create Project',
33+
organization_id: organization.id,
3234
});
33-
amplitude('Viewed Onboarding Create Project', parseInt(organization.id, 10));
3435
}
3536
},
3637

0 commit comments

Comments
 (0)