rozmova-analytics 1.1.12 → 1.1.13
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 +290 -44
- package/dist/analytics.d.ts +3 -0
- package/dist/constants.d.ts +1 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.esm.js +42 -0
- package/dist/index.js +42 -0
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/rozmova-analytics)
|
|
4
4
|
[](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
|
|
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
|
-
```
|
|
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", {
|
|
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(
|
|
66
|
+
### `init(config?)`
|
|
67
67
|
|
|
68
|
-
Initializes the analytics library, setting up Mixpanel
|
|
68
|
+
Initializes the analytics library, setting up Mixpanel, Google Analytics, Customer.io, and Microsoft Clarity integrations.
|
|
69
69
|
|
|
70
|
-
|
|
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
|
-
|
|
75
|
+
**Example:**
|
|
76
|
+
```javascript
|
|
77
|
+
Analytics.init({
|
|
78
|
+
locale: "en",
|
|
79
|
+
platform: "web",
|
|
80
|
+
isClearly: true
|
|
81
|
+
});
|
|
82
|
+
```
|
|
73
83
|
|
|
74
|
-
### `
|
|
84
|
+
### `trackEvent(eventName, properties?, services?)`
|
|
75
85
|
|
|
76
|
-
|
|
86
|
+
Tracks an event across the specified analytics providers.
|
|
77
87
|
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
117
|
+
Associates a user with the provided user ID and sets user properties across all analytics providers.
|
|
85
118
|
|
|
86
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
283
|
+
import Analytics from "rozmova-analytics";
|
|
111
284
|
|
|
112
285
|
// Initialize analytics
|
|
113
|
-
init({
|
|
286
|
+
Analytics.init({
|
|
287
|
+
locale: "en",
|
|
288
|
+
platform: "web",
|
|
289
|
+
isClearly: true
|
|
290
|
+
});
|
|
114
291
|
|
|
115
|
-
// Track a page view
|
|
116
|
-
|
|
292
|
+
// Track a page view (automatically called during init)
|
|
293
|
+
Analytics.trackPageView();
|
|
117
294
|
|
|
118
295
|
// Set user details
|
|
119
|
-
setUser("user-456", {
|
|
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
|
-
|
|
122
|
-
|
|
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.
|
package/dist/analytics.d.ts
CHANGED
|
@@ -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;
|
package/dist/constants.d.ts
CHANGED
|
@@ -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
|
@@ -15,6 +15,12 @@ declare class Analytics {
|
|
|
15
15
|
mixpanel?: boolean;
|
|
16
16
|
customerIO?: boolean;
|
|
17
17
|
}): Promise<void>;
|
|
18
|
+
setConfig({ userId, email, locale, }?: {
|
|
19
|
+
userId?: string;
|
|
20
|
+
email?: string;
|
|
21
|
+
locale?: string;
|
|
22
|
+
}): void;
|
|
23
|
+
trackPageView(): void;
|
|
18
24
|
setUser(userId: string, userParams: {
|
|
19
25
|
email: string;
|
|
20
26
|
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,6 +12570,8 @@ 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,
|
|
@@ -12618,6 +12639,24 @@ class Analytics {
|
|
|
12618
12639
|
}
|
|
12619
12640
|
}
|
|
12620
12641
|
}
|
|
12642
|
+
setConfig({ userId, email, locale, } = {}) {
|
|
12643
|
+
const user_id = userId || getProfileId();
|
|
12644
|
+
const user_email = email || getProfileEmail();
|
|
12645
|
+
this.trackEvent("g_config", {
|
|
12646
|
+
user_id,
|
|
12647
|
+
is_logged: user_id ? "yes" : "no",
|
|
12648
|
+
locale: locale || this.locale,
|
|
12649
|
+
platform: this.platform,
|
|
12650
|
+
user_type: getUserType(user_email),
|
|
12651
|
+
});
|
|
12652
|
+
}
|
|
12653
|
+
trackPageView() {
|
|
12654
|
+
this.trackEvent("page_view", {
|
|
12655
|
+
page_title: document.title,
|
|
12656
|
+
page_location: window.location.href,
|
|
12657
|
+
page_referrer: document.referrer,
|
|
12658
|
+
});
|
|
12659
|
+
}
|
|
12621
12660
|
setUser(userId, userParams) {
|
|
12622
12661
|
if (!this.initialized) {
|
|
12623
12662
|
console.warn("Analytics is not initialized.");
|
|
@@ -12637,6 +12676,8 @@ class Analytics {
|
|
|
12637
12676
|
window.analytics.identify(userId, userParams);
|
|
12638
12677
|
// store user id in cookies
|
|
12639
12678
|
setProfileId(userId);
|
|
12679
|
+
// store user email in cookies
|
|
12680
|
+
setProfileEmail(email);
|
|
12640
12681
|
// login event
|
|
12641
12682
|
this.trackEvent("login", { logged: "yes", uid: userId });
|
|
12642
12683
|
}
|
|
@@ -12673,6 +12714,7 @@ class Analytics {
|
|
|
12673
12714
|
mixpanel.reset();
|
|
12674
12715
|
window.analytics.reset();
|
|
12675
12716
|
resetProfileId();
|
|
12717
|
+
resetProfileEmail();
|
|
12676
12718
|
this.trackEvent("login", { logged: "no" });
|
|
12677
12719
|
generateUserId();
|
|
12678
12720
|
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,6 +12572,8 @@ 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,
|
|
@@ -12620,6 +12641,24 @@ class Analytics {
|
|
|
12620
12641
|
}
|
|
12621
12642
|
}
|
|
12622
12643
|
}
|
|
12644
|
+
setConfig({ userId, email, locale, } = {}) {
|
|
12645
|
+
const user_id = userId || getProfileId();
|
|
12646
|
+
const user_email = email || getProfileEmail();
|
|
12647
|
+
this.trackEvent("g_config", {
|
|
12648
|
+
user_id,
|
|
12649
|
+
is_logged: user_id ? "yes" : "no",
|
|
12650
|
+
locale: locale || this.locale,
|
|
12651
|
+
platform: this.platform,
|
|
12652
|
+
user_type: getUserType(user_email),
|
|
12653
|
+
});
|
|
12654
|
+
}
|
|
12655
|
+
trackPageView() {
|
|
12656
|
+
this.trackEvent("page_view", {
|
|
12657
|
+
page_title: document.title,
|
|
12658
|
+
page_location: window.location.href,
|
|
12659
|
+
page_referrer: document.referrer,
|
|
12660
|
+
});
|
|
12661
|
+
}
|
|
12623
12662
|
setUser(userId, userParams) {
|
|
12624
12663
|
if (!this.initialized) {
|
|
12625
12664
|
console.warn("Analytics is not initialized.");
|
|
@@ -12639,6 +12678,8 @@ class Analytics {
|
|
|
12639
12678
|
window.analytics.identify(userId, userParams);
|
|
12640
12679
|
// store user id in cookies
|
|
12641
12680
|
setProfileId(userId);
|
|
12681
|
+
// store user email in cookies
|
|
12682
|
+
setProfileEmail(email);
|
|
12642
12683
|
// login event
|
|
12643
12684
|
this.trackEvent("login", { logged: "yes", uid: userId });
|
|
12644
12685
|
}
|
|
@@ -12675,6 +12716,7 @@ class Analytics {
|
|
|
12675
12716
|
mixpanel.reset();
|
|
12676
12717
|
window.analytics.reset();
|
|
12677
12718
|
resetProfileId();
|
|
12719
|
+
resetProfileEmail();
|
|
12678
12720
|
this.trackEvent("login", { logged: "no" });
|
|
12679
12721
|
generateUserId();
|
|
12680
12722
|
this.init();
|