-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathdeeplink.ts
More file actions
87 lines (77 loc) · 2.42 KB
/
deeplink.ts
File metadata and controls
87 lines (77 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import type { AttributionData } from './attribution';
/**
* Deep link data extracted from URL parameters
*/
export interface DeepLinkData {
/** Deep link path (e.g., '/product/123') */
path?: string;
/** Deep link value (alternative to path) */
value?: string;
/** All deep link parameters */
params?: Record<string, string>;
/** Full deep link URL */
url?: string;
}
/**
* Common deep link parameter names used by AppsFlyer/Adjust
*/
const DEEP_LINK_PARAM_NAMES = [
'deep_link',
'deep_link_value',
'deep_link_path',
'af_dp', // AppsFlyer deep link path
'af_dl', // AppsFlyer deep link value
'af_web_dp', // AppsFlyer web deep link path
'adjust_deeplink', // Adjust deep link
'deeplink',
'deeplink_path',
'deeplink_value',
];
/**
* Extract deep link data from attribution data
*/
export function extractDeepLinkData(attribution: AttributionData | null): DeepLinkData | null {
if (!attribution || !attribution.custom) {
return null;
}
const deepLink: DeepLinkData = {
params: {},
};
// Check for common deep link parameter names
for (const paramName of DEEP_LINK_PARAM_NAMES) {
const value = attribution.custom[paramName];
if (value) {
if (paramName.includes('path') || paramName === 'af_dp' || paramName === 'af_web_dp') {
deepLink.path = value;
} else if (paramName.includes('value') || paramName === 'af_dl') {
deepLink.value = value;
} else {
// Generic deep link parameter
deepLink.path = deepLink.path || value;
deepLink.value = deepLink.value || value;
}
}
}
// If no standard deep link params found, check for any custom params
// that might be deep link related
if (!deepLink.path && !deepLink.value && Object.keys(attribution.custom).length > 0) {
// Use first custom param as potential deep link
const firstParam = Object.entries(attribution.custom)[0];
if (firstParam) {
deepLink.value = firstParam[1];
deepLink.params = { [firstParam[0]]: firstParam[1] };
}
} else {
// Include all custom params as deep link params
deepLink.params = { ...attribution.custom };
}
// Include landing page URL if available
if (attribution.landingPage) {
deepLink.url = attribution.landingPage;
}
// Return null if no deep link data found
if (!deepLink.path && !deepLink.value && Object.keys(deepLink.params || {}).length === 0) {
return null;
}
return deepLink;
}