Skip to content

Commit

Permalink
track if user is using self-serve or tauri in analytics, fallback for…
Browse files Browse the repository at this point in the history
… device id (BloopAI#333)
  • Loading branch information
anastasiya1155 authored Mar 27, 2023
1 parent f9176e9 commit 2069896
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import { listen } from '@tauri-apps/api/event';
import * as tauriOs from '@tauri-apps/api/os';
import { getVersion } from '@tauri-apps/api/app';
import ClientApp from '../../../client/src/App';
import TextSearch from './TextSearch';
import '../../../client/src/index.css';
import {
DEVICE_ID,
getPlainFromStorage,
savePlainToStorage,
} from '../../../client/src/services/storage';
import { generateUniqueId } from '../../../client/src/utils';
import TextSearch from './TextSearch';

// let askedToUpdate = false;
// let intervalId: number;
Expand Down Expand Up @@ -89,6 +95,13 @@ function App() {
.then((res) => {
if (res) {
setDeviceId(res.toString().trim());
} else {
let generatedId = getPlainFromStorage(DEVICE_ID);
if (!generatedId) {
generatedId = generateUniqueId();
savePlainToStorage(DEVICE_ID, generatedId);
}
setDeviceId(generatedId);
}
})
.catch(console.log);
Expand Down
1 change: 1 addition & 0 deletions client/src/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function Tab({ deviceContextValue, isActive, tab }: Props) {
<AnalyticsContextProvider
deviceId={deviceContextValue.deviceId}
forceAnalytics={deviceContextValue.forceAnalytics}
isSelfServe={deviceContextValue.isSelfServe}
>
<DeviceContextProvider deviceContextValue={deviceContextValue}>
<UIContextProvider>
Expand Down
6 changes: 5 additions & 1 deletion client/src/context/providers/AnalyticsContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ interface AnalyticsProviderProps {
children: React.ReactNode;
deviceId?: string;
forceAnalytics?: boolean;
isSelfServe?: boolean;
}

export const AnalyticsContextProvider: React.FC<AnalyticsProviderProps> = ({
children,
deviceId,
forceAnalytics,
isSelfServe,
}) => {
const WRITE_KEY = import.meta.env.PROD
? import.meta.env.ANALYTICS_FE_WRITE_KEY_PROD
Expand Down Expand Up @@ -45,7 +47,9 @@ export const AnalyticsContextProvider: React.FC<AnalyticsProviderProps> = ({

useEffect(() => {
if (analyticsLoaded && deviceId) {
analytics.identify(deviceId);
analytics.identify(deviceId, {
isSelfServe: isSelfServe,
});
}
}, [analyticsLoaded, deviceId]);

Expand Down
1 change: 1 addition & 0 deletions client/src/services/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export const SEARCH_HISTORY_KEY = 'search_history';
export const ONBOARDING_DONE_KEY = 'onboarding_done';
export const IS_ANALYTICS_ALLOWED_KEY = 'is_analytics_allowed';
export const SESSION_ID_KEY = 'session_id';
export const DEVICE_ID = 'device_id';

0 comments on commit 2069896

Please sign in to comment.