Skip to content

Commit d3a6f26

Browse files
authored
chore(analytics): Add debugging section to analytics page (#12856)
1 parent 3a47569 commit d3a6f26

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

develop-docs/development-infrastructure/analytics.mdx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ description: This guide steps you through instrumenting your code with Sentry's
44
sidebar_order: 90
55
---
66

7-
87
## Big Query
98

109
[BigQuery](https://cloud.google.com/bigquery/) is a Google data warehouse that a lot of our data calls home. This includes all our analytics data and some (not all) production data that might be of interest when joins are necessary for answering richer, more complex questions. From sentry/getsentry, our data goes through [reload](https://github.com/getsentry/reload), our ETL for BigQuery.
@@ -103,6 +102,7 @@ analytics.record(
103102
Run the tests that touch the endpoint to ensure everything is Gucci.
104103

105104
### Step 3:
105+
106106
By default, a new event type is aggregated and sent to Amplitude as long as there is a user_id sent along with the event. If you would like to send events unaggregated, refer to [our Amplitude aggregation docs](https://github.com/getsentry/etl/blob/master/documentation/amplitude_analytics.md)
107107

108108
## Route-Based Frontend Analytics
@@ -180,7 +180,7 @@ Example:
180180
<RestartButton
181181
analyticsEventName="Growth: Guided Tour Restart"
182182
analyticsEventKey="growth.guided_tour_restart"
183-
analyticsParams={{tour: 'issues'}}
183+
analyticsParams={{ tour: "issues" }}
184184
/>
185185
```
186186
@@ -198,10 +198,10 @@ First, add the Typescript definition of the event to an analytics event file ins
198198
199199
```tsx
200200
export type ExampleTutorialEventParameters = {
201-
'example_tutorial.created': {
201+
"example_tutorial.created": {
202202
source: string;
203203
};
204-
'example_tutorial.viewed': {
204+
"example_tutorial.viewed": {
205205
source: string;
206206
};
207207
};
@@ -214,8 +214,8 @@ export const exampleTutorialEventMap: Record<
214214
keyof ExampleTutorialEventParameters,
215215
string | null
216216
> = {
217-
'example_tutorial.created': 'Example Tutorial Created',
218-
'example_tutorial.viewed': null, // don't send to Amplitude
217+
"example_tutorial.created": "Example Tutorial Created",
218+
"example_tutorial.viewed": null, // don't send to Amplitude
219219
};
220220
```
221221
@@ -242,21 +242,23 @@ Our current naming convention for Reload events is `descriptor.action` e.g. what
242242
243243
### Testing your Analytics Event
244244
245+
It's important to test analytic events to ensure the data you are looking at is accurate. Any additional analytic event should be tested before merging to make sure that the events are firing correctly (with the correct values at the right times). A common issue we see when testing gets overlooked is events firing multiple times when they should only fire once.
246+
245247
When developing locally, analytics events will not be sent to Reload or Amplitude. To test to see if your event is sending as expected and with the correct data, you can set "DEBUG_ANALYTICS" to "1" in local storage on your browser. Then it will log the analytics event data to your console, whenever it would've sent an analytics event, allowing to check your analytics locally.
246248
247249
**getsentry**
248250
249251
```jsx
250-
import React from 'react';
252+
import React from "react";
251253

252-
import { trackAnalytics } from 'getsentry/utils/analytics';
254+
import { trackAnalytics } from "getsentry/utils/analytics";
253255

254256
class ExampleComponent extends React.Component {
255257
componentDidMount() {
256-
trackAnalytics('example_tutorial.created', {
258+
trackAnalytics("example_tutorial.created", {
257259
organization,
258260
subscription,
259-
source: 'wakanda',
261+
source: "wakanda",
260262
});
261263
}
262264

@@ -271,15 +273,15 @@ class ExampleComponent extends React.Component {
271273
All you'll actually need is to import analytics from utils and call it wherever you need. Keep in mind the effect of React lifecycles on your data. In this case, we only want to send one event when the component mounts so we place it in `componentDidMount` .
272274
273275
```jsx
274-
import React from 'react';
276+
import React from "react";
275277

276-
import { trackAnalytics } from 'getsentry/utils/analytics';
278+
import { trackAnalytics } from "getsentry/utils/analytics";
277279

278280
class ExampleComponent extends React.Component {
279281
componentDidMount() {
280-
trackAnalytics('example_tutorial.deleted', {
282+
trackAnalytics("example_tutorial.deleted", {
281283
organization,
282-
source: 'wakanda',
284+
source: "wakanda",
283285
});
284286
}
285287
render() {
@@ -288,6 +290,18 @@ class ExampleComponent extends React.Component {
288290
}
289291
```
290292
293+
After deploying your changes, you can open the Dev Tools in your browser and in the "Network" tab, search for the `event/` request. This will show the events being sent to Reload and Amplitude.
294+
295+
## Debugging
296+
297+
If your analytics aren't showing up after you added it, you can't find an event you expect to be there, or something else goes wrong, there are a few troubleshooting steps you can try:
298+
299+
- Follow the steps [above](https://docs.sentry.io/development-infrastructure/analytics/#testing-your-analytics-event) to confirm that your analytics event is sending correctly, with the correct parameters.
300+
- Check Amplitude for blocked events: In Amplitude, go to the "Data" section in the sidebar. From there, navigate to "Events" and search for your event name. It will show up with status "Blocked" if blocked, which means events won't show up. Some events may be blocked in favor of automatic route or button analytics.
301+
- For route analytics, confirm that the analytic event isn't being blocked with `useDisableRouteAnalytics`. Some components already had an analytic event so the route analytics were disabled.
302+
- Check the types of the data you are sending. Arrays aren't recommended data types to send (they can be hard to query and produce some unexpected behavior). Try to remove those if you are using them.
303+
- Remember there will always be some discrepency. Ad-blockers, for example, can block events from being sent. This could be a cause of why some numbers aren't adding up.
304+
291305
## Metrics
292306
293307
Track aggregrate stats with [Metrics](/backend/metrics/). For example, this can be used to track aggregate response codes for an endpoint.

0 commit comments

Comments
 (0)