@reservamos/browser-analytics 1.0.0 → 1.0.2
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 +33 -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/src/track.ts +32 -0
|
@@ -13419,6 +13419,12 @@ const validatorService = {
|
|
|
13419
13419
|
validateProps
|
|
13420
13420
|
};
|
|
13421
13421
|
const FP_TRIGGER_EVENTS = ["Search", "View Results"];
|
|
13422
|
+
const EXTRA_UTM_FIELDS = {
|
|
13423
|
+
utm_brand: "UTM Brand",
|
|
13424
|
+
utm_kxconfig: "UTM KXConfig",
|
|
13425
|
+
gad_source: "GAD Source",
|
|
13426
|
+
gclid: "GCLID"
|
|
13427
|
+
};
|
|
13422
13428
|
function flattenEventData(data) {
|
|
13423
13429
|
return Object.entries(data).reduce((flattenedData, [key, value]) => {
|
|
13424
13430
|
if (!Array.isArray(value)) {
|
|
@@ -13458,10 +13464,12 @@ async function trackEvent(eventName, eventProperties, meta = {}) {
|
|
|
13458
13464
|
const defaultProperties = {
|
|
13459
13465
|
"User Fingerprint": fingerprint
|
|
13460
13466
|
};
|
|
13467
|
+
const trackingParams = extractTrackingParams();
|
|
13461
13468
|
const simplifiedData = flattenEventData(eventProperties);
|
|
13462
13469
|
const properties = {
|
|
13463
13470
|
...defaultProperties,
|
|
13464
13471
|
...simplifiedData,
|
|
13472
|
+
...trackingParams,
|
|
13465
13473
|
...meta
|
|
13466
13474
|
};
|
|
13467
13475
|
mixpanelService.track(eventName, properties);
|
|
@@ -13469,6 +13477,22 @@ async function trackEvent(eventName, eventProperties, meta = {}) {
|
|
|
13469
13477
|
console.error(`Error tracking event '${eventName}':`, error);
|
|
13470
13478
|
}
|
|
13471
13479
|
}
|
|
13480
|
+
function extractTrackingParams() {
|
|
13481
|
+
try {
|
|
13482
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
13483
|
+
const trackingData = {};
|
|
13484
|
+
Object.entries(EXTRA_UTM_FIELDS).forEach(([queryParam, displayName]) => {
|
|
13485
|
+
const value = urlParams.get(queryParam);
|
|
13486
|
+
if (value) {
|
|
13487
|
+
trackingData[displayName] = value;
|
|
13488
|
+
}
|
|
13489
|
+
});
|
|
13490
|
+
return trackingData;
|
|
13491
|
+
} catch (error) {
|
|
13492
|
+
console.error("Error extracting tracking parameters:", error);
|
|
13493
|
+
return {};
|
|
13494
|
+
}
|
|
13495
|
+
}
|
|
13472
13496
|
function trackCustomEvent(eventName, eventData = {}, meta = {}) {
|
|
13473
13497
|
try {
|
|
13474
13498
|
eventNameSchema.parse(eventName);
|
|
@@ -15961,7 +15985,14 @@ function getAnonymousProfilePayload(values, identifiersProps) {
|
|
|
15961
15985
|
identifier_key = "email";
|
|
15962
15986
|
identifier_value = values.email;
|
|
15963
15987
|
}
|
|
15964
|
-
const allowedKeys = [
|
|
15988
|
+
const allowedKeys = [
|
|
15989
|
+
"cpf",
|
|
15990
|
+
"passport",
|
|
15991
|
+
"rg",
|
|
15992
|
+
"email",
|
|
15993
|
+
"phone",
|
|
15994
|
+
"salesforceid"
|
|
15995
|
+
];
|
|
15965
15996
|
Object.entries(values).forEach(([key, value]) => {
|
|
15966
15997
|
if (allowedKeys.includes(key.toLowerCase()) && value) {
|
|
15967
15998
|
if (key !== identifier_key) {
|
|
@@ -15975,6 +16006,7 @@ function getAnonymousProfilePayload(values, identifiersProps) {
|
|
|
15975
16006
|
return {
|
|
15976
16007
|
identifier_key,
|
|
15977
16008
|
identifier_value,
|
|
16009
|
+
details: {},
|
|
15978
16010
|
identifiers
|
|
15979
16011
|
};
|
|
15980
16012
|
}
|