rozmova-analytics 1.1.10 → 1.1.12
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/helpers.d.ts +2 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.esm.js +34 -7
- package/dist/index.js +34 -7
- package/dist/index.umd.js +3 -3
- package/package.json +1 -1
package/dist/helpers.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare function detectOS(): "Windows" | "macOS" | "Linux" | "Android" |
|
|
|
8
8
|
export declare const getDomain: () => string;
|
|
9
9
|
export declare const getReferrer: () => string | null;
|
|
10
10
|
export declare function getSearchQueryFromReferrer(): string | null;
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const getClientIdFromCookies: () => string;
|
|
12
|
+
export declare const getGAClientId: () => Promise<string>;
|
|
12
13
|
export declare function getGASessionId(): string | null;
|
|
13
14
|
export declare const getLocaleFromURL: (isClearly?: boolean) => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,15 +14,16 @@ declare class Analytics {
|
|
|
14
14
|
ga?: boolean;
|
|
15
15
|
mixpanel?: boolean;
|
|
16
16
|
customerIO?: boolean;
|
|
17
|
-
}): void
|
|
17
|
+
}): Promise<void>;
|
|
18
18
|
setUser(userId: string, userParams: {
|
|
19
19
|
email: string;
|
|
20
20
|
name: string;
|
|
21
21
|
numberOfSessions: number;
|
|
22
22
|
locale: string;
|
|
23
23
|
phone?: string;
|
|
24
|
+
isB2B?: boolean;
|
|
24
25
|
}): void;
|
|
25
|
-
getCommonParams(): AnalyticsCommonParams
|
|
26
|
+
getCommonParams(): Promise<AnalyticsCommonParams>;
|
|
26
27
|
setLocale(newLocale: string): void;
|
|
27
28
|
resetUser(): void;
|
|
28
29
|
getUserId: () => string;
|
package/dist/index.esm.js
CHANGED
|
@@ -12123,13 +12123,39 @@ function getSearchQueryFromReferrer() {
|
|
|
12123
12123
|
// If no match with search engines, return null
|
|
12124
12124
|
return null;
|
|
12125
12125
|
}
|
|
12126
|
-
const
|
|
12126
|
+
const getClientIdFromCookies = () => {
|
|
12127
12127
|
const clientId = api.get("_ga");
|
|
12128
12128
|
if (!clientId)
|
|
12129
12129
|
return "";
|
|
12130
12130
|
const splitedClientId = clientId.split(".");
|
|
12131
12131
|
return splitedClientId[2] + "." + splitedClientId[3];
|
|
12132
12132
|
};
|
|
12133
|
+
const getGAClientId = () => {
|
|
12134
|
+
return new Promise((resolve) => {
|
|
12135
|
+
if (typeof gtag !== "undefined") {
|
|
12136
|
+
try {
|
|
12137
|
+
gtag("get", GOOGLE_ANALYTICS_ID, "client_id", function (clientId) {
|
|
12138
|
+
if (clientId) {
|
|
12139
|
+
resolve(clientId);
|
|
12140
|
+
}
|
|
12141
|
+
else {
|
|
12142
|
+
resolve(getClientIdFromCookies());
|
|
12143
|
+
}
|
|
12144
|
+
});
|
|
12145
|
+
setTimeout(() => {
|
|
12146
|
+
resolve(getClientIdFromCookies());
|
|
12147
|
+
}, 1000);
|
|
12148
|
+
}
|
|
12149
|
+
catch (error) {
|
|
12150
|
+
console.warn("Error getting client ID from gtag:", error);
|
|
12151
|
+
resolve(getClientIdFromCookies());
|
|
12152
|
+
}
|
|
12153
|
+
}
|
|
12154
|
+
else {
|
|
12155
|
+
resolve(getClientIdFromCookies());
|
|
12156
|
+
}
|
|
12157
|
+
});
|
|
12158
|
+
};
|
|
12133
12159
|
function getGASessionId() {
|
|
12134
12160
|
const cookieValue = api.get("_ga_GYQLL028VQ");
|
|
12135
12161
|
if (!cookieValue)
|
|
@@ -12539,7 +12565,7 @@ class Analytics {
|
|
|
12539
12565
|
setUserTag(key, value) {
|
|
12540
12566
|
Clarity.setTag(key, value);
|
|
12541
12567
|
}
|
|
12542
|
-
trackEvent(eventName, properties, services = {
|
|
12568
|
+
async trackEvent(eventName, properties, services = {
|
|
12543
12569
|
ga: true,
|
|
12544
12570
|
mixpanel: true,
|
|
12545
12571
|
customerIO: true,
|
|
@@ -12548,7 +12574,7 @@ class Analytics {
|
|
|
12548
12574
|
this.dataLayer.push({ eventName, eventParams: properties });
|
|
12549
12575
|
return;
|
|
12550
12576
|
}
|
|
12551
|
-
const commonParams = this.getCommonParams();
|
|
12577
|
+
const commonParams = await this.getCommonParams();
|
|
12552
12578
|
const allParams = { ...commonParams, ...properties };
|
|
12553
12579
|
// Mixpanel
|
|
12554
12580
|
if (services.mixpanel) {
|
|
@@ -12597,10 +12623,10 @@ class Analytics {
|
|
|
12597
12623
|
console.warn("Analytics is not initialized.");
|
|
12598
12624
|
return;
|
|
12599
12625
|
}
|
|
12600
|
-
const { email, name, phone } = userParams;
|
|
12626
|
+
const { email, name, phone, isB2B } = userParams;
|
|
12601
12627
|
// Mixpanel user
|
|
12602
12628
|
mixpanel.identify(userId);
|
|
12603
|
-
mixpanel.people.set({ $email: email, name, phone });
|
|
12629
|
+
mixpanel.people.set({ $email: email, name, phone, isB2B });
|
|
12604
12630
|
// GA user
|
|
12605
12631
|
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12606
12632
|
user_properties: this.getCommonParams(),
|
|
@@ -12614,14 +12640,15 @@ class Analytics {
|
|
|
12614
12640
|
// login event
|
|
12615
12641
|
this.trackEvent("login", { logged: "yes", uid: userId });
|
|
12616
12642
|
}
|
|
12617
|
-
getCommonParams() {
|
|
12643
|
+
async getCommonParams() {
|
|
12618
12644
|
const persistedParams = getCurrentParams();
|
|
12645
|
+
const user_pseudo_id = await getGAClientId();
|
|
12619
12646
|
return {
|
|
12620
12647
|
...persistedParams,
|
|
12621
12648
|
fbc: api.get("_fbc"),
|
|
12622
12649
|
fbp: api.get("_fbp"),
|
|
12623
12650
|
session_id: getGASessionId(),
|
|
12624
|
-
user_pseudo_id
|
|
12651
|
+
user_pseudo_id,
|
|
12625
12652
|
rid: getUserId(),
|
|
12626
12653
|
funnel_name: api.get("funnel_name"),
|
|
12627
12654
|
language: getBrowserLanguage(),
|
package/dist/index.js
CHANGED
|
@@ -12125,13 +12125,39 @@ function getSearchQueryFromReferrer() {
|
|
|
12125
12125
|
// If no match with search engines, return null
|
|
12126
12126
|
return null;
|
|
12127
12127
|
}
|
|
12128
|
-
const
|
|
12128
|
+
const getClientIdFromCookies = () => {
|
|
12129
12129
|
const clientId = api.get("_ga");
|
|
12130
12130
|
if (!clientId)
|
|
12131
12131
|
return "";
|
|
12132
12132
|
const splitedClientId = clientId.split(".");
|
|
12133
12133
|
return splitedClientId[2] + "." + splitedClientId[3];
|
|
12134
12134
|
};
|
|
12135
|
+
const getGAClientId = () => {
|
|
12136
|
+
return new Promise((resolve) => {
|
|
12137
|
+
if (typeof gtag !== "undefined") {
|
|
12138
|
+
try {
|
|
12139
|
+
gtag("get", GOOGLE_ANALYTICS_ID, "client_id", function (clientId) {
|
|
12140
|
+
if (clientId) {
|
|
12141
|
+
resolve(clientId);
|
|
12142
|
+
}
|
|
12143
|
+
else {
|
|
12144
|
+
resolve(getClientIdFromCookies());
|
|
12145
|
+
}
|
|
12146
|
+
});
|
|
12147
|
+
setTimeout(() => {
|
|
12148
|
+
resolve(getClientIdFromCookies());
|
|
12149
|
+
}, 1000);
|
|
12150
|
+
}
|
|
12151
|
+
catch (error) {
|
|
12152
|
+
console.warn("Error getting client ID from gtag:", error);
|
|
12153
|
+
resolve(getClientIdFromCookies());
|
|
12154
|
+
}
|
|
12155
|
+
}
|
|
12156
|
+
else {
|
|
12157
|
+
resolve(getClientIdFromCookies());
|
|
12158
|
+
}
|
|
12159
|
+
});
|
|
12160
|
+
};
|
|
12135
12161
|
function getGASessionId() {
|
|
12136
12162
|
const cookieValue = api.get("_ga_GYQLL028VQ");
|
|
12137
12163
|
if (!cookieValue)
|
|
@@ -12541,7 +12567,7 @@ class Analytics {
|
|
|
12541
12567
|
setUserTag(key, value) {
|
|
12542
12568
|
Clarity.setTag(key, value);
|
|
12543
12569
|
}
|
|
12544
|
-
trackEvent(eventName, properties, services = {
|
|
12570
|
+
async trackEvent(eventName, properties, services = {
|
|
12545
12571
|
ga: true,
|
|
12546
12572
|
mixpanel: true,
|
|
12547
12573
|
customerIO: true,
|
|
@@ -12550,7 +12576,7 @@ class Analytics {
|
|
|
12550
12576
|
this.dataLayer.push({ eventName, eventParams: properties });
|
|
12551
12577
|
return;
|
|
12552
12578
|
}
|
|
12553
|
-
const commonParams = this.getCommonParams();
|
|
12579
|
+
const commonParams = await this.getCommonParams();
|
|
12554
12580
|
const allParams = { ...commonParams, ...properties };
|
|
12555
12581
|
// Mixpanel
|
|
12556
12582
|
if (services.mixpanel) {
|
|
@@ -12599,10 +12625,10 @@ class Analytics {
|
|
|
12599
12625
|
console.warn("Analytics is not initialized.");
|
|
12600
12626
|
return;
|
|
12601
12627
|
}
|
|
12602
|
-
const { email, name, phone } = userParams;
|
|
12628
|
+
const { email, name, phone, isB2B } = userParams;
|
|
12603
12629
|
// Mixpanel user
|
|
12604
12630
|
mixpanel.identify(userId);
|
|
12605
|
-
mixpanel.people.set({ $email: email, name, phone });
|
|
12631
|
+
mixpanel.people.set({ $email: email, name, phone, isB2B });
|
|
12606
12632
|
// GA user
|
|
12607
12633
|
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12608
12634
|
user_properties: this.getCommonParams(),
|
|
@@ -12616,14 +12642,15 @@ class Analytics {
|
|
|
12616
12642
|
// login event
|
|
12617
12643
|
this.trackEvent("login", { logged: "yes", uid: userId });
|
|
12618
12644
|
}
|
|
12619
|
-
getCommonParams() {
|
|
12645
|
+
async getCommonParams() {
|
|
12620
12646
|
const persistedParams = getCurrentParams();
|
|
12647
|
+
const user_pseudo_id = await getGAClientId();
|
|
12621
12648
|
return {
|
|
12622
12649
|
...persistedParams,
|
|
12623
12650
|
fbc: api.get("_fbc"),
|
|
12624
12651
|
fbp: api.get("_fbp"),
|
|
12625
12652
|
session_id: getGASessionId(),
|
|
12626
|
-
user_pseudo_id
|
|
12653
|
+
user_pseudo_id,
|
|
12627
12654
|
rid: getUserId(),
|
|
12628
12655
|
funnel_name: api.get("funnel_name"),
|
|
12629
12656
|
language: getBrowserLanguage(),
|