@reservamos/browser-analytics 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-analytics.cjs +1 -1
- package/dist/browser-analytics.cjs.map +1 -1
- package/dist/browser-analytics.esm.js +9 -1
- package/dist/browser-analytics.esm.js.map +1 -1
- package/dist/browser-analytics.iife.js +1 -1
- package/dist/browser-analytics.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/profiles/createAnonymousProfile/createAnonymousProfile.ts +20 -11
package/package.json
CHANGED
|
@@ -10,7 +10,8 @@ type IdentifierKey = 'phone' | 'email';
|
|
|
10
10
|
interface AnonymousProfilePayload {
|
|
11
11
|
identifier_key: IdentifierKey;
|
|
12
12
|
identifier_value: string;
|
|
13
|
-
identifiers: AnonymousIdentifier[]
|
|
13
|
+
identifiers: AnonymousIdentifier[];
|
|
14
|
+
details: Record<string, string>;
|
|
14
15
|
}
|
|
15
16
|
interface AnonymousProfileResponse {
|
|
16
17
|
id: string;
|
|
@@ -23,11 +24,11 @@ interface AnonymousProfileResponse {
|
|
|
23
24
|
*/
|
|
24
25
|
function getAnonymousProfilePayload(
|
|
25
26
|
values: CreateAnonymousProfileProps,
|
|
26
|
-
identifiersProps: AnonymousIdentifier[]
|
|
27
|
+
identifiersProps: AnonymousIdentifier[],
|
|
27
28
|
): AnonymousProfilePayload {
|
|
28
29
|
let identifier_key: IdentifierKey = 'phone';
|
|
29
30
|
let identifier_value: string = values.phone || '';
|
|
30
|
-
const identifiers: AnonymousIdentifier[] = []
|
|
31
|
+
const identifiers: AnonymousIdentifier[] = [];
|
|
31
32
|
|
|
32
33
|
if (values.email) {
|
|
33
34
|
identifier_key = 'email';
|
|
@@ -35,7 +36,14 @@ function getAnonymousProfilePayload(
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// List of allowed keys for details
|
|
38
|
-
const allowedKeys = [
|
|
39
|
+
const allowedKeys = [
|
|
40
|
+
'cpf',
|
|
41
|
+
'passport',
|
|
42
|
+
'rg',
|
|
43
|
+
'email',
|
|
44
|
+
'phone',
|
|
45
|
+
'salesforceid',
|
|
46
|
+
];
|
|
39
47
|
|
|
40
48
|
Object.entries(values).forEach(([key, value]) => {
|
|
41
49
|
if (allowedKeys.includes(key.toLowerCase()) && value) {
|
|
@@ -45,13 +53,14 @@ function getAnonymousProfilePayload(
|
|
|
45
53
|
}
|
|
46
54
|
});
|
|
47
55
|
|
|
48
|
-
if(identifiersProps.length){
|
|
49
|
-
|
|
56
|
+
if (identifiersProps.length) {
|
|
57
|
+
identifiersProps.forEach((item) => identifiers.push(item));
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
return {
|
|
53
61
|
identifier_key,
|
|
54
62
|
identifier_value,
|
|
63
|
+
details: {},
|
|
55
64
|
identifiers,
|
|
56
65
|
};
|
|
57
66
|
}
|
|
@@ -68,7 +77,7 @@ interface AnonymousIdentifier {
|
|
|
68
77
|
*/
|
|
69
78
|
async function createAnonymousProfile(
|
|
70
79
|
payload: CreateAnonymousProfileProps,
|
|
71
|
-
): Promise<AnonymousProfileResponse | undefined
|
|
80
|
+
): Promise<AnonymousProfileResponse | undefined> {
|
|
72
81
|
try {
|
|
73
82
|
validatorService.validateProps(payload, CreateAnonymousProfileSchema);
|
|
74
83
|
|
|
@@ -80,13 +89,13 @@ async function createAnonymousProfile(
|
|
|
80
89
|
identifiers.push({ key: 'fingerprint', value: userFingerprintId });
|
|
81
90
|
if (distinctId) identifiers.push({ key: 'distinct_id', value: distinctId });
|
|
82
91
|
|
|
83
|
-
const dataPayload = getAnonymousProfilePayload(payload,identifiers);
|
|
84
|
-
|
|
92
|
+
const dataPayload = getAnonymousProfilePayload(payload, identifiers);
|
|
93
|
+
|
|
85
94
|
const result = await coreApi.createAnonymousProfile(dataPayload);
|
|
86
|
-
return result.data
|
|
95
|
+
return result.data;
|
|
87
96
|
} catch (error) {
|
|
88
97
|
console.error('Could not create anonymous profile:', error);
|
|
89
|
-
return undefined
|
|
98
|
+
return undefined;
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
101
|
|