rozmova-analytics 1.0.16 → 1.0.18
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 +16 -2
- package/dist/analytics.d.ts +5 -14
- package/dist/constants.d.ts +2 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/index.d.ts +16 -12
- package/dist/index.esm.js +120 -103
- package/dist/index.js +120 -103
- package/dist/index.umd.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ Install the package using npm:
|
|
|
13
13
|
npm install rozmova-analytics
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
Alternatively, you can include the library via jsDelivr:
|
|
16
|
+
Alternatively, you can include the library via jsDelivr to use in browser:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
<script src="https://cdn.jsdelivr.net/npm/rozmova-analytics/dist/index.js"></script>
|
|
19
|
+
<script src="https://cdn.jsdelivr.net/npm/rozmova-analytics/dist/index.umd.js"></script>
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
@@ -45,6 +45,20 @@ setUser('user-id-123', { email: 'user@example.com', name: 'John Doe' });
|
|
|
45
45
|
trackEvent('button_click', { button_name: 'Sign Up' });
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
+
Or use in browser:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
|
|
52
|
+
// Initialize the library
|
|
53
|
+
window.Analytics.init('en', 'web');
|
|
54
|
+
|
|
55
|
+
// Set user
|
|
56
|
+
window.Analytics.setUser('user-id-123', { email: 'user@example.com', name: 'John Doe' });
|
|
57
|
+
|
|
58
|
+
// Track an event
|
|
59
|
+
window.Analytics.trackEvent('button_click', { button_name: 'Sign Up' });
|
|
60
|
+
```
|
|
61
|
+
|
|
48
62
|
## API
|
|
49
63
|
|
|
50
64
|
### `init(locale?: string, platform?: string)`
|
package/dist/analytics.d.ts
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import { AnalyticsCommonParams, EventParams } from "./types.js";
|
|
2
1
|
export declare function insertCustomerIOScript(): void;
|
|
3
|
-
export declare const setUserId: (userId: string) => void;
|
|
4
2
|
export declare const generateUserId: () => string;
|
|
5
3
|
export declare const getUserId: () => string;
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export declare const init: (locale?: string, platform?: string) => void;
|
|
12
|
-
export declare const trackEvent: (eventName: string, properties?: EventParams) => void;
|
|
13
|
-
export declare const setUser: (userId: string, userParams: {
|
|
14
|
-
email: string;
|
|
15
|
-
name: string;
|
|
16
|
-
}) => void;
|
|
17
|
-
export declare const resetUser: () => void;
|
|
4
|
+
export declare const getCurrentParams: () => {
|
|
5
|
+
referrer: any;
|
|
6
|
+
search_query: any;
|
|
7
|
+
landing_page_url: any;
|
|
8
|
+
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ export declare const GOOGLE_ANALYTICS_ID = "G-9PCTLFE0F6";
|
|
|
5
5
|
export declare const GA_SERVER_CONTAINER_URL = "https://tagging.clearly.help";
|
|
6
6
|
export declare const MIXPANEL_TOKEN = "9d4cb3d213e5aee689ea01dd68ad65ad";
|
|
7
7
|
export declare const CUSTOMER_IO_WRITE_KEY = "e6d009719c77519432c3";
|
|
8
|
+
export declare const IS_CLEARLY: boolean;
|
|
9
|
+
export declare const SUPPORTED_LANGUAGES: string[];
|
package/dist/helpers.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export declare const getReferrer: () => string | null;
|
|
|
10
10
|
export declare function getSearchQueryFromReferrer(): string | null;
|
|
11
11
|
export declare const getGAClientId: () => string;
|
|
12
12
|
export declare function getGASessionId(): string | null;
|
|
13
|
+
export declare const getLocaleFromURL: () => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { AnalyticsCommonParams, EventParams } from "./types";
|
|
2
|
+
declare class Analytics {
|
|
3
|
+
private initialized;
|
|
4
|
+
private locale;
|
|
5
|
+
private platform;
|
|
6
|
+
init(locale?: string, platform?: string): void;
|
|
7
|
+
trackEvent(eventName: string, properties?: EventParams): void;
|
|
8
|
+
setUser(userId: string, userParams: {
|
|
8
9
|
email: string;
|
|
9
10
|
name: string;
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
setLocale
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
}): void;
|
|
12
|
+
getCommonParams(): AnalyticsCommonParams;
|
|
13
|
+
setLocale(newLocale: string): void;
|
|
14
|
+
resetUser(): void;
|
|
15
|
+
getUserId: () => string;
|
|
16
|
+
}
|
|
17
|
+
declare const _default: Analytics;
|
|
18
|
+
export default _default;
|
package/dist/index.esm.js
CHANGED
|
@@ -30,7 +30,7 @@ var defaultConverter = {
|
|
|
30
30
|
|
|
31
31
|
/* eslint-disable no-var */
|
|
32
32
|
|
|
33
|
-
function init
|
|
33
|
+
function init (converter, defaultAttributes) {
|
|
34
34
|
function set (name, value, attributes) {
|
|
35
35
|
if (typeof document === 'undefined') {
|
|
36
36
|
return
|
|
@@ -115,10 +115,10 @@ function init$1 (converter, defaultAttributes) {
|
|
|
115
115
|
);
|
|
116
116
|
},
|
|
117
117
|
withAttributes: function (attributes) {
|
|
118
|
-
return init
|
|
118
|
+
return init(this.converter, assign({}, this.attributes, attributes))
|
|
119
119
|
},
|
|
120
120
|
withConverter: function (converter) {
|
|
121
|
-
return init
|
|
121
|
+
return init(assign({}, this.converter, converter), this.attributes)
|
|
122
122
|
}
|
|
123
123
|
},
|
|
124
124
|
{
|
|
@@ -128,7 +128,7 @@ function init$1 (converter, defaultAttributes) {
|
|
|
128
128
|
)
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
var api = init
|
|
131
|
+
var api = init(defaultConverter, { path: '/' });
|
|
132
132
|
|
|
133
133
|
var NodeType;
|
|
134
134
|
(function (NodeType) {
|
|
@@ -11945,6 +11945,8 @@ const GOOGLE_ANALYTICS_ID = "G-9PCTLFE0F6";
|
|
|
11945
11945
|
const GA_SERVER_CONTAINER_URL = "https://tagging.clearly.help";
|
|
11946
11946
|
const MIXPANEL_TOKEN = "9d4cb3d213e5aee689ea01dd68ad65ad";
|
|
11947
11947
|
const CUSTOMER_IO_WRITE_KEY = "e6d009719c77519432c3";
|
|
11948
|
+
const IS_CLEARLY = window.location.hostname.includes("clearly");
|
|
11949
|
+
const SUPPORTED_LANGUAGES = ["en", "uk", "pl", "es", "ru"];
|
|
11948
11950
|
|
|
11949
11951
|
const setQueryParam = (name, value) => {
|
|
11950
11952
|
const url = new URL(window.location.href);
|
|
@@ -12076,6 +12078,14 @@ function getGASessionId() {
|
|
|
12076
12078
|
return parts[0];
|
|
12077
12079
|
return null;
|
|
12078
12080
|
}
|
|
12081
|
+
const getLocaleFromURL = () => {
|
|
12082
|
+
const pathname = window.location.pathname;
|
|
12083
|
+
const lng = pathname.split("/")[1];
|
|
12084
|
+
if (SUPPORTED_LANGUAGES.includes(lng))
|
|
12085
|
+
return lng;
|
|
12086
|
+
else
|
|
12087
|
+
return IS_CLEARLY ? "en" : "uk";
|
|
12088
|
+
};
|
|
12079
12089
|
|
|
12080
12090
|
function insertCustomerIOScript() {
|
|
12081
12091
|
const scriptContent = `
|
|
@@ -12159,108 +12169,115 @@ const getCurrentParams = () => {
|
|
|
12159
12169
|
});
|
|
12160
12170
|
return currentParams;
|
|
12161
12171
|
};
|
|
12162
|
-
|
|
12163
|
-
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
};
|
|
12190
|
-
|
|
12191
|
-
insertCustomerIOScript();
|
|
12192
|
-
const userId = getUserId();
|
|
12193
|
-
if (isMetaBrowser()) {
|
|
12194
|
-
setQueryParam(USER_ID_KEY, userId);
|
|
12195
|
-
}
|
|
12196
|
-
mixpanel.init(MIXPANEL_TOKEN, {
|
|
12197
|
-
debug: false,
|
|
12198
|
-
track_pageview: "url-with-path",
|
|
12199
|
-
persistence: "cookie",
|
|
12200
|
-
});
|
|
12201
|
-
if (locale)
|
|
12202
|
-
setLocale(locale);
|
|
12203
|
-
if (platform)
|
|
12204
|
-
setPlatform(platform);
|
|
12205
|
-
const userProperties = getCommonParams();
|
|
12206
|
-
mixpanel.register(userProperties);
|
|
12207
|
-
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12208
|
-
user_properties: userProperties,
|
|
12209
|
-
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12210
|
-
});
|
|
12211
|
-
};
|
|
12212
|
-
const trackEvent = (eventName, properties = {}) => {
|
|
12213
|
-
const commonParams = getCommonParams();
|
|
12214
|
-
const params = { ...commonParams, ...properties };
|
|
12215
|
-
// Mixpanel
|
|
12216
|
-
try {
|
|
12217
|
-
mixpanel.track(eventName, params);
|
|
12218
|
-
}
|
|
12219
|
-
catch (e) {
|
|
12220
|
-
console.log(e);
|
|
12172
|
+
|
|
12173
|
+
class Analytics {
|
|
12174
|
+
initialized = false;
|
|
12175
|
+
locale = getLocaleFromURL();
|
|
12176
|
+
platform = "web";
|
|
12177
|
+
init(locale, platform) {
|
|
12178
|
+
if (this.initialized)
|
|
12179
|
+
return;
|
|
12180
|
+
insertCustomerIOScript();
|
|
12181
|
+
const userId = getUserId();
|
|
12182
|
+
if (isMetaBrowser()) {
|
|
12183
|
+
setQueryParam(USER_ID_KEY, userId);
|
|
12184
|
+
}
|
|
12185
|
+
mixpanel.init(MIXPANEL_TOKEN, {
|
|
12186
|
+
debug: false,
|
|
12187
|
+
track_pageview: "url-with-path",
|
|
12188
|
+
persistence: "cookie",
|
|
12189
|
+
});
|
|
12190
|
+
if (locale)
|
|
12191
|
+
this.locale = locale;
|
|
12192
|
+
if (platform)
|
|
12193
|
+
this.platform = platform;
|
|
12194
|
+
const userProperties = this.getCommonParams();
|
|
12195
|
+
mixpanel.register(userProperties);
|
|
12196
|
+
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12197
|
+
user_properties: userProperties,
|
|
12198
|
+
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12199
|
+
});
|
|
12200
|
+
this.initialized = true;
|
|
12221
12201
|
}
|
|
12222
|
-
|
|
12223
|
-
|
|
12224
|
-
|
|
12202
|
+
trackEvent(eventName, properties) {
|
|
12203
|
+
if (!this.initialized) {
|
|
12204
|
+
console.warn("Analytics is not initialized.");
|
|
12205
|
+
return;
|
|
12206
|
+
}
|
|
12207
|
+
const commonParams = this.getCommonParams();
|
|
12208
|
+
const params = { ...commonParams, ...properties };
|
|
12209
|
+
// Mixpanel
|
|
12210
|
+
try {
|
|
12211
|
+
mixpanel.track(eventName, params);
|
|
12212
|
+
}
|
|
12213
|
+
catch (e) {
|
|
12214
|
+
console.log(e);
|
|
12215
|
+
}
|
|
12216
|
+
// GA
|
|
12217
|
+
try {
|
|
12218
|
+
gtag("event", eventName, params);
|
|
12219
|
+
}
|
|
12220
|
+
catch (e) {
|
|
12221
|
+
console.log(e);
|
|
12222
|
+
}
|
|
12223
|
+
// Customer.io
|
|
12224
|
+
try {
|
|
12225
|
+
window.analytics.track(eventName, params);
|
|
12226
|
+
}
|
|
12227
|
+
catch (e) {
|
|
12228
|
+
console.log(e);
|
|
12229
|
+
}
|
|
12225
12230
|
}
|
|
12226
|
-
|
|
12227
|
-
|
|
12231
|
+
setUser(userId, userParams) {
|
|
12232
|
+
if (!this.initialized) {
|
|
12233
|
+
console.warn("Analytics is not initialized.");
|
|
12234
|
+
return;
|
|
12235
|
+
}
|
|
12236
|
+
const { email, name } = userParams;
|
|
12237
|
+
mixpanel.identify(userId);
|
|
12238
|
+
mixpanel.people.set({ $email: email, name });
|
|
12239
|
+
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12240
|
+
user_properties: this.getCommonParams(),
|
|
12241
|
+
user_id: userId,
|
|
12242
|
+
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12243
|
+
});
|
|
12244
|
+
window.analytics.identify(userId, userParams);
|
|
12245
|
+
}
|
|
12246
|
+
getCommonParams() {
|
|
12247
|
+
const persistedParams = getCurrentParams();
|
|
12248
|
+
return {
|
|
12249
|
+
...persistedParams,
|
|
12250
|
+
fbc: api.get("_fbc"),
|
|
12251
|
+
fbp: api.get("_fbp"),
|
|
12252
|
+
session_id: getGASessionId(),
|
|
12253
|
+
user_pseudo_id: getGAClientId(),
|
|
12254
|
+
rid: getUserId(),
|
|
12255
|
+
funnel_name: api.get("funnel_name"),
|
|
12256
|
+
funnel_type: api.get("funnel_type"),
|
|
12257
|
+
language: getBrowserLanguage(),
|
|
12258
|
+
platform: this.platform,
|
|
12259
|
+
url: window.location.href,
|
|
12260
|
+
device: detectDeviceType(),
|
|
12261
|
+
browser: detectBrowser(),
|
|
12262
|
+
system: detectOS(),
|
|
12263
|
+
locale: this.locale,
|
|
12264
|
+
};
|
|
12228
12265
|
}
|
|
12229
|
-
|
|
12230
|
-
|
|
12231
|
-
window.analytics.track(eventName, params);
|
|
12266
|
+
setLocale(newLocale) {
|
|
12267
|
+
this.locale = newLocale;
|
|
12232
12268
|
}
|
|
12233
|
-
|
|
12234
|
-
|
|
12269
|
+
resetUser() {
|
|
12270
|
+
if (!this.initialized) {
|
|
12271
|
+
console.warn("Analytics is not initialized.");
|
|
12272
|
+
return;
|
|
12273
|
+
}
|
|
12274
|
+
mixpanel.reset();
|
|
12275
|
+
window.analytics.reset();
|
|
12276
|
+
generateUserId();
|
|
12277
|
+
this.init();
|
|
12235
12278
|
}
|
|
12236
|
-
|
|
12237
|
-
|
|
12238
|
-
|
|
12239
|
-
mixpanel.identify(userId);
|
|
12240
|
-
mixpanel.people.set({ $email: email, name });
|
|
12241
|
-
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12242
|
-
user_properties: getCommonParams(),
|
|
12243
|
-
user_id: userId,
|
|
12244
|
-
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12245
|
-
});
|
|
12246
|
-
window.analytics.identify(userId, userParams);
|
|
12247
|
-
};
|
|
12248
|
-
const resetUser = () => {
|
|
12249
|
-
mixpanel.reset();
|
|
12250
|
-
window.analytics.reset();
|
|
12251
|
-
generateUserId();
|
|
12252
|
-
init();
|
|
12253
|
-
};
|
|
12254
|
-
|
|
12255
|
-
const Analytics = {
|
|
12256
|
-
getUserId,
|
|
12257
|
-
generateUserId,
|
|
12258
|
-
init,
|
|
12259
|
-
getCommonParams,
|
|
12260
|
-
trackEvent,
|
|
12261
|
-
setUser,
|
|
12262
|
-
resetUser,
|
|
12263
|
-
setLocale,
|
|
12264
|
-
};
|
|
12279
|
+
getUserId = getUserId;
|
|
12280
|
+
}
|
|
12281
|
+
var index = new Analytics();
|
|
12265
12282
|
|
|
12266
|
-
export {
|
|
12283
|
+
export { index as default };
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var defaultConverter = {
|
|
|
32
32
|
|
|
33
33
|
/* eslint-disable no-var */
|
|
34
34
|
|
|
35
|
-
function init
|
|
35
|
+
function init (converter, defaultAttributes) {
|
|
36
36
|
function set (name, value, attributes) {
|
|
37
37
|
if (typeof document === 'undefined') {
|
|
38
38
|
return
|
|
@@ -117,10 +117,10 @@ function init$1 (converter, defaultAttributes) {
|
|
|
117
117
|
);
|
|
118
118
|
},
|
|
119
119
|
withAttributes: function (attributes) {
|
|
120
|
-
return init
|
|
120
|
+
return init(this.converter, assign({}, this.attributes, attributes))
|
|
121
121
|
},
|
|
122
122
|
withConverter: function (converter) {
|
|
123
|
-
return init
|
|
123
|
+
return init(assign({}, this.converter, converter), this.attributes)
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
126
|
{
|
|
@@ -130,7 +130,7 @@ function init$1 (converter, defaultAttributes) {
|
|
|
130
130
|
)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
var api = init
|
|
133
|
+
var api = init(defaultConverter, { path: '/' });
|
|
134
134
|
|
|
135
135
|
var NodeType;
|
|
136
136
|
(function (NodeType) {
|
|
@@ -11947,6 +11947,8 @@ const GOOGLE_ANALYTICS_ID = "G-9PCTLFE0F6";
|
|
|
11947
11947
|
const GA_SERVER_CONTAINER_URL = "https://tagging.clearly.help";
|
|
11948
11948
|
const MIXPANEL_TOKEN = "9d4cb3d213e5aee689ea01dd68ad65ad";
|
|
11949
11949
|
const CUSTOMER_IO_WRITE_KEY = "e6d009719c77519432c3";
|
|
11950
|
+
const IS_CLEARLY = window.location.hostname.includes("clearly");
|
|
11951
|
+
const SUPPORTED_LANGUAGES = ["en", "uk", "pl", "es", "ru"];
|
|
11950
11952
|
|
|
11951
11953
|
const setQueryParam = (name, value) => {
|
|
11952
11954
|
const url = new URL(window.location.href);
|
|
@@ -12078,6 +12080,14 @@ function getGASessionId() {
|
|
|
12078
12080
|
return parts[0];
|
|
12079
12081
|
return null;
|
|
12080
12082
|
}
|
|
12083
|
+
const getLocaleFromURL = () => {
|
|
12084
|
+
const pathname = window.location.pathname;
|
|
12085
|
+
const lng = pathname.split("/")[1];
|
|
12086
|
+
if (SUPPORTED_LANGUAGES.includes(lng))
|
|
12087
|
+
return lng;
|
|
12088
|
+
else
|
|
12089
|
+
return IS_CLEARLY ? "en" : "uk";
|
|
12090
|
+
};
|
|
12081
12091
|
|
|
12082
12092
|
function insertCustomerIOScript() {
|
|
12083
12093
|
const scriptContent = `
|
|
@@ -12161,108 +12171,115 @@ const getCurrentParams = () => {
|
|
|
12161
12171
|
});
|
|
12162
12172
|
return currentParams;
|
|
12163
12173
|
};
|
|
12164
|
-
|
|
12165
|
-
|
|
12166
|
-
|
|
12167
|
-
|
|
12168
|
-
|
|
12169
|
-
|
|
12170
|
-
|
|
12171
|
-
|
|
12172
|
-
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
|
|
12190
|
-
|
|
12191
|
-
};
|
|
12192
|
-
|
|
12193
|
-
insertCustomerIOScript();
|
|
12194
|
-
const userId = getUserId();
|
|
12195
|
-
if (isMetaBrowser()) {
|
|
12196
|
-
setQueryParam(USER_ID_KEY, userId);
|
|
12197
|
-
}
|
|
12198
|
-
mixpanel.init(MIXPANEL_TOKEN, {
|
|
12199
|
-
debug: false,
|
|
12200
|
-
track_pageview: "url-with-path",
|
|
12201
|
-
persistence: "cookie",
|
|
12202
|
-
});
|
|
12203
|
-
if (locale)
|
|
12204
|
-
setLocale(locale);
|
|
12205
|
-
if (platform)
|
|
12206
|
-
setPlatform(platform);
|
|
12207
|
-
const userProperties = getCommonParams();
|
|
12208
|
-
mixpanel.register(userProperties);
|
|
12209
|
-
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12210
|
-
user_properties: userProperties,
|
|
12211
|
-
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12212
|
-
});
|
|
12213
|
-
};
|
|
12214
|
-
const trackEvent = (eventName, properties = {}) => {
|
|
12215
|
-
const commonParams = getCommonParams();
|
|
12216
|
-
const params = { ...commonParams, ...properties };
|
|
12217
|
-
// Mixpanel
|
|
12218
|
-
try {
|
|
12219
|
-
mixpanel.track(eventName, params);
|
|
12220
|
-
}
|
|
12221
|
-
catch (e) {
|
|
12222
|
-
console.log(e);
|
|
12174
|
+
|
|
12175
|
+
class Analytics {
|
|
12176
|
+
initialized = false;
|
|
12177
|
+
locale = getLocaleFromURL();
|
|
12178
|
+
platform = "web";
|
|
12179
|
+
init(locale, platform) {
|
|
12180
|
+
if (this.initialized)
|
|
12181
|
+
return;
|
|
12182
|
+
insertCustomerIOScript();
|
|
12183
|
+
const userId = getUserId();
|
|
12184
|
+
if (isMetaBrowser()) {
|
|
12185
|
+
setQueryParam(USER_ID_KEY, userId);
|
|
12186
|
+
}
|
|
12187
|
+
mixpanel.init(MIXPANEL_TOKEN, {
|
|
12188
|
+
debug: false,
|
|
12189
|
+
track_pageview: "url-with-path",
|
|
12190
|
+
persistence: "cookie",
|
|
12191
|
+
});
|
|
12192
|
+
if (locale)
|
|
12193
|
+
this.locale = locale;
|
|
12194
|
+
if (platform)
|
|
12195
|
+
this.platform = platform;
|
|
12196
|
+
const userProperties = this.getCommonParams();
|
|
12197
|
+
mixpanel.register(userProperties);
|
|
12198
|
+
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12199
|
+
user_properties: userProperties,
|
|
12200
|
+
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12201
|
+
});
|
|
12202
|
+
this.initialized = true;
|
|
12223
12203
|
}
|
|
12224
|
-
|
|
12225
|
-
|
|
12226
|
-
|
|
12204
|
+
trackEvent(eventName, properties) {
|
|
12205
|
+
if (!this.initialized) {
|
|
12206
|
+
console.warn("Analytics is not initialized.");
|
|
12207
|
+
return;
|
|
12208
|
+
}
|
|
12209
|
+
const commonParams = this.getCommonParams();
|
|
12210
|
+
const params = { ...commonParams, ...properties };
|
|
12211
|
+
// Mixpanel
|
|
12212
|
+
try {
|
|
12213
|
+
mixpanel.track(eventName, params);
|
|
12214
|
+
}
|
|
12215
|
+
catch (e) {
|
|
12216
|
+
console.log(e);
|
|
12217
|
+
}
|
|
12218
|
+
// GA
|
|
12219
|
+
try {
|
|
12220
|
+
gtag("event", eventName, params);
|
|
12221
|
+
}
|
|
12222
|
+
catch (e) {
|
|
12223
|
+
console.log(e);
|
|
12224
|
+
}
|
|
12225
|
+
// Customer.io
|
|
12226
|
+
try {
|
|
12227
|
+
window.analytics.track(eventName, params);
|
|
12228
|
+
}
|
|
12229
|
+
catch (e) {
|
|
12230
|
+
console.log(e);
|
|
12231
|
+
}
|
|
12227
12232
|
}
|
|
12228
|
-
|
|
12229
|
-
|
|
12233
|
+
setUser(userId, userParams) {
|
|
12234
|
+
if (!this.initialized) {
|
|
12235
|
+
console.warn("Analytics is not initialized.");
|
|
12236
|
+
return;
|
|
12237
|
+
}
|
|
12238
|
+
const { email, name } = userParams;
|
|
12239
|
+
mixpanel.identify(userId);
|
|
12240
|
+
mixpanel.people.set({ $email: email, name });
|
|
12241
|
+
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12242
|
+
user_properties: this.getCommonParams(),
|
|
12243
|
+
user_id: userId,
|
|
12244
|
+
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12245
|
+
});
|
|
12246
|
+
window.analytics.identify(userId, userParams);
|
|
12247
|
+
}
|
|
12248
|
+
getCommonParams() {
|
|
12249
|
+
const persistedParams = getCurrentParams();
|
|
12250
|
+
return {
|
|
12251
|
+
...persistedParams,
|
|
12252
|
+
fbc: api.get("_fbc"),
|
|
12253
|
+
fbp: api.get("_fbp"),
|
|
12254
|
+
session_id: getGASessionId(),
|
|
12255
|
+
user_pseudo_id: getGAClientId(),
|
|
12256
|
+
rid: getUserId(),
|
|
12257
|
+
funnel_name: api.get("funnel_name"),
|
|
12258
|
+
funnel_type: api.get("funnel_type"),
|
|
12259
|
+
language: getBrowserLanguage(),
|
|
12260
|
+
platform: this.platform,
|
|
12261
|
+
url: window.location.href,
|
|
12262
|
+
device: detectDeviceType(),
|
|
12263
|
+
browser: detectBrowser(),
|
|
12264
|
+
system: detectOS(),
|
|
12265
|
+
locale: this.locale,
|
|
12266
|
+
};
|
|
12230
12267
|
}
|
|
12231
|
-
|
|
12232
|
-
|
|
12233
|
-
window.analytics.track(eventName, params);
|
|
12268
|
+
setLocale(newLocale) {
|
|
12269
|
+
this.locale = newLocale;
|
|
12234
12270
|
}
|
|
12235
|
-
|
|
12236
|
-
|
|
12271
|
+
resetUser() {
|
|
12272
|
+
if (!this.initialized) {
|
|
12273
|
+
console.warn("Analytics is not initialized.");
|
|
12274
|
+
return;
|
|
12275
|
+
}
|
|
12276
|
+
mixpanel.reset();
|
|
12277
|
+
window.analytics.reset();
|
|
12278
|
+
generateUserId();
|
|
12279
|
+
this.init();
|
|
12237
12280
|
}
|
|
12238
|
-
|
|
12239
|
-
|
|
12240
|
-
|
|
12241
|
-
mixpanel.identify(userId);
|
|
12242
|
-
mixpanel.people.set({ $email: email, name });
|
|
12243
|
-
gtag("config", GOOGLE_ANALYTICS_ID, {
|
|
12244
|
-
user_properties: getCommonParams(),
|
|
12245
|
-
user_id: userId,
|
|
12246
|
-
server_container_url: GA_SERVER_CONTAINER_URL,
|
|
12247
|
-
});
|
|
12248
|
-
window.analytics.identify(userId, userParams);
|
|
12249
|
-
};
|
|
12250
|
-
const resetUser = () => {
|
|
12251
|
-
mixpanel.reset();
|
|
12252
|
-
window.analytics.reset();
|
|
12253
|
-
generateUserId();
|
|
12254
|
-
init();
|
|
12255
|
-
};
|
|
12256
|
-
|
|
12257
|
-
const Analytics = {
|
|
12258
|
-
getUserId,
|
|
12259
|
-
generateUserId,
|
|
12260
|
-
init,
|
|
12261
|
-
getCommonParams,
|
|
12262
|
-
trackEvent,
|
|
12263
|
-
setUser,
|
|
12264
|
-
resetUser,
|
|
12265
|
-
setLocale,
|
|
12266
|
-
};
|
|
12281
|
+
getUserId = getUserId;
|
|
12282
|
+
}
|
|
12283
|
+
var index = new Analytics();
|
|
12267
12284
|
|
|
12268
|
-
module.exports =
|
|
12285
|
+
module.exports = index;
|