Skip to content

Commit 3460e43

Browse files
committed
feat: set custom_referrer if projects visited from org menu
1 parent 13d8ef2 commit 3460e43

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

static/app/views/nav/orgDropdown.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import OrganizationsStore from 'sentry/stores/organizationsStore';
1616
import {useLegacyStore} from 'sentry/stores/useLegacyStore';
1717
import type {Organization} from 'sentry/types/organization';
1818
import {isDemoModeActive} from 'sentry/utils/demoMode';
19+
import localStorage from 'sentry/utils/localStorage';
1920
import {localizeDomain, resolveRoute} from 'sentry/utils/resolveRoute';
21+
import {useNavigate} from 'sentry/utils/useNavigate';
2022
import useOrganization from 'sentry/utils/useOrganization';
2123
import useProjects from 'sentry/utils/useProjects';
2224
import {useNavContext} from 'sentry/views/nav/context';
@@ -61,6 +63,7 @@ export function OrgDropdown({
6163

6264
const config = useLegacyStore(ConfigStore);
6365
const organization = useOrganization();
66+
const navigate = useNavigate();
6467

6568
// It's possible we do not have an org in context (e.g. RouteNotFound)
6669
// Otherwise, we should have the full org
@@ -144,7 +147,10 @@ export function OrgDropdown({
144147
{
145148
key: 'projects',
146149
label: t('Projects'),
147-
to: makeProjectsPathname({path: '/', organization}),
150+
onAction: () => {
151+
localStorage.setItem('customReferrer', 'org-dropdown');
152+
navigate(makeProjectsPathname({path: '/', organization}));
153+
},
148154
hidden: hideOrgLinks,
149155
},
150156
{

static/gsApp/utils/rawTrackAnalyticsEvent.spec.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {setWindowLocation} from 'sentry-test/utils';
55

66
import ConfigStore from 'sentry/stores/configStore';
77
import {uniqueId} from 'sentry/utils/guid';
8+
import localStorageWrapper from 'sentry/utils/localStorage';
89
import sessionStorage from 'sentry/utils/sessionStorage';
910

1011
import rawTrackAnalyticsEvent from 'getsentry/utils/rawTrackAnalyticsEvent';
@@ -184,6 +185,31 @@ describe('rawTrackAnalyticsEvent', () => {
184185
);
185186
setWindowLocation('http:/localhost/');
186187
});
188+
189+
it('sets custom_referrer if found in local storage', () => {
190+
localStorageWrapper.setItem('customReferrer', 'batman');
191+
setWindowLocation('http:/localhost');
192+
rawTrackAnalyticsEvent({
193+
eventKey: 'test_event',
194+
eventName: 'Test Event',
195+
organization,
196+
});
197+
198+
expect(trackReloadEvent).toHaveBeenCalledWith(
199+
'test_event',
200+
expect.objectContaining({custom_referrer: 'batman'})
201+
);
202+
203+
expect(trackAmplitudeEvent).toHaveBeenCalledWith(
204+
'Test Event',
205+
org_id,
206+
expect.objectContaining({custom_referrer: 'batman'}),
207+
{time: undefined}
208+
);
209+
setWindowLocation('http:/localhost/');
210+
expect(localStorageWrapper.getItem('customReferrer')).toBeNull();
211+
});
212+
187213
it('start analytics session', () => {
188214
rawTrackAnalyticsEvent(
189215
{

static/gsApp/utils/rawTrackAnalyticsEvent.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ const hasAnalyticsDebug = () => localStorage.getItem('DEBUG_ANALYTICS_GETSENTRY'
7171

7272
const getCustomReferrer = () => {
7373
try {
74+
// pull the referrer from local storage.
75+
if (
76+
localStorage.getItem('customReferrer') &&
77+
typeof localStorage.getItem('customReferrer') === 'string'
78+
) {
79+
const referrer = localStorage.getItem('customReferrer');
80+
localStorage.removeItem('customReferrer');
81+
return referrer;
82+
}
7483
// pull the referrer from the query parameter of the page
7584
const {referrer} = qs.parse(window.location.search) || {};
7685
if (referrer && typeof referrer === 'string') {

0 commit comments

Comments
 (0)