Skip to content

ref(analytics): Replace amplitude with analytics:track-event #13536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/sentry/static/sentry/app/stores/hookStore.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ const validHookNames = new Set([
'routes:organization-root',

// Analytics and tracking hooks
'amplitude:event',
'analytics:event',
'analytics:init-user',
'analytics:track-event',
'analytics:track-adhoc-event',

// TODO(epurkhser): This is deprecated and should be replaced
'analytics:event',

// Operational metrics
'metrics:event',
Expand Down
60 changes: 48 additions & 12 deletions src/sentry/static/sentry/app/utils/analytics.jsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,70 @@
import HookStore from 'app/stores/hookStore';

/**
* If the backend for `analytics` is reload, you will need to add the event `name`
* to the inclusion list in https://github.com/getsentry/reload/blob/master/reload_app/events.py
* Analytics and metric tracking functionality.
*
* These are primarily driven through hooks provided through the hookstore. For
* sentry.io these are currently mapped to our in-house analytics backend
* 'Reload' and the Amplitude service.
*
* If you are using `gauge` or `increment`, the metric names need to be added to
* https://github.com/getsentry/reload/blob/master/reload_app/metrics/__init__.py
* NOTE: sentry.io contributors, you will need to nesure that the eventKey
* passed exists as an event key in the Reload events.py configuration:
*
* https://github.com/getsentry/reload/blob/master/reload_app/events.py
*
* NOTE: sentry.io contributors, if you are using `gauge` or `increment` the
* name must be added to the Reload metrics module:
*
* https://github.com/getsentry/reload/blob/master/reload_app/metrics/__init__.py
*/

/**
* This should be primarily used for product events. In that case where you
* want to track some one-off Adhoc events, use the `trackAdhocEvent` function.
*
* Generally this is the function you will want to use for event tracking.
*
* Refer for the backend implementation provided through HookStore for more
* details.
*
* @param {Object} options Event tracking options
* @param {String} options.eventKey The string key of the event to track
* @param {String} options.name The human readable string name of the event
* @param {...Object} options.data The parameters of the event to track
*/
export const trackAnalyticsEvent = options =>
HookStore.get('analytics:track-event').forEach(cb => cb(options));

/**
* This should be used for adhoc analytics tracking.
*
* This is used for high volume events, and events with unbounded parameters,
* such as tracking search queries.
*
* Refer for the backend implementation provided through HookStore for a more
* thorough explanation of when to use this.
*
* @param {Object} options Event tracking options
* @param {String} options.eventKey The string key of the event to track
* @param {...Object} options.data The parameters of the event to track
*/
export const trackAdhocEvent = options =>
HookStore.get('analytics:track-adhoc-event').forEach(cb => cb(options));

/**
* @param {String} name The name of the event
* @param {Object} data Additional event data to record
*/
export function analytics(name, data) {
export const analytics = (name, data) =>
HookStore.get('analytics:event').forEach(cb => cb(name, data));
}

export function amplitude(name, organization_id, data) {
HookStore.get('amplitude:event').forEach(cb => cb(name, organization_id, data));
}

/**
* @param {String} name Metric name
* @param {Number} value Value to record for this metric
* @param {Object} tags An additional tags object
*/
export function metric(name, value, tags) {
export const metric = (name, value, tags) =>
HookStore.get('metrics:event').forEach(cb => cb(name, value, tags));
}

// JSDOM implements window.performance but not window.performance.mark
const CAN_MARK =
Expand Down
31 changes: 14 additions & 17 deletions src/sentry/static/sentry/app/views/onboarding/configure.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {browserHistory} from 'react-router';
import React from 'react';
import styled from 'react-emotion';

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

componentDidMount() {
const {organization, params} = this.props;
const data = {

trackAnalyticsEvent({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So do these now go to both reload and amplitude?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were already going to both. yes

eventKey: 'onboarding.configure_viewed',
eventName: 'Viewed Onboarding Installation Instructions',
organization_id: organization.id,
project: params.projectId,
platform: params.platform,
};

amplitude(
'Viewed Onboarding Installation Instructions',
parseInt(organization.id, 10),
data
);
});

data.org_id = parseInt(organization.id, 10);
analytics('onboarding.configure_viewed', data);
this.sentRealEvent();
}

Expand Down Expand Up @@ -64,12 +60,13 @@ class Configure extends React.Component {
submit = () => {
const {organization} = this.props;
const {projectId} = this.props.params;
analytics('onboarding.complete', {project: projectId});
amplitude(
'Completed Onboarding Installation Instructions',
parseInt(organization.id, 10),
{projectId}
);

trackAnalyticsEvent({
eventKey: 'onboarding.complete',
eventName: 'Completed Onboarding Installation Instructions',
organization_id: organization.id,
projectId,
});
this.redirectUrl();
};

Expand Down
9 changes: 5 additions & 4 deletions src/sentry/static/sentry/app/views/onboarding/progress.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react';
import createReactClass from 'create-react-class';
import styled from 'react-emotion';

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

if (step === 1) {
analytics('onboarding.create_project_viewed', {
org_id: parseInt(organization.id, 10),
trackAnalyticsEvent({
eventKey: 'onboarding.create_project_viewed',
eventName: 'Viewed Onboarding Create Project',
organization_id: organization.id,
});
amplitude('Viewed Onboarding Create Project', parseInt(organization.id, 10));
}
},

Expand Down