rozmova-analytics 1.1.31 → 1.1.33

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.
@@ -2,11 +2,7 @@ import { EventParams } from "./types";
2
2
  export declare function insertCustomerIOScript(): void;
3
3
  export declare const generateUserId: () => string;
4
4
  export declare const getUserId: () => string;
5
- export declare const getCurrentParams: () => {
6
- referrer: any;
7
- search_query: any;
8
- landing_page_url: any;
9
- };
5
+ export declare const getCurrentParams: () => any;
10
6
  export declare const storeGeoParam: () => void;
11
7
  export declare const initialLoginEvent: (trackEvent: (eventName: string, properties?: EventParams, services?: {
12
8
  ga?: boolean;
@@ -19,3 +15,7 @@ export declare const resetProfileId: () => void;
19
15
  export declare const setProfileEmail: (email: string) => void;
20
16
  export declare const getProfileEmail: () => string | undefined;
21
17
  export declare const resetProfileEmail: () => void;
18
+ export declare const getLastListNameAndIndex: () => {
19
+ listName: string | null;
20
+ index: string | null;
21
+ };
@@ -9,3 +9,4 @@ export declare const CLARITY_ID = "irbqmnlbwz";
9
9
  export declare const SUPPORTED_LANGUAGES: string[];
10
10
  export declare const GA_ECOMMERCE_EVENTS: string[];
11
11
  export declare const INTERNAL_USER_EMAILS: string[];
12
+ export declare const CREATE_THERAPY_PAGE_PLACEMENT_KEY = "createTherapyPlacementPage";
package/dist/helpers.d.ts CHANGED
@@ -15,3 +15,6 @@ export declare const setGAClientId: (clientId: string) => void;
15
15
  export declare const getLocaleFromURL: (isClearly?: boolean) => string;
16
16
  export declare const getUserType: (email?: string) => "external" | "internal";
17
17
  export declare function shallowEqual(obj1: Record<string, unknown>, obj2: Record<string, unknown>): boolean;
18
+ export declare function toNumberValue(value: number | string | null): number | null;
19
+ export declare function b64EncodeUnicode(str: string): string;
20
+ export declare const getAPIEndpoint: (isProd: boolean, endpoint: string) => string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AnalyticsCommonParams, EventParams } from "./types";
1
+ import { AnalyticsCommonParams, EventParams, UserAttributionProperties } from "./types";
2
2
  type GConfig = {
3
3
  userId?: string;
4
4
  email?: string;
@@ -7,9 +7,11 @@ declare class Analytics {
7
7
  private initialized;
8
8
  private locale;
9
9
  private platform;
10
+ private isProd;
10
11
  private dataLayer;
11
12
  private lastGConfig;
12
- init({ locale, platform, isClearly, config, }?: {
13
+ init({ isProd, locale, platform, isClearly, config, }?: {
14
+ isProd?: boolean;
13
15
  locale?: string;
14
16
  platform?: string;
15
17
  isClearly?: boolean;
@@ -40,6 +42,8 @@ declare class Analytics {
40
42
  setLocale(newLocale: string): void;
41
43
  resetUser(): void;
42
44
  getUserId: () => string;
45
+ getAttributionProperties(): Promise<UserAttributionProperties>;
46
+ trackFirstPartyEvent(eventName: string, properties?: EventParams): Promise<Response>;
43
47
  }
44
48
  declare const _default: Analytics;
45
49
  export default _default;
package/dist/index.esm.js CHANGED
@@ -12007,6 +12007,7 @@ const INTERNAL_USER_EMAILS = [
12007
12007
  "clearly.help",
12008
12008
  "uptech.team",
12009
12009
  ];
12010
+ const CREATE_THERAPY_PAGE_PLACEMENT_KEY = "createTherapyPlacementPage";
12010
12011
 
12011
12012
  const setQueryParam = (name, value) => {
12012
12013
  const url = new URL(window.location.href);
@@ -12212,6 +12213,21 @@ function shallowEqual(obj1, obj2) {
12212
12213
  return false;
12213
12214
  return keys1.every((key) => obj1[key] === obj2[key]);
12214
12215
  }
12216
+ function toNumberValue(value) {
12217
+ const num = Number(value);
12218
+ return isNaN(num) ? null : num;
12219
+ }
12220
+ function b64EncodeUnicode(str) {
12221
+ return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
12222
+ return String.fromCharCode(parseInt(p1, 16));
12223
+ }));
12224
+ }
12225
+ const getAPIEndpoint = (isProd, endpoint) => {
12226
+ const baseURL = isProd
12227
+ ? "https://trp.rozmova.me"
12228
+ : "https://stage.trp.rozmova.me";
12229
+ return baseURL + endpoint;
12230
+ };
12215
12231
 
12216
12232
  function insertCustomerIOScript() {
12217
12233
  const scriptContent = `
@@ -12275,17 +12291,87 @@ const getUserId = () => {
12275
12291
  api.get(USER_ID_KEY) ||
12276
12292
  generateUserId());
12277
12293
  };
12294
+ const getUTMParam = (paramName, searchParams, referrer) => {
12295
+ const gclid = searchParams.get("gclid");
12296
+ const wbraid = searchParams.get("wbraid");
12297
+ const gbraid = searchParams.get("gbraid");
12298
+ const source = searchParams.get("utm_source");
12299
+ const medium = searchParams.get("utm_medium");
12300
+ function getSource() {
12301
+ if (gclid || wbraid || gbraid)
12302
+ return "google";
12303
+ if (source)
12304
+ return source;
12305
+ if (medium)
12306
+ return "(none)";
12307
+ if (gclid || wbraid || gbraid)
12308
+ return "google";
12309
+ if (referrer) {
12310
+ if (referrer.includes("google."))
12311
+ return "google";
12312
+ if (referrer.includes("bing."))
12313
+ return "bing";
12314
+ if (referrer.includes("yahoo."))
12315
+ return "yahoo";
12316
+ if (referrer.includes("baidu."))
12317
+ return "baidu";
12318
+ if (referrer.includes("duckduckgo."))
12319
+ return "duckduckgo";
12320
+ if (referrer.includes("googlesyndication.com"))
12321
+ return "google";
12322
+ if (referrer.includes("facebook."))
12323
+ return "facebook";
12324
+ if (referrer.includes("instagram."))
12325
+ return "instagram";
12326
+ if (/linkedin\.|lnkd\./.test(referrer))
12327
+ return "linkedin";
12328
+ return referrer;
12329
+ }
12330
+ return null;
12331
+ }
12332
+ function getMedium() {
12333
+ if (gclid || wbraid || gbraid)
12334
+ return "cpc";
12335
+ if (medium)
12336
+ return medium;
12337
+ if (source)
12338
+ return "(none)";
12339
+ if (referrer) {
12340
+ if (/google\.|bing\.|duckduckgo\.|yahoo\.|baidu\./.test(referrer))
12341
+ return "organic";
12342
+ if (referrer.includes("googlesyndication.com"))
12343
+ return "cpc";
12344
+ if (referrer.includes("facebook."))
12345
+ return "referral";
12346
+ if (referrer.includes("instagram."))
12347
+ return "referral";
12348
+ if (/linkedin\.|lnkd\./.test(referrer))
12349
+ return "referral";
12350
+ return "referral";
12351
+ }
12352
+ return null;
12353
+ }
12354
+ if (paramName === "utm_source") {
12355
+ return getSource();
12356
+ }
12357
+ if (paramName === "utm_medium") {
12358
+ return getMedium();
12359
+ }
12360
+ return searchParams.get(paramName);
12361
+ };
12278
12362
  const getCurrentParams = () => {
12279
12363
  const paramsFromCookie = api.get(PARAMS_COOKIE_NAME);
12280
12364
  const prevParams = paramsFromCookie ? JSON.parse(paramsFromCookie) : {};
12281
12365
  const searchParams = new URLSearchParams(window.location.search);
12282
12366
  const referrer = getReferrer();
12283
- const isNewSetUTM = referrer ||
12284
- UTM_KEYS.some((utmKey) => searchParams.get(utmKey) &&
12285
- searchParams.get(utmKey) !== prevParams[utmKey]);
12286
- const currentUTMParams = isNewSetUTM
12287
- ? UTM_KEYS.reduce((prev, curr) => ({ ...prev, [curr]: searchParams.get(curr) }), {})
12288
- : UTM_KEYS.reduce((prev, curr) => ({ ...prev, [curr]: prevParams[curr] }), {});
12367
+ const params = UTM_KEYS.reduce((prev, curr) => ({
12368
+ ...prev,
12369
+ [curr]: getUTMParam(curr, searchParams, referrer),
12370
+ }), {});
12371
+ const isNewSetUTM = UTM_KEYS.some((utmKey) => {
12372
+ return params[utmKey] && params[utmKey] !== prevParams[utmKey];
12373
+ });
12374
+ const currentUTMParams = isNewSetUTM ? params : prevParams;
12289
12375
  const currentParams = {
12290
12376
  ...currentUTMParams,
12291
12377
  referrer: referrer || prevParams.referrer,
@@ -12341,6 +12427,12 @@ const resetProfileEmail = () => {
12341
12427
  const domain = getDomain();
12342
12428
  api.remove(PROFILE_EMAIL_KEY, { domain });
12343
12429
  };
12430
+ const getLastListNameAndIndex = () => {
12431
+ return {
12432
+ listName: localStorage.getItem("listName"),
12433
+ index: localStorage.getItem("index"),
12434
+ };
12435
+ };
12344
12436
 
12345
12437
  /*!
12346
12438
  * CookieConsent 3.0.1
@@ -12567,15 +12659,18 @@ class Analytics {
12567
12659
  initialized = false;
12568
12660
  locale = "uk";
12569
12661
  platform = "web";
12662
+ isProd = true;
12570
12663
  dataLayer = [];
12571
12664
  lastGConfig = {};
12572
- async init({ locale, platform, isClearly, config, } = {}) {
12665
+ async init({ isProd, locale, platform, isClearly, config, } = {}) {
12573
12666
  insertCustomerIOScript();
12574
12667
  storeGeoParam();
12575
12668
  const userId = getUserId();
12576
12669
  if (isMetaBrowser()) {
12577
12670
  setQueryParam(USER_ID_KEY, userId);
12578
12671
  }
12672
+ if (typeof isProd === "boolean")
12673
+ this.isProd = isProd;
12579
12674
  if (locale)
12580
12675
  this.locale = locale;
12581
12676
  else
@@ -12768,6 +12863,58 @@ class Analytics {
12768
12863
  this.init();
12769
12864
  }
12770
12865
  getUserId = getUserId;
12866
+ async getAttributionProperties() {
12867
+ const paramsFromCookie = this.getCommonParams();
12868
+ const { listName, index } = getLastListNameAndIndex();
12869
+ const placement = localStorage.getItem(CREATE_THERAPY_PAGE_PLACEMENT_KEY);
12870
+ const gaClientId = await this.getGAClientId();
12871
+ return {
12872
+ funnelInfo: {
12873
+ funnelName: paramsFromCookie.funnel_name,
12874
+ funnelType: null,
12875
+ listName,
12876
+ platform: this.platform,
12877
+ index: toNumberValue(index),
12878
+ placement,
12879
+ },
12880
+ trackingParams: {
12881
+ source: paramsFromCookie.utm_source,
12882
+ medium: paramsFromCookie.utm_medium,
12883
+ advertiserId: paramsFromCookie.utm_advertiser_id,
12884
+ campaignId: paramsFromCookie.utm_campaign_id,
12885
+ campaignName: paramsFromCookie.utm_campaign,
12886
+ adsetId: paramsFromCookie.utm_adset_id,
12887
+ adId: paramsFromCookie.utm_ad_id,
12888
+ adName: paramsFromCookie.utm_ad_name,
12889
+ keyword: paramsFromCookie.utm_keyword,
12890
+ searchQuery: paramsFromCookie.search_query,
12891
+ referrer: paramsFromCookie.referrer,
12892
+ landingPageUrl: paramsFromCookie.landing_page_url,
12893
+ },
12894
+ externalAnalyticsUserInfo: {
12895
+ gaClientId,
12896
+ gaSessionId: paramsFromCookie.session_id,
12897
+ rid: getUserId(),
12898
+ fbp: paramsFromCookie.fbp,
12899
+ fbc: paramsFromCookie.fbc,
12900
+ },
12901
+ };
12902
+ }
12903
+ async trackFirstPartyEvent(eventName, properties) {
12904
+ const attributionProperties = await this.getAttributionProperties();
12905
+ const attributionJSON = JSON.stringify(attributionProperties);
12906
+ const attributionJSONbase64 = b64EncodeUnicode(attributionJSON);
12907
+ const headers = new Headers({
12908
+ "X-Attribution": attributionJSONbase64,
12909
+ "Content-Type": "application/json",
12910
+ });
12911
+ const endpoint = getAPIEndpoint(this.isProd, "/api/analytics/track");
12912
+ return await fetch(endpoint, {
12913
+ body: JSON.stringify({ eventName, eventParams: properties }),
12914
+ method: "POST",
12915
+ headers,
12916
+ });
12917
+ }
12771
12918
  }
12772
12919
  var index = new Analytics();
12773
12920
 
package/dist/index.js CHANGED
@@ -12009,6 +12009,7 @@ const INTERNAL_USER_EMAILS = [
12009
12009
  "clearly.help",
12010
12010
  "uptech.team",
12011
12011
  ];
12012
+ const CREATE_THERAPY_PAGE_PLACEMENT_KEY = "createTherapyPlacementPage";
12012
12013
 
12013
12014
  const setQueryParam = (name, value) => {
12014
12015
  const url = new URL(window.location.href);
@@ -12214,6 +12215,21 @@ function shallowEqual(obj1, obj2) {
12214
12215
  return false;
12215
12216
  return keys1.every((key) => obj1[key] === obj2[key]);
12216
12217
  }
12218
+ function toNumberValue(value) {
12219
+ const num = Number(value);
12220
+ return isNaN(num) ? null : num;
12221
+ }
12222
+ function b64EncodeUnicode(str) {
12223
+ return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
12224
+ return String.fromCharCode(parseInt(p1, 16));
12225
+ }));
12226
+ }
12227
+ const getAPIEndpoint = (isProd, endpoint) => {
12228
+ const baseURL = isProd
12229
+ ? "https://trp.rozmova.me"
12230
+ : "https://stage.trp.rozmova.me";
12231
+ return baseURL + endpoint;
12232
+ };
12217
12233
 
12218
12234
  function insertCustomerIOScript() {
12219
12235
  const scriptContent = `
@@ -12277,17 +12293,87 @@ const getUserId = () => {
12277
12293
  api.get(USER_ID_KEY) ||
12278
12294
  generateUserId());
12279
12295
  };
12296
+ const getUTMParam = (paramName, searchParams, referrer) => {
12297
+ const gclid = searchParams.get("gclid");
12298
+ const wbraid = searchParams.get("wbraid");
12299
+ const gbraid = searchParams.get("gbraid");
12300
+ const source = searchParams.get("utm_source");
12301
+ const medium = searchParams.get("utm_medium");
12302
+ function getSource() {
12303
+ if (gclid || wbraid || gbraid)
12304
+ return "google";
12305
+ if (source)
12306
+ return source;
12307
+ if (medium)
12308
+ return "(none)";
12309
+ if (gclid || wbraid || gbraid)
12310
+ return "google";
12311
+ if (referrer) {
12312
+ if (referrer.includes("google."))
12313
+ return "google";
12314
+ if (referrer.includes("bing."))
12315
+ return "bing";
12316
+ if (referrer.includes("yahoo."))
12317
+ return "yahoo";
12318
+ if (referrer.includes("baidu."))
12319
+ return "baidu";
12320
+ if (referrer.includes("duckduckgo."))
12321
+ return "duckduckgo";
12322
+ if (referrer.includes("googlesyndication.com"))
12323
+ return "google";
12324
+ if (referrer.includes("facebook."))
12325
+ return "facebook";
12326
+ if (referrer.includes("instagram."))
12327
+ return "instagram";
12328
+ if (/linkedin\.|lnkd\./.test(referrer))
12329
+ return "linkedin";
12330
+ return referrer;
12331
+ }
12332
+ return null;
12333
+ }
12334
+ function getMedium() {
12335
+ if (gclid || wbraid || gbraid)
12336
+ return "cpc";
12337
+ if (medium)
12338
+ return medium;
12339
+ if (source)
12340
+ return "(none)";
12341
+ if (referrer) {
12342
+ if (/google\.|bing\.|duckduckgo\.|yahoo\.|baidu\./.test(referrer))
12343
+ return "organic";
12344
+ if (referrer.includes("googlesyndication.com"))
12345
+ return "cpc";
12346
+ if (referrer.includes("facebook."))
12347
+ return "referral";
12348
+ if (referrer.includes("instagram."))
12349
+ return "referral";
12350
+ if (/linkedin\.|lnkd\./.test(referrer))
12351
+ return "referral";
12352
+ return "referral";
12353
+ }
12354
+ return null;
12355
+ }
12356
+ if (paramName === "utm_source") {
12357
+ return getSource();
12358
+ }
12359
+ if (paramName === "utm_medium") {
12360
+ return getMedium();
12361
+ }
12362
+ return searchParams.get(paramName);
12363
+ };
12280
12364
  const getCurrentParams = () => {
12281
12365
  const paramsFromCookie = api.get(PARAMS_COOKIE_NAME);
12282
12366
  const prevParams = paramsFromCookie ? JSON.parse(paramsFromCookie) : {};
12283
12367
  const searchParams = new URLSearchParams(window.location.search);
12284
12368
  const referrer = getReferrer();
12285
- const isNewSetUTM = referrer ||
12286
- UTM_KEYS.some((utmKey) => searchParams.get(utmKey) &&
12287
- searchParams.get(utmKey) !== prevParams[utmKey]);
12288
- const currentUTMParams = isNewSetUTM
12289
- ? UTM_KEYS.reduce((prev, curr) => ({ ...prev, [curr]: searchParams.get(curr) }), {})
12290
- : UTM_KEYS.reduce((prev, curr) => ({ ...prev, [curr]: prevParams[curr] }), {});
12369
+ const params = UTM_KEYS.reduce((prev, curr) => ({
12370
+ ...prev,
12371
+ [curr]: getUTMParam(curr, searchParams, referrer),
12372
+ }), {});
12373
+ const isNewSetUTM = UTM_KEYS.some((utmKey) => {
12374
+ return params[utmKey] && params[utmKey] !== prevParams[utmKey];
12375
+ });
12376
+ const currentUTMParams = isNewSetUTM ? params : prevParams;
12291
12377
  const currentParams = {
12292
12378
  ...currentUTMParams,
12293
12379
  referrer: referrer || prevParams.referrer,
@@ -12343,6 +12429,12 @@ const resetProfileEmail = () => {
12343
12429
  const domain = getDomain();
12344
12430
  api.remove(PROFILE_EMAIL_KEY, { domain });
12345
12431
  };
12432
+ const getLastListNameAndIndex = () => {
12433
+ return {
12434
+ listName: localStorage.getItem("listName"),
12435
+ index: localStorage.getItem("index"),
12436
+ };
12437
+ };
12346
12438
 
12347
12439
  /*!
12348
12440
  * CookieConsent 3.0.1
@@ -12569,15 +12661,18 @@ class Analytics {
12569
12661
  initialized = false;
12570
12662
  locale = "uk";
12571
12663
  platform = "web";
12664
+ isProd = true;
12572
12665
  dataLayer = [];
12573
12666
  lastGConfig = {};
12574
- async init({ locale, platform, isClearly, config, } = {}) {
12667
+ async init({ isProd, locale, platform, isClearly, config, } = {}) {
12575
12668
  insertCustomerIOScript();
12576
12669
  storeGeoParam();
12577
12670
  const userId = getUserId();
12578
12671
  if (isMetaBrowser()) {
12579
12672
  setQueryParam(USER_ID_KEY, userId);
12580
12673
  }
12674
+ if (typeof isProd === "boolean")
12675
+ this.isProd = isProd;
12581
12676
  if (locale)
12582
12677
  this.locale = locale;
12583
12678
  else
@@ -12770,6 +12865,58 @@ class Analytics {
12770
12865
  this.init();
12771
12866
  }
12772
12867
  getUserId = getUserId;
12868
+ async getAttributionProperties() {
12869
+ const paramsFromCookie = this.getCommonParams();
12870
+ const { listName, index } = getLastListNameAndIndex();
12871
+ const placement = localStorage.getItem(CREATE_THERAPY_PAGE_PLACEMENT_KEY);
12872
+ const gaClientId = await this.getGAClientId();
12873
+ return {
12874
+ funnelInfo: {
12875
+ funnelName: paramsFromCookie.funnel_name,
12876
+ funnelType: null,
12877
+ listName,
12878
+ platform: this.platform,
12879
+ index: toNumberValue(index),
12880
+ placement,
12881
+ },
12882
+ trackingParams: {
12883
+ source: paramsFromCookie.utm_source,
12884
+ medium: paramsFromCookie.utm_medium,
12885
+ advertiserId: paramsFromCookie.utm_advertiser_id,
12886
+ campaignId: paramsFromCookie.utm_campaign_id,
12887
+ campaignName: paramsFromCookie.utm_campaign,
12888
+ adsetId: paramsFromCookie.utm_adset_id,
12889
+ adId: paramsFromCookie.utm_ad_id,
12890
+ adName: paramsFromCookie.utm_ad_name,
12891
+ keyword: paramsFromCookie.utm_keyword,
12892
+ searchQuery: paramsFromCookie.search_query,
12893
+ referrer: paramsFromCookie.referrer,
12894
+ landingPageUrl: paramsFromCookie.landing_page_url,
12895
+ },
12896
+ externalAnalyticsUserInfo: {
12897
+ gaClientId,
12898
+ gaSessionId: paramsFromCookie.session_id,
12899
+ rid: getUserId(),
12900
+ fbp: paramsFromCookie.fbp,
12901
+ fbc: paramsFromCookie.fbc,
12902
+ },
12903
+ };
12904
+ }
12905
+ async trackFirstPartyEvent(eventName, properties) {
12906
+ const attributionProperties = await this.getAttributionProperties();
12907
+ const attributionJSON = JSON.stringify(attributionProperties);
12908
+ const attributionJSONbase64 = b64EncodeUnicode(attributionJSON);
12909
+ const headers = new Headers({
12910
+ "X-Attribution": attributionJSONbase64,
12911
+ "Content-Type": "application/json",
12912
+ });
12913
+ const endpoint = getAPIEndpoint(this.isProd, "/api/analytics/track");
12914
+ return await fetch(endpoint, {
12915
+ body: JSON.stringify({ eventName, eventParams: properties }),
12916
+ method: "POST",
12917
+ headers,
12918
+ });
12919
+ }
12773
12920
  }
12774
12921
  var index = new Analytics();
12775
12922