@reservamos/browser-analytics 1.1.8-alpha.2 → 1.1.8-alpha.3
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/CHANGELOG.md +4 -0
- package/README.md +7 -1
- package/dist/browser-analytics.cjs +2 -2
- package/dist/browser-analytics.cjs.map +1 -1
- package/dist/browser-analytics.d.ts +8 -8
- package/dist/browser-analytics.esm.js +308 -118
- package/dist/browser-analytics.esm.js.map +1 -1
- package/dist/browser-analytics.iife.js +2 -2
- package/dist/browser-analytics.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/events/identify/identify.recovery.test.ts +367 -0
- package/src/events/identify/identify.ts +5 -18
- package/src/init.ts +10 -1
- package/src/profiles/createAnonymousProfile/createAnonymousProfile.ts +18 -2
- package/src/services/mixpanel.batch.test.ts +108 -0
- package/src/services/mixpanel.ts +22 -5
- package/src/services/profileEnrichment.ts +258 -0
|
@@ -1059,35 +1059,35 @@ declare const CreateAnonymousProfileSchema: z.ZodEffects<z.ZodObject<{
|
|
|
1059
1059
|
}, "strip", z.ZodTypeAny, {
|
|
1060
1060
|
email?: string | undefined;
|
|
1061
1061
|
phone?: string | undefined;
|
|
1062
|
-
firstName?: string | undefined;
|
|
1063
|
-
lastName?: string | undefined;
|
|
1064
1062
|
cpf?: string | undefined;
|
|
1065
1063
|
passport?: string | undefined;
|
|
1066
1064
|
rg?: string | undefined;
|
|
1065
|
+
firstName?: string | undefined;
|
|
1066
|
+
lastName?: string | undefined;
|
|
1067
1067
|
}, {
|
|
1068
1068
|
email?: string | undefined;
|
|
1069
1069
|
phone?: string | undefined;
|
|
1070
|
-
firstName?: string | undefined;
|
|
1071
|
-
lastName?: string | undefined;
|
|
1072
1070
|
cpf?: string | undefined;
|
|
1073
1071
|
passport?: string | undefined;
|
|
1074
1072
|
rg?: string | undefined;
|
|
1073
|
+
firstName?: string | undefined;
|
|
1074
|
+
lastName?: string | undefined;
|
|
1075
1075
|
}>, {
|
|
1076
1076
|
email?: string | undefined;
|
|
1077
1077
|
phone?: string | undefined;
|
|
1078
|
-
firstName?: string | undefined;
|
|
1079
|
-
lastName?: string | undefined;
|
|
1080
1078
|
cpf?: string | undefined;
|
|
1081
1079
|
passport?: string | undefined;
|
|
1082
1080
|
rg?: string | undefined;
|
|
1081
|
+
firstName?: string | undefined;
|
|
1082
|
+
lastName?: string | undefined;
|
|
1083
1083
|
}, {
|
|
1084
1084
|
email?: string | undefined;
|
|
1085
1085
|
phone?: string | undefined;
|
|
1086
|
-
firstName?: string | undefined;
|
|
1087
|
-
lastName?: string | undefined;
|
|
1088
1086
|
cpf?: string | undefined;
|
|
1089
1087
|
passport?: string | undefined;
|
|
1090
1088
|
rg?: string | undefined;
|
|
1089
|
+
firstName?: string | undefined;
|
|
1090
|
+
lastName?: string | undefined;
|
|
1091
1091
|
}>;
|
|
1092
1092
|
export type CreateAnonymousProfileProps = z.infer<typeof CreateAnonymousProfileSchema>;
|
|
1093
1093
|
declare function createAnonymousProfile(payload: CreateAnonymousProfileProps): Promise<AnonymousProfile | undefined>;
|
|
@@ -13341,13 +13341,13 @@ function loadNoop(_src, onload) {
|
|
|
13341
13341
|
onload();
|
|
13342
13342
|
}
|
|
13343
13343
|
var mixpanel = init_as_module(loadNoop);
|
|
13344
|
-
let generation = 0;
|
|
13344
|
+
let generation$1 = 0;
|
|
13345
13345
|
let initialized = false;
|
|
13346
13346
|
let userId;
|
|
13347
13347
|
const subscribers = /* @__PURE__ */ new Set();
|
|
13348
13348
|
const initializationSubscribers = /* @__PURE__ */ new Set();
|
|
13349
13349
|
function invalidate$1() {
|
|
13350
|
-
generation++;
|
|
13350
|
+
generation$1++;
|
|
13351
13351
|
subscribers.forEach((notify) => notify());
|
|
13352
13352
|
}
|
|
13353
13353
|
function beginInitialization() {
|
|
@@ -13363,8 +13363,8 @@ function identify$2(nextUserId) {
|
|
|
13363
13363
|
}
|
|
13364
13364
|
}
|
|
13365
13365
|
function capture() {
|
|
13366
|
-
const captured = generation;
|
|
13367
|
-
return () => captured === generation;
|
|
13366
|
+
const captured = generation$1;
|
|
13367
|
+
return () => captured === generation$1;
|
|
13368
13368
|
}
|
|
13369
13369
|
function onChange(notify) {
|
|
13370
13370
|
subscribers.add(notify);
|
|
@@ -13473,7 +13473,7 @@ function observeIdentifyResult(stage, report, onTimeout) {
|
|
|
13473
13473
|
}, 5e3);
|
|
13474
13474
|
return { complete };
|
|
13475
13475
|
}
|
|
13476
|
-
const version = "1.1.8-alpha.
|
|
13476
|
+
const version = "1.1.8-alpha.3";
|
|
13477
13477
|
const MIXPANEL_DISTINCT_ID_CACHE_KEY = "mp_distinct_id";
|
|
13478
13478
|
const readinessSubscribers$1 = /* @__PURE__ */ new Set();
|
|
13479
13479
|
let initializing = false;
|
|
@@ -13503,6 +13503,7 @@ function init$2(mixpanelToken, debug = false, proxyUrl) {
|
|
|
13503
13503
|
return new Promise((resolve) => {
|
|
13504
13504
|
mixpanel.init(mixpanelToken, {
|
|
13505
13505
|
debug,
|
|
13506
|
+
batch_flush_interval_ms: 1e3,
|
|
13506
13507
|
loaded: () => {
|
|
13507
13508
|
if (attempt !== initialization$2) {
|
|
13508
13509
|
resolve();
|
|
@@ -13538,27 +13539,33 @@ function attachProperty(key, value) {
|
|
|
13538
13539
|
}
|
|
13539
13540
|
mixpanel.people.union(key, [value]);
|
|
13540
13541
|
}
|
|
13541
|
-
function setPeopleProperties(properties, report) {
|
|
13542
|
+
function setPeopleProperties(properties, report, onAccepted) {
|
|
13542
13543
|
if (!isReady()) {
|
|
13543
13544
|
return;
|
|
13544
13545
|
}
|
|
13545
|
-
writePeopleProperties(properties, report);
|
|
13546
|
+
writePeopleProperties(properties, report, onAccepted);
|
|
13547
|
+
}
|
|
13548
|
+
function restorePeopleProperties(userId2, properties, report, onAccepted) {
|
|
13549
|
+
if (!isReady() || mixpanel.get_distinct_id() !== userId2) return;
|
|
13550
|
+
mixpanel.identify(userId2);
|
|
13551
|
+
writePeopleProperties(properties, report, onAccepted);
|
|
13546
13552
|
}
|
|
13547
|
-
function writePeopleProperties(properties, report) {
|
|
13548
|
-
if (!report) {
|
|
13553
|
+
function writePeopleProperties(properties, report, onAccepted) {
|
|
13554
|
+
if (!report && !onAccepted) {
|
|
13549
13555
|
mixpanel.people.set(properties);
|
|
13550
13556
|
return;
|
|
13551
13557
|
}
|
|
13552
|
-
const observer = observeIdentifyResult("people", report);
|
|
13558
|
+
const observer = report ? observeIdentifyResult("people", report) : void 0;
|
|
13553
13559
|
try {
|
|
13554
13560
|
mixpanel.people.set(properties, (response) => {
|
|
13555
13561
|
const status = typeof response === "number" ? response : response == null ? void 0 : response.status;
|
|
13556
|
-
|
|
13562
|
+
if (status === 1) onAccepted == null ? void 0 : onAccepted();
|
|
13563
|
+
observer == null ? void 0 : observer.complete(
|
|
13557
13564
|
status === 1 ? void 0 : status === 0 ? "failed" : "unconfirmed"
|
|
13558
13565
|
);
|
|
13559
13566
|
});
|
|
13560
13567
|
} catch {
|
|
13561
|
-
observer.complete("failed");
|
|
13568
|
+
observer == null ? void 0 : observer.complete("failed");
|
|
13562
13569
|
}
|
|
13563
13570
|
}
|
|
13564
13571
|
function isReady() {
|
|
@@ -13599,6 +13606,7 @@ const mixpanelService = {
|
|
|
13599
13606
|
identify: identify$1,
|
|
13600
13607
|
attachProperty,
|
|
13601
13608
|
setPeopleProperties,
|
|
13609
|
+
restorePeopleProperties,
|
|
13602
13610
|
getMixpanelDistinctId
|
|
13603
13611
|
};
|
|
13604
13612
|
const DEFAULT_CACHE_NAME = "default_fingerprint_cache";
|
|
@@ -14415,11 +14423,285 @@ const validatorService = {
|
|
|
14415
14423
|
parseIdentifyProps,
|
|
14416
14424
|
validateProps
|
|
14417
14425
|
};
|
|
14426
|
+
function isCamelCase(word) {
|
|
14427
|
+
if (!word || word.includes(" ")) return false;
|
|
14428
|
+
if (word[0] !== word[0].toLowerCase()) return false;
|
|
14429
|
+
if (/[^a-zA-Z]/.test(word)) return false;
|
|
14430
|
+
if (!/[A-Z]/.test(word)) return false;
|
|
14431
|
+
return true;
|
|
14432
|
+
}
|
|
14433
|
+
const CreateAnonymousProfileSchema = z.object({
|
|
14434
|
+
email: z.string().email().optional(),
|
|
14435
|
+
phone: z.string().optional(),
|
|
14436
|
+
cpf: z.string().optional(),
|
|
14437
|
+
passport: z.string().optional(),
|
|
14438
|
+
rg: z.string().optional(),
|
|
14439
|
+
firstName: z.string().optional(),
|
|
14440
|
+
lastName: z.string().optional()
|
|
14441
|
+
}).refine((data) => data.email || data.phone, {
|
|
14442
|
+
message: "At least one of 'email' or 'phone' must be provided"
|
|
14443
|
+
});
|
|
14444
|
+
function getAnonymousProfilePayload(values, identifiersProps) {
|
|
14445
|
+
let identifier_key = "phone";
|
|
14446
|
+
let identifier_value = values.phone || "";
|
|
14447
|
+
const identifiers = [];
|
|
14448
|
+
const details = {};
|
|
14449
|
+
if (values.email) {
|
|
14450
|
+
identifier_key = "email";
|
|
14451
|
+
identifier_value = values.email;
|
|
14452
|
+
}
|
|
14453
|
+
const allowedKeys = [
|
|
14454
|
+
"cpf",
|
|
14455
|
+
"passport",
|
|
14456
|
+
"rg",
|
|
14457
|
+
"email",
|
|
14458
|
+
"phone",
|
|
14459
|
+
"salesforceid"
|
|
14460
|
+
];
|
|
14461
|
+
const allowedKeysDetails = ["name", "firstName", "lastName"];
|
|
14462
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
14463
|
+
key = isCamelCase(key) ? key : key.toLocaleLowerCase();
|
|
14464
|
+
if (allowedKeys.includes(key) && value) {
|
|
14465
|
+
if (key !== identifier_key) {
|
|
14466
|
+
identifiers.push({ key, value });
|
|
14467
|
+
}
|
|
14468
|
+
} else if (allowedKeysDetails.includes(key) && value) {
|
|
14469
|
+
details[key] = value;
|
|
14470
|
+
}
|
|
14471
|
+
});
|
|
14472
|
+
if (identifiersProps.length) {
|
|
14473
|
+
identifiersProps.forEach((item) => identifiers.push(item));
|
|
14474
|
+
}
|
|
14475
|
+
return {
|
|
14476
|
+
identifier_key,
|
|
14477
|
+
identifier_value,
|
|
14478
|
+
details,
|
|
14479
|
+
identifiers
|
|
14480
|
+
};
|
|
14481
|
+
}
|
|
14482
|
+
async function createAnonymousProfile(payload) {
|
|
14483
|
+
try {
|
|
14484
|
+
return await requestAnonymousProfile(payload);
|
|
14485
|
+
} catch (error) {
|
|
14486
|
+
console.error("Could not create anonymous profile:", error);
|
|
14487
|
+
return void 0;
|
|
14488
|
+
}
|
|
14489
|
+
}
|
|
14490
|
+
function createAnonymousProfileForIdentify(payload, report) {
|
|
14491
|
+
return requestAnonymousProfile(payload, report);
|
|
14492
|
+
}
|
|
14493
|
+
async function requestAnonymousProfile(payload, report) {
|
|
14494
|
+
return requestPreparedAnonymousProfile(
|
|
14495
|
+
prepareAnonymousProfileForIdentify(payload, report)
|
|
14496
|
+
);
|
|
14497
|
+
}
|
|
14498
|
+
function prepareAnonymousProfileForIdentify(payload, report) {
|
|
14499
|
+
validatorService.validateProps(payload, CreateAnonymousProfileSchema);
|
|
14500
|
+
const identifiers = [];
|
|
14501
|
+
const readIdentifier = (read2) => {
|
|
14502
|
+
if (!report) return read2();
|
|
14503
|
+
try {
|
|
14504
|
+
return read2();
|
|
14505
|
+
} catch {
|
|
14506
|
+
report("cache", "unavailable");
|
|
14507
|
+
return null;
|
|
14508
|
+
}
|
|
14509
|
+
};
|
|
14510
|
+
const userFingerprintId = readIdentifier(
|
|
14511
|
+
fingerprintService.getCachedFingerprint
|
|
14512
|
+
);
|
|
14513
|
+
const distinctId = readIdentifier(mixpanelService.getMixpanelDistinctId);
|
|
14514
|
+
if (userFingerprintId)
|
|
14515
|
+
identifiers.push({ key: "fingerprint", value: userFingerprintId });
|
|
14516
|
+
if (distinctId) identifiers.push({ key: "distinct_id", value: distinctId });
|
|
14517
|
+
return getAnonymousProfilePayload(payload, identifiers);
|
|
14518
|
+
}
|
|
14519
|
+
function requestPreparedAnonymousProfile(payload) {
|
|
14520
|
+
return a$1.profiles.createAnonymousProfile(payload);
|
|
14521
|
+
}
|
|
14522
|
+
const STORAGE_KEY = "reservamos_pending_profile_v1";
|
|
14523
|
+
const LIFETIME_MS = 10 * 60 * 1e3;
|
|
14524
|
+
const MAX_ATTEMPTS = 3;
|
|
14525
|
+
const MAX_BYTES = 4096;
|
|
14526
|
+
const profileIdSchema = z.union([
|
|
14527
|
+
z.string().min(1),
|
|
14528
|
+
z.number().int().positive()
|
|
14529
|
+
]);
|
|
14530
|
+
const requestSchema = z.object({
|
|
14531
|
+
identifier_key: z.enum(["email", "phone"]),
|
|
14532
|
+
identifier_value: z.string().min(1),
|
|
14533
|
+
identifiers: z.array(
|
|
14534
|
+
z.object({ key: z.string().min(1), value: z.string().min(1) }).strict()
|
|
14535
|
+
),
|
|
14536
|
+
details: z.record(z.string())
|
|
14537
|
+
}).strict();
|
|
14538
|
+
const pendingSchema = z.object({
|
|
14539
|
+
version: z.literal(1),
|
|
14540
|
+
id: z.string().min(1),
|
|
14541
|
+
userId: z.string().min(1),
|
|
14542
|
+
scope: z.string().min(1),
|
|
14543
|
+
expiresAt: z.number().int(),
|
|
14544
|
+
attempts: z.number().int().min(1).max(MAX_ATTEMPTS),
|
|
14545
|
+
request: requestSchema.optional(),
|
|
14546
|
+
profileId: profileIdSchema.optional()
|
|
14547
|
+
}).strict().refine((entry) => entry.request || entry.profileId);
|
|
14548
|
+
let scope;
|
|
14549
|
+
let generation = 0;
|
|
14550
|
+
function remove(report, id) {
|
|
14551
|
+
try {
|
|
14552
|
+
if (id) {
|
|
14553
|
+
const stored = JSON.parse(
|
|
14554
|
+
sessionStorage.getItem(STORAGE_KEY) || "null"
|
|
14555
|
+
);
|
|
14556
|
+
if ((stored == null ? void 0 : stored.id) !== id) return;
|
|
14557
|
+
}
|
|
14558
|
+
sessionStorage.removeItem(STORAGE_KEY);
|
|
14559
|
+
} catch {
|
|
14560
|
+
report("cache", "unavailable");
|
|
14561
|
+
}
|
|
14562
|
+
}
|
|
14563
|
+
function save(entry, report) {
|
|
14564
|
+
try {
|
|
14565
|
+
const serialized = JSON.stringify(entry);
|
|
14566
|
+
if (new Blob([serialized]).size > MAX_BYTES) {
|
|
14567
|
+
remove(report);
|
|
14568
|
+
report("cache", "unavailable");
|
|
14569
|
+
return false;
|
|
14570
|
+
}
|
|
14571
|
+
sessionStorage.setItem(STORAGE_KEY, serialized);
|
|
14572
|
+
return true;
|
|
14573
|
+
} catch {
|
|
14574
|
+
remove(report);
|
|
14575
|
+
report("cache", "unavailable");
|
|
14576
|
+
return false;
|
|
14577
|
+
}
|
|
14578
|
+
}
|
|
14579
|
+
function read(report) {
|
|
14580
|
+
try {
|
|
14581
|
+
const serialized = sessionStorage.getItem(STORAGE_KEY);
|
|
14582
|
+
if (!serialized) return void 0;
|
|
14583
|
+
if (new Blob([serialized]).size > MAX_BYTES) throw new Error();
|
|
14584
|
+
const entry = pendingSchema.parse(JSON.parse(serialized));
|
|
14585
|
+
if (entry.expiresAt <= Date.now() || entry.expiresAt > Date.now() + LIFETIME_MS) {
|
|
14586
|
+
remove(report);
|
|
14587
|
+
return void 0;
|
|
14588
|
+
}
|
|
14589
|
+
return entry;
|
|
14590
|
+
} catch {
|
|
14591
|
+
remove(report);
|
|
14592
|
+
report("cache", "unavailable");
|
|
14593
|
+
return void 0;
|
|
14594
|
+
}
|
|
14595
|
+
}
|
|
14596
|
+
function currentUserIs(userId2) {
|
|
14597
|
+
return mixpanelService.isReady() && mixpanelService.getMixpanelDistinctId() === userId2;
|
|
14598
|
+
}
|
|
14599
|
+
async function resolveProfile(userId2, properties, isCurrent, report, entry, recovering = false) {
|
|
14600
|
+
if (!isCurrent()) return void 0;
|
|
14601
|
+
const profile = (entry == null ? void 0 : entry.profileId) !== void 0 ? { id: entry.profileId } : await waitForIdentifyStage(
|
|
14602
|
+
"profile",
|
|
14603
|
+
3e3,
|
|
14604
|
+
(context) => isCurrent() ? (entry == null ? void 0 : entry.request) ? requestPreparedAnonymousProfile(entry.request) : createAnonymousProfileForIdentify(
|
|
14605
|
+
{ ...properties },
|
|
14606
|
+
context.report
|
|
14607
|
+
) : Promise.resolve(void 0),
|
|
14608
|
+
report
|
|
14609
|
+
);
|
|
14610
|
+
if (!isCurrent()) return void 0;
|
|
14611
|
+
if (!profile) {
|
|
14612
|
+
if (entry && entry.attempts >= MAX_ATTEMPTS) remove(report, entry.id);
|
|
14613
|
+
return void 0;
|
|
14614
|
+
}
|
|
14615
|
+
const parsedId = profileIdSchema.safeParse(profile.id);
|
|
14616
|
+
if (!parsedId.success) {
|
|
14617
|
+
report("profile", "failed");
|
|
14618
|
+
return void 0;
|
|
14619
|
+
}
|
|
14620
|
+
const profileId = parsedId.data;
|
|
14621
|
+
if (entry) save({ ...entry, request: void 0, profileId }, report);
|
|
14622
|
+
const accepted = () => {
|
|
14623
|
+
if (entry && isCurrent()) remove(report, entry.id);
|
|
14624
|
+
};
|
|
14625
|
+
try {
|
|
14626
|
+
const properties2 = { reservamos_one_id: profileId };
|
|
14627
|
+
if (recovering) {
|
|
14628
|
+
mixpanelService.restorePeopleProperties(
|
|
14629
|
+
userId2,
|
|
14630
|
+
properties2,
|
|
14631
|
+
report,
|
|
14632
|
+
accepted
|
|
14633
|
+
);
|
|
14634
|
+
} else if (entry) {
|
|
14635
|
+
mixpanelService.setPeopleProperties(properties2, report, accepted);
|
|
14636
|
+
} else {
|
|
14637
|
+
mixpanelService.setPeopleProperties(properties2, report);
|
|
14638
|
+
}
|
|
14639
|
+
} catch {
|
|
14640
|
+
report("profile", "failed");
|
|
14641
|
+
}
|
|
14642
|
+
return { id: profileId };
|
|
14643
|
+
}
|
|
14644
|
+
function enrich(userId2, properties, isActive, report) {
|
|
14645
|
+
if (!isActive()) return Promise.resolve(void 0);
|
|
14646
|
+
const attempt = ++generation;
|
|
14647
|
+
let request;
|
|
14648
|
+
if (scope) {
|
|
14649
|
+
try {
|
|
14650
|
+
const prepared = requestSchema.safeParse(
|
|
14651
|
+
prepareAnonymousProfileForIdentify({ ...properties }, report)
|
|
14652
|
+
);
|
|
14653
|
+
if (prepared.success) request = prepared.data;
|
|
14654
|
+
} catch {
|
|
14655
|
+
}
|
|
14656
|
+
}
|
|
14657
|
+
const entry = scope && request ? {
|
|
14658
|
+
version: 1,
|
|
14659
|
+
id: `${Date.now()}-${Math.random()}`,
|
|
14660
|
+
userId: userId2,
|
|
14661
|
+
scope,
|
|
14662
|
+
expiresAt: Date.now() + LIFETIME_MS,
|
|
14663
|
+
attempts: 1,
|
|
14664
|
+
request
|
|
14665
|
+
} : void 0;
|
|
14666
|
+
if (entry) save(entry, report);
|
|
14667
|
+
else if (scope) remove(report);
|
|
14668
|
+
const isCurrent = () => attempt === generation && isActive() && (!entry || Date.now() < entry.expiresAt) && (!scope || currentUserIs(userId2));
|
|
14669
|
+
return resolveProfile(userId2, properties, isCurrent, report, entry);
|
|
14670
|
+
}
|
|
14671
|
+
function initialize(configuration) {
|
|
14672
|
+
scope = JSON.stringify([
|
|
14673
|
+
configuration.project,
|
|
14674
|
+
configuration.proxy ?? "",
|
|
14675
|
+
configuration.apiBaseUrl,
|
|
14676
|
+
configuration.appName ?? ""
|
|
14677
|
+
]);
|
|
14678
|
+
const attempt = ++generation;
|
|
14679
|
+
const report = createIdentifyReporter();
|
|
14680
|
+
const entry = read(report);
|
|
14681
|
+
if (!entry) return;
|
|
14682
|
+
if (entry.scope !== scope || !currentUserIs(entry.userId) || entry.profileId === void 0 && entry.attempts >= MAX_ATTEMPTS) {
|
|
14683
|
+
remove(report, entry.id);
|
|
14684
|
+
return;
|
|
14685
|
+
}
|
|
14686
|
+
const lifecycle = trackingLifecycle.capture();
|
|
14687
|
+
const isCurrent = () => attempt === generation && lifecycle() && Date.now() < entry.expiresAt && currentUserIs(entry.userId);
|
|
14688
|
+
const resumed = {
|
|
14689
|
+
...entry,
|
|
14690
|
+
attempts: entry.attempts + (entry.profileId === void 0 ? 1 : 0)
|
|
14691
|
+
};
|
|
14692
|
+
if (entry.profileId === void 0 && !save(resumed, report)) return;
|
|
14693
|
+
const scopedReport = (...args) => {
|
|
14694
|
+
if (isCurrent()) report(...args);
|
|
14695
|
+
};
|
|
14696
|
+
void resolveProfile(entry.userId, {}, isCurrent, scopedReport, resumed, true);
|
|
14697
|
+
}
|
|
14698
|
+
const profileEnrichment = { enrich, initialize };
|
|
14418
14699
|
let initialization = 0;
|
|
14419
14700
|
function onLoaded() {
|
|
14420
14701
|
window.dispatchEvent(new CustomEvent("Tracker Ready"));
|
|
14421
14702
|
}
|
|
14422
14703
|
async function init$1(config) {
|
|
14704
|
+
var _a;
|
|
14423
14705
|
validatorService.parseInitProps(config);
|
|
14424
14706
|
const {
|
|
14425
14707
|
mixpanelToken,
|
|
@@ -14439,9 +14721,16 @@ async function init$1(config) {
|
|
|
14439
14721
|
if (appName2) {
|
|
14440
14722
|
configService.setAppName(appName2);
|
|
14441
14723
|
}
|
|
14442
|
-
|
|
14724
|
+
const coreConfig = configService.getCoreAPIConfig();
|
|
14725
|
+
a$1.setConfig(coreConfig);
|
|
14443
14726
|
onLoaded();
|
|
14444
14727
|
if (!isCurrent()) return;
|
|
14728
|
+
profileEnrichment.initialize({
|
|
14729
|
+
project: mixpanelToken,
|
|
14730
|
+
proxy: mixpanelProxyUrl,
|
|
14731
|
+
apiBaseUrl: coreConfig.baseUrl,
|
|
14732
|
+
appName: (_a = coreConfig.defaultHeaders) == null ? void 0 : _a["x-app-name"]
|
|
14733
|
+
});
|
|
14445
14734
|
await Promise.all([
|
|
14446
14735
|
initializeOptionalStage(
|
|
14447
14736
|
"fingerprint",
|
|
@@ -14456,7 +14745,7 @@ async function init$1(config) {
|
|
|
14456
14745
|
)
|
|
14457
14746
|
]);
|
|
14458
14747
|
}
|
|
14459
|
-
function initializeOptionalStage(stage,
|
|
14748
|
+
function initializeOptionalStage(stage, initialize2) {
|
|
14460
14749
|
return new Promise((resolve) => {
|
|
14461
14750
|
let active = true;
|
|
14462
14751
|
const finish = (reason) => {
|
|
@@ -14468,7 +14757,7 @@ function initializeOptionalStage(stage, initialize) {
|
|
|
14468
14757
|
resolve();
|
|
14469
14758
|
};
|
|
14470
14759
|
const timer = setTimeout(() => finish("timeout"), 3e3);
|
|
14471
|
-
void Promise.resolve().then(
|
|
14760
|
+
void Promise.resolve().then(initialize2).then(
|
|
14472
14761
|
() => finish(),
|
|
14473
14762
|
() => finish("failed")
|
|
14474
14763
|
);
|
|
@@ -14956,95 +15245,6 @@ function trackCustomEvent(eventName, eventData = {}, meta = {}) {
|
|
|
14956
15245
|
trackEventError(eventName, error, eventData);
|
|
14957
15246
|
}
|
|
14958
15247
|
}
|
|
14959
|
-
function isCamelCase(word) {
|
|
14960
|
-
if (!word || word.includes(" ")) return false;
|
|
14961
|
-
if (word[0] !== word[0].toLowerCase()) return false;
|
|
14962
|
-
if (/[^a-zA-Z]/.test(word)) return false;
|
|
14963
|
-
if (!/[A-Z]/.test(word)) return false;
|
|
14964
|
-
return true;
|
|
14965
|
-
}
|
|
14966
|
-
const CreateAnonymousProfileSchema = z.object({
|
|
14967
|
-
email: z.string().email().optional(),
|
|
14968
|
-
phone: z.string().optional(),
|
|
14969
|
-
cpf: z.string().optional(),
|
|
14970
|
-
passport: z.string().optional(),
|
|
14971
|
-
rg: z.string().optional(),
|
|
14972
|
-
firstName: z.string().optional(),
|
|
14973
|
-
lastName: z.string().optional()
|
|
14974
|
-
}).refine((data) => data.email || data.phone, {
|
|
14975
|
-
message: "At least one of 'email' or 'phone' must be provided"
|
|
14976
|
-
});
|
|
14977
|
-
function getAnonymousProfilePayload(values, identifiersProps) {
|
|
14978
|
-
let identifier_key = "phone";
|
|
14979
|
-
let identifier_value = values.phone || "";
|
|
14980
|
-
const identifiers = [];
|
|
14981
|
-
const details = {};
|
|
14982
|
-
if (values.email) {
|
|
14983
|
-
identifier_key = "email";
|
|
14984
|
-
identifier_value = values.email;
|
|
14985
|
-
}
|
|
14986
|
-
const allowedKeys = [
|
|
14987
|
-
"cpf",
|
|
14988
|
-
"passport",
|
|
14989
|
-
"rg",
|
|
14990
|
-
"email",
|
|
14991
|
-
"phone",
|
|
14992
|
-
"salesforceid"
|
|
14993
|
-
];
|
|
14994
|
-
const allowedKeysDetails = ["name", "firstName", "lastName"];
|
|
14995
|
-
Object.entries(values).forEach(([key, value]) => {
|
|
14996
|
-
key = isCamelCase(key) ? key : key.toLocaleLowerCase();
|
|
14997
|
-
if (allowedKeys.includes(key) && value) {
|
|
14998
|
-
if (key !== identifier_key) {
|
|
14999
|
-
identifiers.push({ key, value });
|
|
15000
|
-
}
|
|
15001
|
-
} else if (allowedKeysDetails.includes(key) && value) {
|
|
15002
|
-
details[key] = value;
|
|
15003
|
-
}
|
|
15004
|
-
});
|
|
15005
|
-
if (identifiersProps.length) {
|
|
15006
|
-
identifiersProps.forEach((item) => identifiers.push(item));
|
|
15007
|
-
}
|
|
15008
|
-
return {
|
|
15009
|
-
identifier_key,
|
|
15010
|
-
identifier_value,
|
|
15011
|
-
details,
|
|
15012
|
-
identifiers
|
|
15013
|
-
};
|
|
15014
|
-
}
|
|
15015
|
-
async function createAnonymousProfile(payload) {
|
|
15016
|
-
try {
|
|
15017
|
-
return await requestAnonymousProfile(payload);
|
|
15018
|
-
} catch (error) {
|
|
15019
|
-
console.error("Could not create anonymous profile:", error);
|
|
15020
|
-
return void 0;
|
|
15021
|
-
}
|
|
15022
|
-
}
|
|
15023
|
-
function createAnonymousProfileForIdentify(payload, report) {
|
|
15024
|
-
return requestAnonymousProfile(payload, report);
|
|
15025
|
-
}
|
|
15026
|
-
async function requestAnonymousProfile(payload, report) {
|
|
15027
|
-
validatorService.validateProps(payload, CreateAnonymousProfileSchema);
|
|
15028
|
-
const identifiers = [];
|
|
15029
|
-
const readIdentifier = (read) => {
|
|
15030
|
-
if (!report) return read();
|
|
15031
|
-
try {
|
|
15032
|
-
return read();
|
|
15033
|
-
} catch {
|
|
15034
|
-
report("cache", "unavailable");
|
|
15035
|
-
return null;
|
|
15036
|
-
}
|
|
15037
|
-
};
|
|
15038
|
-
const userFingerprintId = readIdentifier(
|
|
15039
|
-
fingerprintService.getCachedFingerprint
|
|
15040
|
-
);
|
|
15041
|
-
const distinctId = readIdentifier(mixpanelService.getMixpanelDistinctId);
|
|
15042
|
-
if (userFingerprintId)
|
|
15043
|
-
identifiers.push({ key: "fingerprint", value: userFingerprintId });
|
|
15044
|
-
if (distinctId) identifiers.push({ key: "distinct_id", value: distinctId });
|
|
15045
|
-
const dataPayload = getAnonymousProfilePayload(payload, identifiers);
|
|
15046
|
-
return await a$1.profiles.createAnonymousProfile(dataPayload);
|
|
15047
|
-
}
|
|
15048
15248
|
const KNOWN_PROPERTIES = ["firstName", "lastName", "email", "phone"];
|
|
15049
15249
|
const FINGERPRINT_PROPERTY = "Known Fingerprints";
|
|
15050
15250
|
let latestAttempt = 0;
|
|
@@ -15118,10 +15318,10 @@ const identifyWithLocation = async (userId2, properties, report) => {
|
|
|
15118
15318
|
}
|
|
15119
15319
|
};
|
|
15120
15320
|
async function enrichProfileAndLocation(userId2, properties, isActive, report) {
|
|
15121
|
-
const profile = await
|
|
15122
|
-
|
|
15123
|
-
|
|
15124
|
-
|
|
15321
|
+
const profile = await profileEnrichment.enrich(
|
|
15322
|
+
userId2,
|
|
15323
|
+
properties,
|
|
15324
|
+
isActive,
|
|
15125
15325
|
report
|
|
15126
15326
|
);
|
|
15127
15327
|
if (!isActive()) return;
|
|
@@ -15129,16 +15329,6 @@ async function enrichProfileAndLocation(userId2, properties, isActive, report) {
|
|
|
15129
15329
|
...properties,
|
|
15130
15330
|
...profile && { reservamos_one_id: profile.id }
|
|
15131
15331
|
};
|
|
15132
|
-
if (profile) {
|
|
15133
|
-
try {
|
|
15134
|
-
mixpanelService.setPeopleProperties(
|
|
15135
|
-
{ reservamos_one_id: profile.id },
|
|
15136
|
-
report
|
|
15137
|
-
);
|
|
15138
|
-
} catch {
|
|
15139
|
-
report("profile", "failed");
|
|
15140
|
-
}
|
|
15141
|
-
}
|
|
15142
15332
|
void identifyWithLocation(userId2, enriched, report);
|
|
15143
15333
|
}
|
|
15144
15334
|
async function enrichFingerprint(isActive, report) {
|