Skip to content

Commit 2b52362

Browse files
committed
refactor: include device_id in events
1 parent d6d1364 commit 2b52362

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

src/DetourContext.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { resolveStorage } from './links/utils/storage';
1111
import { useDetour } from './links/hooks/useDetour';
1212
import { prepareDeviceIdForApi } from './analytics/utils/devicePersistence';
1313
import { sendRetentionEvent } from './analytics/api/retention';
14-
import type { DetourEventNames } from './analytics/types';
14+
import type { DetourEvent, DetourEventNames } from './analytics/types';
1515
import { useAppOpenRetention } from './analytics/hooks/useAppOpenRetention';
1616

1717
type Props = PropsWithChildren & { config: Config };
@@ -46,13 +46,20 @@ export const DetourProvider = ({ config, children }: Props) => {
4646
return;
4747
}
4848

49+
const deviceId = await prepareDeviceIdForApi(storage);
50+
4951
if (isRetention) {
50-
const deviceId = await prepareDeviceIdForApi(storage);
5152
sendRetentionEvent({ API_KEY, appID, eventName, deviceId });
5253
} else {
53-
sendEvent(API_KEY, appID, {
54+
const event: DetourEvent = {
5455
eventName: eventName as DetourEventNames,
5556
data,
57+
};
58+
sendEvent({
59+
API_KEY,
60+
appID,
61+
event,
62+
deviceId,
5663
});
5764
}
5865
}

src/analytics/api/events.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import type { DetourEvent } from '../types';
33

44
const EVENT_API_URL = 'https://godetour.dev/api/analytics/event';
55

6-
export const sendEvent = async (
7-
API_KEY: string,
8-
appID: string,
9-
event: DetourEvent
10-
) => {
6+
export const sendEvent = async ({
7+
API_KEY,
8+
appID,
9+
deviceId,
10+
event,
11+
}: {
12+
API_KEY: string;
13+
appID: string;
14+
event: DetourEvent;
15+
deviceId: string;
16+
}) => {
1117
try {
1218
const response = await fetch(EVENT_API_URL, {
1319
method: 'POST',
@@ -21,6 +27,7 @@ export const sendEvent = async (
2127
data: event.data,
2228
timestamp: new Date().toISOString(),
2329
platform: Platform.OS,
30+
device_id: deviceId,
2431
}),
2532
});
2633

0 commit comments

Comments
 (0)