rozmova-analytics 1.1.12 → 1.1.14

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm-version](https://img.shields.io/npm/v/rozmova-analytics.svg)](https://www.npmjs.com/package/rozmova-analytics)
4
4
  [![minified-size](https://img.shields.io/bundlephobia/minzip/rozmova-analytics@1.0.7)](https://bundlephobia.com/package/rozmova-analytics)
5
5
 
6
- A lightweight JavaScript analytics library designed to streamline event tracking, user identification, and common analytics parameter management. This package integrates with Mixpanel and Google Analytics to provide seamless data collection and insights.
6
+ A lightweight JavaScript analytics library designed to streamline event tracking, user identification, and common analytics parameter management. This package integrates with Mixpanel, Google Analytics, Customer.io, and Microsoft Clarity to provide seamless data collection and insights.
7
7
 
8
8
  ## Installation
9
9
 
@@ -15,7 +15,7 @@ npm install rozmova-analytics
15
15
 
16
16
  Alternatively, you can include the library via jsDelivr to use in browser:
17
17
 
18
- ```bash
18
+ ```html
19
19
  <script src="https://cdn.jsdelivr.net/npm/rozmova-analytics/dist/index.umd.js"></script>
20
20
  ```
21
21
 
@@ -24,25 +24,23 @@ Alternatively, you can include the library via jsDelivr to use in browser:
24
24
  Import the library in your project and initialize it:
25
25
 
26
26
  ```javascript
27
- import {
28
- generateUserId,
29
- getCommonParams,
30
- getUserId,
31
- init,
32
- resetUser,
33
- setUser,
34
- trackEvent,
35
- setLocale,
36
- } from "rozmova-analytics";
27
+ import Analytics from "rozmova-analytics";
37
28
 
38
29
  // Initialize the library
39
- init({ locale: "en", platform: "web", isClearly: true });
30
+ Analytics.init({ locale: "en", platform: "web", isClearly: true });
40
31
 
41
32
  // Set user
42
- setUser("user-id-123", { email: "user@example.com", name: "John Doe" });
33
+ Analytics.setUser("user-id-123", {
34
+ email: "user@example.com",
35
+ name: "John Doe",
36
+ numberOfSessions: 5,
37
+ locale: "en",
38
+ phone: "+1234567890",
39
+ isB2B: false
40
+ });
43
41
 
44
42
  // Track an event
45
- trackEvent("button_click", { button_name: "Sign Up" });
43
+ Analytics.trackEvent("button_click", { button_name: "Sign Up" });
46
44
  ```
47
45
 
48
46
  Or use in browser:
@@ -55,77 +53,325 @@ window.Analytics.init({ locale: "en", platform: "web" });
55
53
  window.Analytics.setUser("user-id-123", {
56
54
  email: "user@example.com",
57
55
  name: "John Doe",
56
+ numberOfSessions: 1,
57
+ locale: "en"
58
58
  });
59
59
 
60
60
  // Track an event
61
61
  window.Analytics.trackEvent("button_click", { button_name: "Sign Up" });
62
62
  ```
63
63
 
64
- ## API
64
+ ## API Reference
65
65
 
66
- ### `init(initParams:{locale?: string, platform?: string})`
66
+ ### `init(config?)`
67
67
 
68
- Initializes the analytics library, setting up Mixpanel and Google Analytics integrations. Optionally, set a locale and platform.
68
+ Initializes the analytics library, setting up Mixpanel, Google Analytics, Customer.io, and Microsoft Clarity integrations.
69
69
 
70
- ### `generateUserId()`
70
+ **Parameters:**
71
+ - `config.locale?: string` - The locale for analytics data (default: auto-detected or "uk")
72
+ - `config.platform?: string` - The platform identifier (default: "web")
73
+ - `config.isClearly?: boolean` - Whether to enable Clearly-specific features like cookie consent banner
71
74
 
72
- Generates a unique user ID, stores it in cookies and localStorage, and returns the ID.
75
+ **Example:**
76
+ ```javascript
77
+ Analytics.init({
78
+ locale: "en",
79
+ platform: "web",
80
+ isClearly: true
81
+ });
82
+ ```
73
83
 
74
- ### `getUserId()`
84
+ ### `trackEvent(eventName, properties?, services?)`
75
85
 
76
- Retrieves the user ID from cookies, localStorage, or URL query parameters. If not found, generates a new one.
86
+ Tracks an event across the specified analytics providers.
77
87
 
78
- ### `getCommonParams()`
88
+ **Parameters:**
89
+ - `eventName: string` - The name of the event to track
90
+ - `properties?: EventParams` - Additional event properties (optional)
91
+ - `services?: object` - Which services to track to (optional, default: all enabled)
92
+ - `ga?: boolean` - Google Analytics (default: true)
93
+ - `mixpanel?: boolean` - Mixpanel (default: true)
94
+ - `customerIO?: boolean` - Customer.io (default: true)
79
95
 
80
- Returns an object with common analytics parameters such as device, browser, referrer, and UTM parameters.
96
+ **Example:**
97
+ ```javascript
98
+ // Track to all services
99
+ Analytics.trackEvent("purchase", {
100
+ product_id: "123",
101
+ price: 29.99,
102
+ currency: "USD"
103
+ });
81
104
 
82
- ### `setLocale(newLocale: string)`
105
+ // Track to specific services only
106
+ Analytics.trackEvent("newsletter_signup", {
107
+ source: "footer"
108
+ }, {
109
+ ga: true,
110
+ mixpanel: false,
111
+ customerIO: true
112
+ });
113
+ ```
114
+
115
+ ### `setUser(userId, userParams)`
83
116
 
84
- Sets the locale for analytics data.
117
+ Associates a user with the provided user ID and sets user properties across all analytics providers.
85
118
 
86
- ### `setUser(userId: string, userParams: { email: string; name: string })`
119
+ **Parameters:**
120
+ - `userId: string` - Unique user identifier
121
+ - `userParams: object` - User properties
122
+ - `email: string` - User's email address
123
+ - `name: string` - User's full name
124
+ - `numberOfSessions: number` - Number of user sessions
125
+ - `locale: string` - User's locale
126
+ - `phone?: string` - User's phone number (optional)
127
+ - `isB2B?: boolean` - Whether the user is a business user (optional)
87
128
 
88
- Associates a user with the provided user ID and sets user properties in Mixpanel and Google Analytics.
129
+ **Example:**
130
+ ```javascript
131
+ Analytics.setUser("user-456", {
132
+ email: "jane@example.com",
133
+ name: "Jane Doe",
134
+ numberOfSessions: 3,
135
+ locale: "en",
136
+ phone: "+1234567890",
137
+ isB2B: true
138
+ });
139
+ ```
89
140
 
90
141
  ### `resetUser()`
91
142
 
92
- Resets the current user, generating a new user ID and reinitializing the library.
143
+ Resets the current user across all analytics providers, clears stored user data, generates a new user ID, and reinitializes the library.
144
+
145
+ **Example:**
146
+ ```javascript
147
+ Analytics.resetUser();
148
+ ```
149
+
150
+ ### `setUserTag(key, value)`
151
+
152
+ Sets a user tag in Microsoft Clarity for enhanced user identification and session analysis.
153
+
154
+ **Parameters:**
155
+ - `key: string` - The tag key
156
+ - `value: string` - The tag value
157
+
158
+ **Example:**
159
+ ```javascript
160
+ Analytics.setUserTag("user_type", "premium");
161
+ Analytics.setUserTag("subscription_plan", "pro");
162
+ ```
163
+
164
+ ### `setConfig(params?)`
165
+
166
+ Updates the analytics configuration with new parameters.
167
+
168
+ **Parameters:**
169
+ - `params.userId?: string` - User ID to set
170
+ - `params.email?: string` - User email to set
171
+ - `params.locale?: string` - Locale to set
172
+
173
+ **Example:**
174
+ ```javascript
175
+ Analytics.setConfig({
176
+ userId: "new-user-id",
177
+ locale: "fr"
178
+ });
179
+ ```
180
+
181
+ ### `setLocale(newLocale)`
182
+
183
+ Updates the locale for analytics data.
184
+
185
+ **Parameters:**
186
+ - `newLocale: string` - The new locale to set
187
+
188
+ **Example:**
189
+ ```javascript
190
+ Analytics.setLocale("es");
191
+ ```
192
+
193
+ ### `trackPageView()`
194
+
195
+ Tracks a page view event with current page information including title, location, and referrer.
196
+
197
+ **Example:**
198
+ ```javascript
199
+ Analytics.trackPageView();
200
+ ```
201
+
202
+ ### `getCommonParams()`
93
203
 
94
- ### `trackEvent(eventName: string, properties?: EventParams, services = {ga: true, mixpanel: true, customerIO: true})`
204
+ Returns a promise that resolves to an object with common analytics parameters including device information, browser details, UTM parameters, user data, and session information.
95
205
 
96
- Tracks an event with the specified name and optional properties, services.
206
+ **Returns:** `Promise<AnalyticsCommonParams>`
207
+
208
+ **Example:**
209
+ ```javascript
210
+ const params = await Analytics.getCommonParams();
211
+ console.log(params.device, params.browser, params.locale);
212
+ ```
213
+
214
+ ### `getUserId()`
215
+
216
+ Retrieves the current user ID from cookies, localStorage, or URL query parameters. Generates a new one if not found.
217
+
218
+ **Returns:** `string`
219
+
220
+ **Example:**
221
+ ```javascript
222
+ const userId = Analytics.getUserId();
223
+ ```
224
+
225
+ ## Analytics Providers
226
+
227
+ The library integrates with multiple analytics providers out of the box:
228
+
229
+ ### Mixpanel
230
+ - Event tracking with custom properties
231
+ - User identification and profile management
232
+ - Automatic page view tracking
233
+ - User property registration
234
+
235
+ ### Google Analytics 4
236
+ - Event tracking with enhanced ecommerce support
237
+ - User identification with custom user properties
238
+ - Server-side container support
239
+ - Automatic ecommerce event handling
240
+
241
+ ### Customer.io
242
+ - Behavioral event tracking
243
+ - User identification and profile management
244
+ - Automated messaging and email triggers
245
+
246
+ ### Microsoft Clarity
247
+ - Session recording and heatmaps
248
+ - User tagging for enhanced insights
249
+ - Automatic session tracking
250
+
251
+ ## Features
252
+
253
+ ### Event Queuing
254
+ Events tracked before initialization are queued and processed once the library is ready.
255
+
256
+ ### Error Handling
257
+ Individual service failures don't affect other providers - the library includes comprehensive error handling.
258
+
259
+ ### Cookie Consent
260
+ Automatic cookie consent banner integration for GDPR compliance when `isClearly` is enabled.
261
+
262
+ ### Meta Browser Detection
263
+ Special handling for Meta (Facebook) browsers with automatic URL parameter tracking.
264
+
265
+ ### Geo Parameter Storage
266
+ Automatic storage and tracking of geographic parameters.
267
+
268
+ ### Session Management
269
+ Comprehensive session tracking with Google Analytics session IDs and user pseudo IDs.
97
270
 
98
271
  ## Browser Support
99
272
 
100
- The package works on modern browsers and supports the following:
273
+ The package works on modern browsers and supports:
101
274
 
102
- - Chrome
103
- - Firefox
104
- - Safari
105
- - Edge
275
+ - Chrome (latest)
276
+ - Firefox (latest)
277
+ - Safari (latest)
278
+ - Edge (latest)
106
279
 
107
280
  ## Example Integration
108
281
 
109
282
  ```javascript
110
- import { init, trackEvent, setUser, resetUser } from "rozmova-analytics";
283
+ import Analytics from "rozmova-analytics";
111
284
 
112
285
  // Initialize analytics
113
- init({ locale: "en", platform: "ios", isClearly: true });
286
+ Analytics.init({
287
+ locale: "en",
288
+ platform: "web",
289
+ isClearly: true
290
+ });
114
291
 
115
- // Track a page view event
116
- trackEvent("page_view", { page: "Home" });
292
+ // Track a page view (automatically called during init)
293
+ Analytics.trackPageView();
117
294
 
118
295
  // Set user details
119
- setUser("user-456", { email: "user456@example.com", name: "Jane Doe" });
296
+ Analytics.setUser("user-456", {
297
+ email: "user456@example.com",
298
+ name: "Jane Doe",
299
+ numberOfSessions: 1,
300
+ locale: "en",
301
+ phone: "+1234567890",
302
+ isB2B: false
303
+ });
304
+
305
+ // Track custom events
306
+ Analytics.trackEvent("feature_used", {
307
+ feature_name: "advanced_search",
308
+ user_tier: "premium"
309
+ });
310
+
311
+ // Set user tags for Clarity
312
+ Analytics.setUserTag("subscription", "premium");
313
+ Analytics.setUserTag("user_segment", "power_user");
314
+
315
+ // Update configuration
316
+ Analytics.setConfig({
317
+ locale: "fr"
318
+ });
319
+
320
+ // Reset user on logout
321
+ Analytics.resetUser();
322
+ ```
323
+
324
+ ## Configuration
325
+
326
+ Make sure to configure your analytics provider tokens in your constants file:
120
327
 
121
- // Reset the user
122
- resetUser();
328
+ ```javascript
329
+ // constants.js
330
+ export const MIXPANEL_TOKEN = "your-mixpanel-token";
331
+ export const GOOGLE_ANALYTICS_ID = "your-ga-measurement-id";
332
+ export const CLARITY_ID = "your-clarity-project-id";
333
+ export const GA_SERVER_CONTAINER_URL = "your-server-container-url";
334
+ ```
335
+
336
+ ## Common Parameters
337
+
338
+ The library automatically collects and includes common parameters with every event:
339
+
340
+ - Device type, browser, and operating system
341
+ - User language and locale
342
+ - UTM parameters and referrer information
343
+ - Session IDs and user pseudo IDs
344
+ - Facebook tracking parameters (fbc, fbp)
345
+ - Current URL and page information
346
+ - User login status and profile data
347
+
348
+ ## TypeScript Support
349
+
350
+ The library includes TypeScript definitions for better development experience:
351
+
352
+ ```typescript
353
+ import Analytics from "rozmova-analytics";
354
+ import type { EventParams } from "rozmova-analytics";
355
+
356
+ // Type-safe event tracking
357
+ const eventParams: EventParams = {
358
+ product_id: "123",
359
+ category: "electronics"
360
+ };
361
+
362
+ Analytics.trackEvent("product_view", eventParams);
123
363
  ```
124
364
 
125
365
  ## Contributing
126
366
 
127
367
  Contributions are welcome! Please fork the repository and create a pull request with your changes.
128
368
 
369
+ 1. Fork the repository
370
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
371
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
372
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
373
+ 5. Open a Pull Request
374
+
129
375
  ## License
130
376
 
131
- This project is licensed under the MIT License.
377
+ This project is licensed under the MIT License.
@@ -16,3 +16,6 @@ export declare const initialLoginEvent: (trackEvent: (eventName: string, propert
16
16
  export declare const setProfileId: (profileId: string) => void;
17
17
  export declare const getProfileId: () => string | undefined;
18
18
  export declare const resetProfileId: () => void;
19
+ export declare const setProfileEmail: (email: string) => void;
20
+ export declare const getProfileEmail: () => string | undefined;
21
+ export declare const resetProfileEmail: () => void;
@@ -8,3 +8,4 @@ export declare const CUSTOMER_IO_WRITE_KEY = "e6d009719c77519432c3";
8
8
  export declare const CLARITY_ID = "irbqmnlbwz";
9
9
  export declare const SUPPORTED_LANGUAGES: string[];
10
10
  export declare const GA_ECOMMERCE_EVENTS: string[];
11
+ export declare const INTERNAL_USER_EMAILS: string[];
package/dist/helpers.d.ts CHANGED
@@ -12,3 +12,4 @@ export declare const getClientIdFromCookies: () => string;
12
12
  export declare const getGAClientId: () => Promise<string>;
13
13
  export declare function getGASessionId(): string | null;
14
14
  export declare const getLocaleFromURL: (isClearly?: boolean) => string;
15
+ export declare const getUserType: (email?: string) => "external" | "internal";
package/dist/index.d.ts CHANGED
@@ -9,12 +9,19 @@ declare class Analytics {
9
9
  platform?: string;
10
10
  isClearly?: boolean;
11
11
  }): void;
12
+ private processDataLayer;
12
13
  setUserTag(key: string, value: string): void;
13
14
  trackEvent(eventName: string, properties?: EventParams, services?: {
14
15
  ga?: boolean;
15
16
  mixpanel?: boolean;
16
17
  customerIO?: boolean;
17
18
  }): Promise<void>;
19
+ setConfig({ userId, email, locale, }?: {
20
+ userId?: string;
21
+ email?: string;
22
+ locale?: string;
23
+ }): void;
24
+ trackPageView(): void;
18
25
  setUser(userId: string, userParams: {
19
26
  email: string;
20
27
  name: string;
package/dist/index.esm.js CHANGED
@@ -12003,6 +12003,7 @@ const GA_ECOMMERCE_EVENTS = [
12003
12003
  "begin_checkout",
12004
12004
  "add_payment_info",
12005
12005
  ];
12006
+ const INTERNAL_USER_EMAILS = ["rozmova.me", "uptech.team"];
12006
12007
 
12007
12008
  const setQueryParam = (name, value) => {
12008
12009
  const url = new URL(window.location.href);
@@ -12183,6 +12184,12 @@ const getLocaleFromURL = (isClearly) => {
12183
12184
  else
12184
12185
  return isClearly ? "en" : "uk";
12185
12186
  };
12187
+ const getUserType = (email) => {
12188
+ if (!email)
12189
+ return "external";
12190
+ const isInternal = INTERNAL_USER_EMAILS.some((internalEmail) => email.includes(internalEmail));
12191
+ return isInternal ? "internal" : "external";
12192
+ };
12186
12193
 
12187
12194
  function insertCustomerIOScript() {
12188
12195
  const scriptContent = `
@@ -12298,6 +12305,18 @@ const resetProfileId = () => {
12298
12305
  const domain = getDomain();
12299
12306
  api.remove(PROFILE_ID_KEY, { domain });
12300
12307
  };
12308
+ const PROFILE_EMAIL_KEY = "my_profile_email";
12309
+ const setProfileEmail = (email) => {
12310
+ const domain = getDomain();
12311
+ api.set(PROFILE_EMAIL_KEY, email, { domain });
12312
+ };
12313
+ const getProfileEmail = () => {
12314
+ return api.get(PROFILE_EMAIL_KEY);
12315
+ };
12316
+ const resetProfileEmail = () => {
12317
+ const domain = getDomain();
12318
+ api.remove(PROFILE_EMAIL_KEY, { domain });
12319
+ };
12301
12320
 
12302
12321
  /*!
12303
12322
  * CookieConsent 3.0.1
@@ -12551,12 +12570,25 @@ class Analytics {
12551
12570
  Clarity.init(CLARITY_ID);
12552
12571
  const userProperties = this.getCommonParams();
12553
12572
  mixpanel.register(userProperties);
12573
+ this.setConfig();
12574
+ this.trackPageView();
12554
12575
  gtag("config", GOOGLE_ANALYTICS_ID, {
12555
12576
  user_properties: userProperties,
12556
12577
  server_container_url: GA_SERVER_CONTAINER_URL,
12557
12578
  });
12558
12579
  initialLoginEvent(this.trackEvent.bind(this));
12559
12580
  this.initialized = true;
12581
+ this.processDataLayer();
12582
+ }
12583
+ processDataLayer() {
12584
+ const priorityEvents = ["g_config", "page_view"];
12585
+ for (const priorityEvent of priorityEvents) {
12586
+ const eventIndex = this.dataLayer.findIndex((event) => event.eventName === priorityEvent);
12587
+ if (eventIndex !== -1) {
12588
+ const event = this.dataLayer.splice(eventIndex, 1)[0];
12589
+ this.trackEvent(event.eventName, event.eventParams);
12590
+ }
12591
+ }
12560
12592
  while (this.dataLayer.length > 0) {
12561
12593
  const event = this.dataLayer.shift();
12562
12594
  this.trackEvent(event?.eventName, event?.eventParams);
@@ -12618,6 +12650,24 @@ class Analytics {
12618
12650
  }
12619
12651
  }
12620
12652
  }
12653
+ setConfig({ userId, email, locale, } = {}) {
12654
+ const user_id = userId || getProfileId();
12655
+ const user_email = email || getProfileEmail();
12656
+ this.trackEvent("g_config", {
12657
+ user_id,
12658
+ is_logged: user_id ? "yes" : "no",
12659
+ locale: locale || this.locale,
12660
+ platform: this.platform,
12661
+ user_type: getUserType(user_email),
12662
+ });
12663
+ }
12664
+ trackPageView() {
12665
+ this.trackEvent("page_view", {
12666
+ page_title: document.title,
12667
+ page_location: window.location.href,
12668
+ page_referrer: document.referrer,
12669
+ });
12670
+ }
12621
12671
  setUser(userId, userParams) {
12622
12672
  if (!this.initialized) {
12623
12673
  console.warn("Analytics is not initialized.");
@@ -12637,6 +12687,8 @@ class Analytics {
12637
12687
  window.analytics.identify(userId, userParams);
12638
12688
  // store user id in cookies
12639
12689
  setProfileId(userId);
12690
+ // store user email in cookies
12691
+ setProfileEmail(email);
12640
12692
  // login event
12641
12693
  this.trackEvent("login", { logged: "yes", uid: userId });
12642
12694
  }
@@ -12673,6 +12725,7 @@ class Analytics {
12673
12725
  mixpanel.reset();
12674
12726
  window.analytics.reset();
12675
12727
  resetProfileId();
12728
+ resetProfileEmail();
12676
12729
  this.trackEvent("login", { logged: "no" });
12677
12730
  generateUserId();
12678
12731
  this.init();
package/dist/index.js CHANGED
@@ -12005,6 +12005,7 @@ const GA_ECOMMERCE_EVENTS = [
12005
12005
  "begin_checkout",
12006
12006
  "add_payment_info",
12007
12007
  ];
12008
+ const INTERNAL_USER_EMAILS = ["rozmova.me", "uptech.team"];
12008
12009
 
12009
12010
  const setQueryParam = (name, value) => {
12010
12011
  const url = new URL(window.location.href);
@@ -12185,6 +12186,12 @@ const getLocaleFromURL = (isClearly) => {
12185
12186
  else
12186
12187
  return isClearly ? "en" : "uk";
12187
12188
  };
12189
+ const getUserType = (email) => {
12190
+ if (!email)
12191
+ return "external";
12192
+ const isInternal = INTERNAL_USER_EMAILS.some((internalEmail) => email.includes(internalEmail));
12193
+ return isInternal ? "internal" : "external";
12194
+ };
12188
12195
 
12189
12196
  function insertCustomerIOScript() {
12190
12197
  const scriptContent = `
@@ -12300,6 +12307,18 @@ const resetProfileId = () => {
12300
12307
  const domain = getDomain();
12301
12308
  api.remove(PROFILE_ID_KEY, { domain });
12302
12309
  };
12310
+ const PROFILE_EMAIL_KEY = "my_profile_email";
12311
+ const setProfileEmail = (email) => {
12312
+ const domain = getDomain();
12313
+ api.set(PROFILE_EMAIL_KEY, email, { domain });
12314
+ };
12315
+ const getProfileEmail = () => {
12316
+ return api.get(PROFILE_EMAIL_KEY);
12317
+ };
12318
+ const resetProfileEmail = () => {
12319
+ const domain = getDomain();
12320
+ api.remove(PROFILE_EMAIL_KEY, { domain });
12321
+ };
12303
12322
 
12304
12323
  /*!
12305
12324
  * CookieConsent 3.0.1
@@ -12553,12 +12572,25 @@ class Analytics {
12553
12572
  Clarity.init(CLARITY_ID);
12554
12573
  const userProperties = this.getCommonParams();
12555
12574
  mixpanel.register(userProperties);
12575
+ this.setConfig();
12576
+ this.trackPageView();
12556
12577
  gtag("config", GOOGLE_ANALYTICS_ID, {
12557
12578
  user_properties: userProperties,
12558
12579
  server_container_url: GA_SERVER_CONTAINER_URL,
12559
12580
  });
12560
12581
  initialLoginEvent(this.trackEvent.bind(this));
12561
12582
  this.initialized = true;
12583
+ this.processDataLayer();
12584
+ }
12585
+ processDataLayer() {
12586
+ const priorityEvents = ["g_config", "page_view"];
12587
+ for (const priorityEvent of priorityEvents) {
12588
+ const eventIndex = this.dataLayer.findIndex((event) => event.eventName === priorityEvent);
12589
+ if (eventIndex !== -1) {
12590
+ const event = this.dataLayer.splice(eventIndex, 1)[0];
12591
+ this.trackEvent(event.eventName, event.eventParams);
12592
+ }
12593
+ }
12562
12594
  while (this.dataLayer.length > 0) {
12563
12595
  const event = this.dataLayer.shift();
12564
12596
  this.trackEvent(event?.eventName, event?.eventParams);
@@ -12620,6 +12652,24 @@ class Analytics {
12620
12652
  }
12621
12653
  }
12622
12654
  }
12655
+ setConfig({ userId, email, locale, } = {}) {
12656
+ const user_id = userId || getProfileId();
12657
+ const user_email = email || getProfileEmail();
12658
+ this.trackEvent("g_config", {
12659
+ user_id,
12660
+ is_logged: user_id ? "yes" : "no",
12661
+ locale: locale || this.locale,
12662
+ platform: this.platform,
12663
+ user_type: getUserType(user_email),
12664
+ });
12665
+ }
12666
+ trackPageView() {
12667
+ this.trackEvent("page_view", {
12668
+ page_title: document.title,
12669
+ page_location: window.location.href,
12670
+ page_referrer: document.referrer,
12671
+ });
12672
+ }
12623
12673
  setUser(userId, userParams) {
12624
12674
  if (!this.initialized) {
12625
12675
  console.warn("Analytics is not initialized.");
@@ -12639,6 +12689,8 @@ class Analytics {
12639
12689
  window.analytics.identify(userId, userParams);
12640
12690
  // store user id in cookies
12641
12691
  setProfileId(userId);
12692
+ // store user email in cookies
12693
+ setProfileEmail(email);
12642
12694
  // login event
12643
12695
  this.trackEvent("login", { logged: "yes", uid: userId });
12644
12696
  }
@@ -12675,6 +12727,7 @@ class Analytics {
12675
12727
  mixpanel.reset();
12676
12728
  window.analytics.reset();
12677
12729
  resetProfileId();
12730
+ resetProfileEmail();
12678
12731
  this.trackEvent("login", { logged: "no" });
12679
12732
  generateUserId();
12680
12733
  this.init();