Skip to content

Commit 3f09a3a

Browse files
authored
feat: added event log for opening app via universal link (#48)
1 parent 1d87f0d commit 3f09a3a

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const OPENED_VIA_UNIVERSAL_LINK = 'opened_via_universal_link';
2+
export const DEFAULT_RETENTION_EVENT = 'app_open';

src/analytics/hooks/useAppOpenRetention.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect } from 'react';
22
import { logRetention } from '../analytics';
3+
import { DEFAULT_RETENTION_EVENT } from '../const/definedEvents';
34

4-
const DEFAULT_RETENTION_EVENT = 'app_open';
55
let isColdStartLogged = false;
66

77
export const useAppOpenRetention = () => {

src/expo-router/nativeIntent.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { OPENED_VIA_UNIVERSAL_LINK } from '../analytics/const/definedEvents';
2+
import { analyticsEmitter } from '../analytics/utils/analyticsEmitter';
13
import { resolveShortLink } from '../links/api/resolveShortLink';
24
import type { Config } from '../links/types';
35
import { getRouteFromDeepLink } from '../links/utils/urlHelpers';
@@ -293,6 +295,11 @@ export const createDetourNativeIntentHandler = (
293295
return path;
294296
}
295297

298+
analyticsEmitter.emit({
299+
eventName: OPENED_VIA_UNIVERSAL_LINK,
300+
data: { url: path },
301+
});
302+
296303
if (!options.config) {
297304
return fallbackPath;
298305
}

src/links/hooks/useDetour.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useEffect, useState } from 'react';
22
import { Linking } from 'react-native';
3+
import { analyticsEmitter } from '../../analytics/utils/analyticsEmitter';
34
import { getDeferredLink } from '../api/getDeferredLink';
45
import { resolveShortLink } from '../api/resolveShortLink';
56
import type {
@@ -15,6 +16,7 @@ import {
1516
isInfrastructureUrl,
1617
isWebUrl,
1718
} from '../utils/urlHelpers';
19+
import { OPENED_VIA_UNIVERSAL_LINK } from '../../analytics/const/definedEvents';
1820

1921
let sessionHandled = false;
2022

@@ -152,7 +154,15 @@ export const useDetour = ({
152154

153155
const subscription = Linking.addEventListener('url', async ({ url }) => {
154156
const resolved = await resolveLink(url);
155-
if (resolved) setLink(resolved);
157+
if (resolved) {
158+
if (resolved.type !== 'scheme') {
159+
analyticsEmitter.emit({
160+
eventName: OPENED_VIA_UNIVERSAL_LINK,
161+
data: { url },
162+
});
163+
}
164+
setLink(resolved);
165+
}
156166
});
157167
return () => subscription.remove();
158168
}, [linkProcessingMode, resolveLink]);
@@ -175,7 +185,15 @@ export const useDetour = ({
175185
if (initialUrl && !isInfrastructureUrl(initialUrl)) {
176186
await markFirstEntrance(storage);
177187
const resolved = await resolveLink(initialUrl);
178-
if (resolved) setLink(resolved);
188+
if (resolved) {
189+
if (resolved.type !== 'scheme') {
190+
analyticsEmitter.emit({
191+
eventName: OPENED_VIA_UNIVERSAL_LINK,
192+
data: { url: initialUrl },
193+
});
194+
}
195+
setLink(resolved);
196+
}
179197
return;
180198
}
181199
}

0 commit comments

Comments
 (0)