Skip to content

Commit cabc705

Browse files
authored
feat(suspect-commits): Add analytics events (#14080)
1 parent 7cd4e9e commit cabc705

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-4
lines changed

src/sentry/static/sentry/app/components/events/eventCauseEmpty.jsx

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SentryTypes from 'app/sentryTypes';
1313
import {snoozedDays} from 'app/utils/promptsActivity';
1414
import space from 'app/styles/space';
1515
import {t} from 'app/locale';
16+
import {trackAdhocEvent, trackAnalyticsEvent} from 'app/utils/analytics';
1617
import Tooltip from 'app/components/tooltip';
1718
import withApi from 'app/utils/withApi';
1819

@@ -48,6 +49,21 @@ class EventCauseEmpty extends React.Component {
4849
this.fetchData();
4950
}
5051

52+
componentDidUpdate(_prevProps, prevState) {
53+
const {project, organization} = this.props;
54+
const {shouldShow} = this.state;
55+
56+
if (!prevState.shouldShow && shouldShow) {
57+
// send to reload only due to high event volume
58+
trackAdhocEvent({
59+
eventKey: 'event_cause.viewed',
60+
org_id: parseInt(organization.id, 10),
61+
project_id: parseInt(project.id, 10),
62+
platform: project.platform,
63+
});
64+
}
65+
}
66+
5167
async fetchData() {
5268
const {api, project, organization} = this.props;
5369

@@ -72,7 +88,7 @@ class EventCauseEmpty extends React.Component {
7288
return true;
7389
}
7490

75-
handleClick(action) {
91+
handleClick({action, eventKey, eventName}) {
7692
const {api, project, organization} = this.props;
7793

7894
const data = {
@@ -82,6 +98,19 @@ class EventCauseEmpty extends React.Component {
8298
status: action,
8399
};
84100
promptsUpdate(api, data).then(this.setState({shouldShow: false}));
101+
this.trackAnalytics({eventKey, eventName});
102+
}
103+
104+
trackAnalytics({eventKey, eventName}) {
105+
const {project, organization} = this.props;
106+
107+
trackAnalyticsEvent({
108+
eventKey,
109+
eventName,
110+
organization_id: parseInt(organization.id, 10),
111+
project_id: parseInt(project.id, 10),
112+
platform: project.platform,
113+
});
85114
}
86115

87116
render() {
@@ -103,6 +132,13 @@ class EventCauseEmpty extends React.Component {
103132
size="small"
104133
priority="primary"
105134
href="https://docs.sentry.io/workflow/releases/#create-release"
135+
onClick={() =>
136+
this.trackAnalytics({
137+
eventKey: 'event_cause.docs_clicked',
138+
eventName: 'Event Cause Docs Clicked',
139+
})
140+
}
141+
data-test-id="read-the-docs"
106142
>
107143
{t('Read the docs')}
108144
</Button>
@@ -111,15 +147,27 @@ class EventCauseEmpty extends React.Component {
111147
<Tooltip title={t('Remind me next week')}>
112148
<SnoozeButton
113149
size="small"
114-
onClick={() => this.handleClick('snoozed')}
150+
onClick={() =>
151+
this.handleClick({
152+
action: 'snoozed',
153+
eventKey: 'event_cause.snoozed',
154+
eventName: 'Event Cause Snoozed',
155+
})
156+
}
115157
data-test-id="snoozed"
116158
>
117159
{t('Snooze')}
118160
</SnoozeButton>
119161
</Tooltip>
120162
<DismissButton
121163
size="small"
122-
onClick={() => this.handleClick('dismissed')}
164+
onClick={() =>
165+
this.handleClick({
166+
action: 'dismissed',
167+
eventKey: 'event_cause.dismissed',
168+
eventName: 'Event Cause Dismissed',
169+
})
170+
}
123171
data-test-id="dismissed"
124172
>
125173
{t('Dismiss')}

tests/js/spec/components/events/eventCauseEmpty.spec.jsx

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import moment from 'moment';
33
import {mount} from 'enzyme';
44

55
import EventCauseEmpty from 'app/components/events/eventCauseEmpty';
6+
import {trackAdhocEvent, trackAnalyticsEvent} from 'app/utils/analytics';
7+
8+
jest.mock('app/utils/analytics');
69

710
describe('EventCauseEmpty', function() {
811
let putMock;
912
const routerContext = TestStubs.routerContext();
1013
const organization = TestStubs.Organization();
11-
const project = TestStubs.Project();
14+
const project = TestStubs.Project({platform: 'javascript'});
1215

1316
beforeEach(function() {
1417
MockApiClient.clearMockResponses();
@@ -38,6 +41,13 @@ describe('EventCauseEmpty', function() {
3841
wrapper.update();
3942

4043
expect(wrapper.find('CommitRow').exists()).toBe(true);
44+
45+
expect(trackAdhocEvent).toHaveBeenCalledWith({
46+
eventKey: 'event_cause.viewed',
47+
org_id: parseInt(organization.id, 10),
48+
project_id: parseInt(project.id, 10),
49+
platform: project.platform,
50+
});
4151
});
4252

4353
it('can be snoozed', async function() {
@@ -68,6 +78,14 @@ describe('EventCauseEmpty', function() {
6878
);
6979

7080
expect(wrapper.find('CommitRow').exists()).toBe(false);
81+
82+
expect(trackAnalyticsEvent).toHaveBeenCalledWith({
83+
eventKey: 'event_cause.snoozed',
84+
eventName: 'Event Cause Snoozed',
85+
organization_id: parseInt(organization.id, 10),
86+
project_id: parseInt(project.id, 10),
87+
platform: project.platform,
88+
});
7189
});
7290

7391
it('does not render when snoozed', async function() {
@@ -142,6 +160,14 @@ describe('EventCauseEmpty', function() {
142160
);
143161

144162
expect(wrapper.find('CommitRow').exists()).toBe(false);
163+
164+
expect(trackAnalyticsEvent).toHaveBeenCalledWith({
165+
eventKey: 'event_cause.dismissed',
166+
eventName: 'Event Cause Dismissed',
167+
organization_id: parseInt(organization.id, 10),
168+
project_id: parseInt(project.id, 10),
169+
platform: project.platform,
170+
});
145171
});
146172

147173
it('does not render when dismissed', async function() {
@@ -161,4 +187,27 @@ describe('EventCauseEmpty', function() {
161187

162188
expect(wrapper.find('CommitRow').exists()).toBe(false);
163189
});
190+
191+
it('can capture analytics on docs click', async function() {
192+
const wrapper = mount(
193+
<EventCauseEmpty organization={organization} project={project} />,
194+
routerContext
195+
);
196+
197+
await tick();
198+
wrapper.update();
199+
200+
wrapper
201+
.find('[data-test-id="read-the-docs"]')
202+
.first()
203+
.simulate('click');
204+
205+
expect(trackAnalyticsEvent).toHaveBeenCalledWith({
206+
eventKey: 'event_cause.docs_clicked',
207+
eventName: 'Event Cause Docs Clicked',
208+
organization_id: parseInt(organization.id, 10),
209+
project_id: parseInt(project.id, 10),
210+
platform: project.platform,
211+
});
212+
});
164213
});

0 commit comments

Comments
 (0)