Skip to content

Commit 0936337

Browse files
authored
Merge pull request #1438 from AppQuality/send-utm-source-to-analytics
Store UTM source and improve Userpilot token handling
2 parents 019c69d + d2fdd08 commit 0936337

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/analytics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const analytics = Analytics({
1515
}),
1616
}),
1717
userpilot({
18-
token: isDev() ? 'STG-NX-54e88e10' : 'NX-54e88e10',
18+
token: 'NX-54e88e10',
1919
}),
2020
],
2121
}),

src/common/Track.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const Track = ({
1919
const { data: userData, isLoading, isSuccess } = useGetUsersMeQuery();
2020
const { activeWorkspace } = useActiveWorkspace();
2121
const { track, identify, page } = useAnalytics();
22+
const utmSource = sessionStorage.getItem('utmSource');
2223
const location = useLocation();
2324

2425
const defaultMeta = [
@@ -63,6 +64,7 @@ export const Track = ({
6364
email: userData.email,
6465
company: activeWorkspace.company,
6566
workspace: activeWorkspace,
67+
...((utmSource && { utm_source: utmSource }) || {}),
6668
});
6769

6870
track(

src/common/analytics-plugins/userpilot.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { User } from 'src/features/api';
22
import { Userpilot } from 'userpilot';
3+
import { isDev } from '../isDevEnvironment';
34

45
declare global {
56
interface Window {
@@ -56,6 +57,9 @@ export default function userpilotPlugin(pluginSettings: UserpilotConfig) {
5657
Userpilot.track(event, { ...properties, userId });
5758
},
5859

59-
loaded: () => !!window.userpilot,
60+
loaded: () => {
61+
const previewEnabled = localStorage.getItem('userpilot_ug_preview');
62+
return isDev() && previewEnabled !== null ? true : !!window.userpilot;
63+
},
6064
};
6165
}

src/pages/JoinPage/useJoinSubmit.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function useJoinSubmit(isInvited: boolean) {
1616
const sendGTMevent = useSendGTMevent({ loggedUser: false });
1717

1818
const templateParam = searchParams.get('template');
19+
const utmSource = searchParams.get('utm_source');
1920
let templateId: number | undefined;
2021

2122
if (templateParam !== null) {
@@ -29,6 +30,10 @@ export function useJoinSubmit(isInvited: boolean) {
2930
templateId = parsed;
3031
}
3132

33+
if (utmSource !== null) {
34+
sessionStorage.setItem('utmSource', utmSource);
35+
}
36+
3237
const onSubmit = useCallback(
3338
async (
3439
values: JoinFormValues,

0 commit comments

Comments
 (0)