Skip to content

Commit 2c8a518

Browse files
authored
analytics(insights): pass in referrer to open in explore and create alert in charts (#93901)
Under the hood, our track analytics functions automatically read the `referrer` query param, and add it as the `custom_referrer` attribute. https://github.com/getsentry/sentry/blob/c17702cc58f623bd71844cb07e81142f85b0a5b1/static/gsApp/utils/rawTrackAnalyticsEvent.tsx#L170 This pr ensure the explore url and alerts url contain a referrer when navigating from an insights chart
1 parent fdeae58 commit 2c8a518

File tree

9 files changed

+37
-11
lines changed

9 files changed

+37
-11
lines changed

static/app/views/explore/multiQueryMode/locationUtils.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,15 @@ type CompareRouteProps = {
298298
mode: Mode;
299299
organization: Organization;
300300
queries: WritableExploreQueryParts[];
301+
referrer?: string;
301302
};
302303

303304
export function generateExploreCompareRoute({
304305
organization,
305306
location,
306307
mode,
307308
queries,
309+
referrer,
308310
}: CompareRouteProps): LocationDescriptorObject {
309311
const url = getCompareBaseUrl(organization);
310312
const compareQueries = queries.map(query => ({
@@ -318,17 +320,22 @@ export function generateExploreCompareRoute({
318320
if (compareQueries.length < 2) {
319321
compareQueries.push(DEFAULT_QUERY);
320322
}
323+
const query = {
324+
[URL_PARAM.END]: location.query.end,
325+
[URL_PARAM.START]: location.query.start,
326+
[URL_PARAM.UTC]: location.query.utc,
327+
[URL_PARAM.PERIOD]: location.query.statsPeriod,
328+
[URL_PARAM.PROJECT]: location.query.project,
329+
[URL_PARAM.ENVIRONMENT]: location.query.environment,
330+
queries: getQueriesAsUrlParam(compareQueries),
331+
};
332+
333+
if (referrer) {
334+
query.referrer = referrer;
335+
}
321336

322337
return {
323338
pathname: url,
324-
query: {
325-
[URL_PARAM.END]: location.query.end,
326-
[URL_PARAM.START]: location.query.start,
327-
[URL_PARAM.UTC]: location.query.utc,
328-
[URL_PARAM.PERIOD]: location.query.statsPeriod,
329-
[URL_PARAM.PROJECT]: location.query.project,
330-
[URL_PARAM.ENVIRONMENT]: location.query.environment,
331-
queries: getQueriesAsUrlParam(compareQueries),
332-
},
339+
query,
333340
};
334341
}

static/app/views/explore/utils.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export function getExploreUrl({
5454
field,
5555
id,
5656
title,
57+
referrer,
5758
}: {
5859
organization: Organization;
5960
aggregateField?: Array<GroupBy | BaseVisualize>;
@@ -63,6 +64,7 @@ export function getExploreUrl({
6364
interval?: string;
6465
mode?: Mode;
6566
query?: string;
67+
referrer?: string;
6668
selection?: PageFilters;
6769
sort?: string;
6870
title?: string;
@@ -87,6 +89,7 @@ export function getExploreUrl({
8789
utc,
8890
id,
8991
title,
92+
referrer,
9093
};
9194

9295
return (

static/app/views/insights/common/components/chartActionDropdown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function ChartActionDropdown({
5353
query: search?.formatString(),
5454
sort: undefined,
5555
groupBy,
56+
referrer,
5657
});
5758

5859
const alertsUrls = yAxes.map((yAxis, index) => {

static/app/views/insights/common/components/widgets/httpDomainSummaryResponseCodesChartWidget.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function HttpDomainSummaryResponseCodesChartWidget(
7272
...query,
7373
chartType: ChartType.LINE,
7474
})),
75+
referrer,
7576
});
7677

7778
const extraActions = [
@@ -89,6 +90,7 @@ export default function HttpDomainSummaryResponseCodesChartWidget(
8990
pageFilters: selection,
9091
dataset: Dataset.EVENTS_ANALYTICS_PLATFORM,
9192
query: query.query,
93+
referrer,
9294
}),
9395
}))}
9496
/>,

static/app/views/insights/common/components/widgets/httpResponseCodesChartWidget.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export default function HttpResponseCodesChartWidget(props: LoadableChartWidgetP
7070
...query,
7171
chartType: ChartType.LINE,
7272
})),
73+
referrer,
7374
});
7475

7576
const extraActions = [
@@ -87,6 +88,7 @@ export default function HttpResponseCodesChartWidget(props: LoadableChartWidgetP
8788
pageFilters: selection,
8889
dataset: Dataset.EVENTS_ANALYTICS_PLATFORM,
8990
query: query.query,
91+
referrer,
9092
}),
9193
}))}
9294
/>,

static/app/views/insights/common/utils/getAlertsUrl.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function getAlertsUrl({
1515
name,
1616
interval,
1717
dataset = Dataset.GENERIC_METRICS,
18+
referrer,
1819
}: {
1920
aggregate: string;
2021
organization: Organization;
@@ -24,6 +25,7 @@ export function getAlertsUrl({
2425
name?: string;
2526
project?: Project;
2627
query?: string;
28+
referrer?: string;
2729
}) {
2830
const statsPeriod = getStatsPeriod(pageFilters);
2931
const environment = pageFilters.environments;
@@ -38,6 +40,7 @@ export function getAlertsUrl({
3840
environment,
3941
name,
4042
interval: supportedInterval,
43+
referrer,
4144
};
4245

4346
return (

static/app/views/insights/http/components/charts/responseCodeCountChart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export function ResponseCodeCountChart({
9292
query: search?.formatString(),
9393
sort: undefined,
9494
groupBy,
95+
referrer,
9596
});
9697

9798
const extraActions = [
@@ -109,6 +110,7 @@ export function ResponseCodeCountChart({
109110
pageFilters: selection,
110111
dataset: Dataset.EVENTS_ANALYTICS_PLATFORM,
111112
query: query.query,
113+
referrer,
112114
}),
113115
}))}
114116
/>,

static/app/views/insights/pages/platform/shared/toolbar.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ export function Toolbar({
3232
const {selection} = usePageFilters();
3333
const project = useAlertsProject();
3434

35+
const referrer = loaderSource || 'insights.platform.toolbar';
36+
3537
const exploreUrl =
36-
exploreParams && getExploreUrl({...exploreParams, organization, selection});
38+
exploreParams && getExploreUrl({...exploreParams, organization, selection, referrer});
3739

3840
const yAxes = exploreParams?.visualize?.flatMap(v => v.yAxes) || [];
3941

@@ -49,6 +51,7 @@ export function Toolbar({
4951
pageFilters: selection,
5052
aggregate: yAxis,
5153
organization,
54+
referrer,
5255
}),
5356
};
5457
});
@@ -59,7 +62,7 @@ export function Toolbar({
5962
<BaseChartActionDropdown
6063
exploreUrl={exploreUrl}
6164
alertMenuOptions={showCreateAlert ? alertsUrls : []}
62-
referrer={loaderSource || 'insights.platform.toolbar'}
65+
referrer={referrer}
6366
/>
6467
) : null}
6568

static/app/views/insights/queues/charts/throughputChart.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function ThroughputChart({id, error, destination, pageFilters, referrer}:
8787
query: search?.formatString(),
8888
sort: undefined,
8989
groupBy: [groupBy],
90+
referrer,
9091
});
9192

9293
const extraActions = [
@@ -103,6 +104,7 @@ export function ThroughputChart({id, error, destination, pageFilters, referrer}:
103104
pageFilters: selection,
104105
aggregate: yAxis,
105106
organization,
107+
referrer,
106108
}),
107109
},
108110
{
@@ -115,6 +117,7 @@ export function ThroughputChart({id, error, destination, pageFilters, referrer}:
115117
pageFilters: selection,
116118
aggregate: yAxis,
117119
organization,
120+
referrer,
118121
}),
119122
},
120123
]}

0 commit comments

Comments
 (0)