rozmova-analytics 1.1.18 → 1.1.20

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 CHANGED
@@ -13,3 +13,4 @@ export declare const getGAClientId: () => Promise<string>;
13
13
  export declare function getGASessionId(): string | null;
14
14
  export declare const getLocaleFromURL: (isClearly?: boolean) => string;
15
15
  export declare const getUserType: (email?: string) => "external" | "internal";
16
+ export declare function shallowEqual(obj1: Record<string, unknown>, obj2: Record<string, unknown>): boolean;
package/dist/index.d.ts CHANGED
@@ -1,16 +1,10 @@
1
1
  import { AnalyticsCommonParams, EventParams } from "./types";
2
- type GConfig = {
3
- userId?: string;
4
- email?: string;
5
- locale?: string;
6
- };
7
2
  declare class Analytics {
8
3
  private initialized;
9
4
  private locale;
10
5
  private platform;
11
6
  private dataLayer;
12
7
  private lastGConfig;
13
- isInitialized(): boolean;
14
8
  init({ locale, platform, isClearly, }?: {
15
9
  locale?: string;
16
10
  platform?: string;
@@ -23,8 +17,7 @@ declare class Analytics {
23
17
  mixpanel?: boolean;
24
18
  customerIO?: boolean;
25
19
  }): Promise<void>;
26
- setConfig(params?: GConfig): void;
27
- getLastGConfig(): GConfig;
20
+ private setConfig;
28
21
  trackPageView({ referrer }?: {
29
22
  referrer?: string;
30
23
  }): void;
package/dist/index.esm.js CHANGED
@@ -12189,6 +12189,13 @@ const getUserType = (email) => {
12189
12189
  const isInternal = INTERNAL_USER_EMAILS.some((internalEmail) => email.includes(internalEmail));
12190
12190
  return isInternal ? "internal" : "external";
12191
12191
  };
12192
+ function shallowEqual(obj1, obj2) {
12193
+ const keys1 = Object.keys(obj1);
12194
+ const keys2 = Object.keys(obj2);
12195
+ if (keys1.length !== keys2.length)
12196
+ return false;
12197
+ return keys1.every((key) => obj1[key] === obj2[key]);
12198
+ }
12192
12199
 
12193
12200
  function insertCustomerIOScript() {
12194
12201
  const scriptContent = `
@@ -12544,12 +12551,7 @@ class Analytics {
12544
12551
  platform = "web";
12545
12552
  dataLayer = [];
12546
12553
  lastGConfig = {};
12547
- isInitialized() {
12548
- return this.initialized;
12549
- }
12550
12554
  async init({ locale, platform, isClearly, } = {}) {
12551
- if (this.initialized)
12552
- return;
12553
12555
  insertCustomerIOScript();
12554
12556
  storeGeoParam();
12555
12557
  const userId = getUserId();
@@ -12571,10 +12573,10 @@ class Analytics {
12571
12573
  });
12572
12574
  // init microsoft clarity
12573
12575
  Clarity.init(CLARITY_ID);
12574
- const userProperties = await this.getCommonParams();
12575
- mixpanel.register(userProperties);
12576
12576
  this.setConfig();
12577
12577
  this.trackPageView();
12578
+ const userProperties = await this.getCommonParams();
12579
+ mixpanel.register(userProperties);
12578
12580
  // gtag("config", GOOGLE_ANALYTICS_ID, {
12579
12581
  // user_properties: userProperties,
12580
12582
  // server_container_url: GA_SERVER_CONTAINER_URL,
@@ -12656,14 +12658,15 @@ class Analytics {
12656
12658
  setConfig(params = {
12657
12659
  userId: getProfileId(),
12658
12660
  email: getProfileEmail(),
12659
- locale: this.locale,
12660
12661
  }) {
12662
+ if (shallowEqual(params, this.lastGConfig))
12663
+ return;
12661
12664
  this.lastGConfig = params;
12662
- const { userId, email, locale } = params;
12665
+ const { userId, email } = params;
12663
12666
  const eventParams = {
12664
12667
  user_id: userId,
12665
12668
  is_logged: userId ? "yes" : "no",
12666
- locale: locale,
12669
+ locale: this.locale,
12667
12670
  platform: this.platform,
12668
12671
  user_type: getUserType(email),
12669
12672
  };
@@ -12673,9 +12676,6 @@ class Analytics {
12673
12676
  ...eventParams,
12674
12677
  });
12675
12678
  }
12676
- getLastGConfig() {
12677
- return this.lastGConfig;
12678
- }
12679
12679
  trackPageView({ referrer } = {}) {
12680
12680
  const eventParams = {
12681
12681
  page_title: document.title,
@@ -12689,11 +12689,9 @@ class Analytics {
12689
12689
  });
12690
12690
  }
12691
12691
  setUser(userId, userParams) {
12692
- if (!this.initialized) {
12693
- console.warn("Analytics is not initialized.");
12694
- return;
12695
- }
12696
12692
  const { email, name, phone, isB2B } = userParams;
12693
+ // Update config
12694
+ this.setConfig({ userId, email });
12697
12695
  // Mixpanel user
12698
12696
  mixpanel.identify(userId);
12699
12697
  mixpanel.people.set({ $email: email, name, phone, isB2B });
@@ -12738,14 +12736,11 @@ class Analytics {
12738
12736
  this.locale = newLocale;
12739
12737
  }
12740
12738
  resetUser() {
12741
- if (!this.initialized) {
12742
- console.warn("Analytics is not initialized.");
12743
- return;
12744
- }
12745
12739
  mixpanel.reset();
12746
12740
  window.analytics.reset();
12747
12741
  resetProfileId();
12748
12742
  resetProfileEmail();
12743
+ this.setConfig();
12749
12744
  this.trackEvent("login", { logged: "no" });
12750
12745
  generateUserId();
12751
12746
  this.init();
package/dist/index.js CHANGED
@@ -12191,6 +12191,13 @@ const getUserType = (email) => {
12191
12191
  const isInternal = INTERNAL_USER_EMAILS.some((internalEmail) => email.includes(internalEmail));
12192
12192
  return isInternal ? "internal" : "external";
12193
12193
  };
12194
+ function shallowEqual(obj1, obj2) {
12195
+ const keys1 = Object.keys(obj1);
12196
+ const keys2 = Object.keys(obj2);
12197
+ if (keys1.length !== keys2.length)
12198
+ return false;
12199
+ return keys1.every((key) => obj1[key] === obj2[key]);
12200
+ }
12194
12201
 
12195
12202
  function insertCustomerIOScript() {
12196
12203
  const scriptContent = `
@@ -12546,12 +12553,7 @@ class Analytics {
12546
12553
  platform = "web";
12547
12554
  dataLayer = [];
12548
12555
  lastGConfig = {};
12549
- isInitialized() {
12550
- return this.initialized;
12551
- }
12552
12556
  async init({ locale, platform, isClearly, } = {}) {
12553
- if (this.initialized)
12554
- return;
12555
12557
  insertCustomerIOScript();
12556
12558
  storeGeoParam();
12557
12559
  const userId = getUserId();
@@ -12573,10 +12575,10 @@ class Analytics {
12573
12575
  });
12574
12576
  // init microsoft clarity
12575
12577
  Clarity.init(CLARITY_ID);
12576
- const userProperties = await this.getCommonParams();
12577
- mixpanel.register(userProperties);
12578
12578
  this.setConfig();
12579
12579
  this.trackPageView();
12580
+ const userProperties = await this.getCommonParams();
12581
+ mixpanel.register(userProperties);
12580
12582
  // gtag("config", GOOGLE_ANALYTICS_ID, {
12581
12583
  // user_properties: userProperties,
12582
12584
  // server_container_url: GA_SERVER_CONTAINER_URL,
@@ -12658,14 +12660,15 @@ class Analytics {
12658
12660
  setConfig(params = {
12659
12661
  userId: getProfileId(),
12660
12662
  email: getProfileEmail(),
12661
- locale: this.locale,
12662
12663
  }) {
12664
+ if (shallowEqual(params, this.lastGConfig))
12665
+ return;
12663
12666
  this.lastGConfig = params;
12664
- const { userId, email, locale } = params;
12667
+ const { userId, email } = params;
12665
12668
  const eventParams = {
12666
12669
  user_id: userId,
12667
12670
  is_logged: userId ? "yes" : "no",
12668
- locale: locale,
12671
+ locale: this.locale,
12669
12672
  platform: this.platform,
12670
12673
  user_type: getUserType(email),
12671
12674
  };
@@ -12675,9 +12678,6 @@ class Analytics {
12675
12678
  ...eventParams,
12676
12679
  });
12677
12680
  }
12678
- getLastGConfig() {
12679
- return this.lastGConfig;
12680
- }
12681
12681
  trackPageView({ referrer } = {}) {
12682
12682
  const eventParams = {
12683
12683
  page_title: document.title,
@@ -12691,11 +12691,9 @@ class Analytics {
12691
12691
  });
12692
12692
  }
12693
12693
  setUser(userId, userParams) {
12694
- if (!this.initialized) {
12695
- console.warn("Analytics is not initialized.");
12696
- return;
12697
- }
12698
12694
  const { email, name, phone, isB2B } = userParams;
12695
+ // Update config
12696
+ this.setConfig({ userId, email });
12699
12697
  // Mixpanel user
12700
12698
  mixpanel.identify(userId);
12701
12699
  mixpanel.people.set({ $email: email, name, phone, isB2B });
@@ -12740,14 +12738,11 @@ class Analytics {
12740
12738
  this.locale = newLocale;
12741
12739
  }
12742
12740
  resetUser() {
12743
- if (!this.initialized) {
12744
- console.warn("Analytics is not initialized.");
12745
- return;
12746
- }
12747
12741
  mixpanel.reset();
12748
12742
  window.analytics.reset();
12749
12743
  resetProfileId();
12750
12744
  resetProfileEmail();
12745
+ this.setConfig();
12751
12746
  this.trackEvent("login", { logged: "no" });
12752
12747
  generateUserId();
12753
12748
  this.init();