Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 2069896

Browse files
track if user is using self-serve or tauri in analytics, fallback for device id (#333)
1 parent f9176e9 commit 2069896

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

apps/desktop/src/App.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ import { listen } from '@tauri-apps/api/event';
77
import * as tauriOs from '@tauri-apps/api/os';
88
import { getVersion } from '@tauri-apps/api/app';
99
import ClientApp from '../../../client/src/App';
10-
import TextSearch from './TextSearch';
1110
import '../../../client/src/index.css';
11+
import {
12+
DEVICE_ID,
13+
getPlainFromStorage,
14+
savePlainToStorage,
15+
} from '../../../client/src/services/storage';
16+
import { generateUniqueId } from '../../../client/src/utils';
17+
import TextSearch from './TextSearch';
1218

1319
// let askedToUpdate = false;
1420
// let intervalId: number;
@@ -89,6 +95,13 @@ function App() {
8995
.then((res) => {
9096
if (res) {
9197
setDeviceId(res.toString().trim());
98+
} else {
99+
let generatedId = getPlainFromStorage(DEVICE_ID);
100+
if (!generatedId) {
101+
generatedId = generateUniqueId();
102+
savePlainToStorage(DEVICE_ID, generatedId);
103+
}
104+
setDeviceId(generatedId);
92105
}
93106
})
94107
.catch(console.log);

client/src/Tab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function Tab({ deviceContextValue, isActive, tab }: Props) {
3838
<AnalyticsContextProvider
3939
deviceId={deviceContextValue.deviceId}
4040
forceAnalytics={deviceContextValue.forceAnalytics}
41+
isSelfServe={deviceContextValue.isSelfServe}
4142
>
4243
<DeviceContextProvider deviceContextValue={deviceContextValue}>
4344
<UIContextProvider>

client/src/context/providers/AnalyticsContextProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ interface AnalyticsProviderProps {
1010
children: React.ReactNode;
1111
deviceId?: string;
1212
forceAnalytics?: boolean;
13+
isSelfServe?: boolean;
1314
}
1415

1516
export const AnalyticsContextProvider: React.FC<AnalyticsProviderProps> = ({
1617
children,
1718
deviceId,
1819
forceAnalytics,
20+
isSelfServe,
1921
}) => {
2022
const WRITE_KEY = import.meta.env.PROD
2123
? import.meta.env.ANALYTICS_FE_WRITE_KEY_PROD
@@ -45,7 +47,9 @@ export const AnalyticsContextProvider: React.FC<AnalyticsProviderProps> = ({
4547

4648
useEffect(() => {
4749
if (analyticsLoaded && deviceId) {
48-
analytics.identify(deviceId);
50+
analytics.identify(deviceId, {
51+
isSelfServe: isSelfServe,
52+
});
4953
}
5054
}, [analyticsLoaded, deviceId]);
5155

client/src/services/storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export const SEARCH_HISTORY_KEY = 'search_history';
2222
export const ONBOARDING_DONE_KEY = 'onboarding_done';
2323
export const IS_ANALYTICS_ALLOWED_KEY = 'is_analytics_allowed';
2424
export const SESSION_ID_KEY = 'session_id';
25+
export const DEVICE_ID = 'device_id';

0 commit comments

Comments
 (0)