swetrix 2.2.0 → 2.3.0

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.
@@ -28,311 +28,326 @@
28
28
  return t;
29
29
  };
30
30
  return __assign.apply(this, arguments);
31
+ };
32
+
33
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
34
+ var e = new Error(message);
35
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
31
36
  };
32
37
 
33
- var findInSearch = function (exp) {
34
- var res = location.search.match(exp);
35
- return (res && res[2]) || undefined;
36
- };
37
- var utmSourceRegex = /[?&](ref|source|utm_source)=([^?&]+)/;
38
- var utmCampaignRegex = /[?&](utm_campaign)=([^?&]+)/;
39
- var utmMediumRegex = /[?&](utm_medium)=([^?&]+)/;
40
- var isInBrowser = function () {
41
- return typeof window !== 'undefined';
42
- };
43
- var isLocalhost = function () {
44
- return (location === null || location === void 0 ? void 0 : location.hostname) === 'localhost' || (location === null || location === void 0 ? void 0 : location.hostname) === '127.0.0.1' || (location === null || location === void 0 ? void 0 : location.hostname) === '';
45
- };
46
- var isAutomated = function () {
47
- return navigator === null || navigator === void 0 ? void 0 : navigator.webdriver;
48
- };
49
- var getLocale = function () {
50
- return typeof navigator.languages !== 'undefined' ? navigator.languages[0] : navigator.language;
51
- };
52
- var getTimezone = function () {
53
- try {
54
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
55
- }
56
- catch (e) {
57
- return;
58
- }
59
- };
60
- var getReferrer = function () {
61
- return document.referrer || undefined;
62
- };
63
- var getUTMSource = function () { return findInSearch(utmSourceRegex); };
64
- var getUTMMedium = function () { return findInSearch(utmMediumRegex); };
65
- var getUTMCampaign = function () { return findInSearch(utmCampaignRegex); };
66
- var getPath = function () {
67
- // TODO: Maybe we should also include such data as location.hash or location.search
68
- return location.pathname || '';
38
+ var findInSearch = function (exp) {
39
+ var res = location.search.match(exp);
40
+ return (res && res[2]) || undefined;
41
+ };
42
+ var utmSourceRegex = /[?&](ref|source|utm_source)=([^?&]+)/;
43
+ var utmCampaignRegex = /[?&](utm_campaign)=([^?&]+)/;
44
+ var utmMediumRegex = /[?&](utm_medium)=([^?&]+)/;
45
+ var isInBrowser = function () {
46
+ return typeof window !== 'undefined';
47
+ };
48
+ var isLocalhost = function () {
49
+ return (location === null || location === void 0 ? void 0 : location.hostname) === 'localhost' || (location === null || location === void 0 ? void 0 : location.hostname) === '127.0.0.1' || (location === null || location === void 0 ? void 0 : location.hostname) === '';
50
+ };
51
+ var isAutomated = function () {
52
+ return navigator === null || navigator === void 0 ? void 0 : navigator.webdriver;
53
+ };
54
+ var getLocale = function () {
55
+ return typeof navigator.languages !== 'undefined' ? navigator.languages[0] : navigator.language;
56
+ };
57
+ var getTimezone = function () {
58
+ try {
59
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
60
+ }
61
+ catch (e) {
62
+ return;
63
+ }
64
+ };
65
+ var getReferrer = function () {
66
+ return document.referrer || undefined;
67
+ };
68
+ var getUTMSource = function () { return findInSearch(utmSourceRegex); };
69
+ var getUTMMedium = function () { return findInSearch(utmMediumRegex); };
70
+ var getUTMCampaign = function () { return findInSearch(utmCampaignRegex); };
71
+ var getPath = function () {
72
+ // TODO: Maybe we should also include such data as location.hash or location.search
73
+ return location.pathname || '';
69
74
  };
70
75
 
71
- var defaultPageActions = {
72
- stop: function () { },
73
- };
74
- var DEFAULT_API_HOST = 'https://api.swetrix.com/log';
75
- var Lib = /** @class */ (function () {
76
- function Lib(projectID, options) {
77
- this.projectID = projectID;
78
- this.options = options;
79
- this.pageData = null;
80
- this.pageViewsOptions = null;
81
- this.perfStatsCollected = false;
82
- this.activePage = null;
83
- this.trackPathChange = this.trackPathChange.bind(this);
84
- this.heartbeat = this.heartbeat.bind(this);
85
- }
86
- Lib.prototype.track = function (event) {
87
- if (!this.canTrack()) {
88
- return;
89
- }
90
- var data = __assign({ pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, event);
91
- this.sendRequest('custom', data);
92
- };
93
- Lib.prototype.trackPageViews = function (options) {
94
- if (!this.canTrack()) {
95
- return defaultPageActions;
96
- }
97
- if (this.pageData) {
98
- return this.pageData.actions;
99
- }
100
- this.pageViewsOptions = options;
101
- var hbInterval, interval;
102
- if (!(options === null || options === void 0 ? void 0 : options.unique)) {
103
- interval = setInterval(this.trackPathChange, 2000);
104
- }
105
- if (!(options === null || options === void 0 ? void 0 : options.noHeartbeat)) {
106
- setTimeout(this.heartbeat, 3000);
107
- hbInterval = setInterval(this.heartbeat, 28000);
108
- }
109
- var path = getPath();
110
- this.pageData = {
111
- path: path,
112
- actions: {
113
- stop: function () {
114
- clearInterval(interval);
115
- clearInterval(hbInterval);
116
- },
117
- },
118
- };
119
- this.trackPage(path, options === null || options === void 0 ? void 0 : options.unique);
120
- return this.pageData.actions;
121
- };
122
- Lib.prototype.getPerformanceStats = function () {
123
- var _a;
124
- if (!this.canTrack() || this.perfStatsCollected || !((_a = window.performance) === null || _a === void 0 ? void 0 : _a.getEntriesByType)) {
125
- return {};
126
- }
127
- var perf = window.performance.getEntriesByType('navigation')[0];
128
- if (!perf) {
129
- return {};
130
- }
131
- this.perfStatsCollected = true;
132
- return {
133
- // Network
134
- // @ts-ignore
135
- dns: perf.domainLookupEnd - perf.domainLookupStart,
136
- // @ts-ignore
137
- tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0,
138
- // @ts-ignore
139
- conn: perf.secureConnectionStart ? perf.secureConnectionStart - perf.connectStart : perf.connectEnd - perf.connectStart,
140
- // @ts-ignore
141
- response: perf.responseEnd - perf.responseStart,
142
- // Frontend
143
- // @ts-ignore
144
- render: perf.domComplete - perf.domContentLoadedEventEnd,
145
- // @ts-ignore
146
- dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
147
- // @ts-ignore
148
- page_load: perf.loadEventStart,
149
- // Backend
150
- // @ts-ignore
151
- ttfb: perf.responseStart - perf.requestStart,
152
- };
153
- };
154
- Lib.prototype.heartbeat = function () {
155
- var _a;
156
- if (!((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.heartbeatOnBackground) && document.visibilityState === 'hidden') {
157
- return;
158
- }
159
- var data = {
160
- pid: this.projectID,
161
- };
162
- this.sendRequest('hb', data);
163
- };
164
- Lib.prototype.checkIgnore = function (path) {
165
- var _a;
166
- var ignore = (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.ignore;
167
- if (Array.isArray(ignore)) {
168
- for (var i = 0; i < ignore.length; ++i) {
169
- if (ignore[i] === path)
170
- return true;
171
- // @ts-ignore
172
- if (ignore[i] instanceof RegExp && ignore[i].test(path))
173
- return true;
174
- }
175
- }
176
- return false;
177
- };
178
- // Tracking path changes. If path changes -> calling this.trackPage method
179
- Lib.prototype.trackPathChange = function () {
180
- if (!this.pageData)
181
- return;
182
- var newPath = getPath();
183
- var path = this.pageData.path;
184
- if (path !== newPath) {
185
- this.trackPage(newPath, false);
186
- }
187
- };
188
- Lib.prototype.getPreviousPage = function () {
189
- // Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
190
- // That method of getting previous page works for SPA websites
191
- if (this.activePage) {
192
- return this.activePage;
193
- }
194
- // Checking if URL is supported by the browser (for example, IE11 does not support it)
195
- if (typeof URL === 'function') {
196
- // That method of getting previous page works for websites with page reloads
197
- var referrer = getReferrer();
198
- if (!referrer) {
199
- return null;
200
- }
201
- var host = location.host;
202
- try {
203
- var url = new URL(referrer);
204
- var refHost = url.host, pathname = url.pathname;
205
- if (host !== refHost) {
206
- return null;
207
- }
208
- return pathname;
209
- }
210
- catch (_a) {
211
- return null;
212
- }
213
- }
214
- return null;
215
- };
216
- Lib.prototype.trackPage = function (pg, unique) {
217
- var _a;
218
- if (unique === void 0) { unique = false; }
219
- if (!this.pageData)
220
- return;
221
- this.pageData.path = pg;
222
- if (this.checkIgnore(pg))
223
- return;
224
- var perf = this.getPerformanceStats();
225
- var prev;
226
- if (!((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.noUserFlow)) {
227
- prev = this.getPreviousPage();
228
- }
229
- var data = {
230
- pid: this.projectID,
231
- lc: getLocale(),
232
- tz: getTimezone(),
233
- ref: getReferrer(),
234
- so: getUTMSource(),
235
- me: getUTMMedium(),
236
- ca: getUTMCampaign(),
237
- unique: unique,
238
- pg: pg,
239
- perf: perf,
240
- prev: prev,
241
- };
242
- this.activePage = pg;
243
- this.sendRequest('', data);
244
- };
245
- Lib.prototype.debug = function (message) {
246
- var _a;
247
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.debug) {
248
- console.log('[Swetrix]', message);
249
- }
250
- };
251
- Lib.prototype.canTrack = function () {
252
- var _a, _b, _c, _d;
253
- if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled) {
254
- this.debug('Tracking disabled: the \'disabled\' setting is set to true.');
255
- return false;
256
- }
257
- if (!isInBrowser()) {
258
- this.debug('Tracking disabled: script does not run in browser environment.');
259
- return false;
260
- }
261
- if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') {
262
- this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
263
- return false;
264
- }
265
- if (!((_d = this.options) === null || _d === void 0 ? void 0 : _d.debug) && isLocalhost()) {
266
- return false;
267
- }
268
- if (isAutomated()) {
269
- this.debug('Tracking disabled: navigation is automated by WebDriver.');
270
- return false;
271
- }
272
- return true;
273
- };
274
- Lib.prototype.sendRequest = function (path, body) {
275
- var _a;
276
- var host = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.apiURL) || DEFAULT_API_HOST;
277
- var req = new XMLHttpRequest();
278
- req.open('POST', "".concat(host, "/").concat(path), true);
279
- req.setRequestHeader('Content-Type', 'application/json');
280
- req.send(JSON.stringify(body));
281
- };
282
- return Lib;
76
+ var defaultPageActions = {
77
+ stop: function () { },
78
+ };
79
+ var DEFAULT_API_HOST = 'https://api.swetrix.com/log';
80
+ var Lib = /** @class */ (function () {
81
+ function Lib(projectID, options) {
82
+ this.projectID = projectID;
83
+ this.options = options;
84
+ this.pageData = null;
85
+ this.pageViewsOptions = null;
86
+ this.perfStatsCollected = false;
87
+ this.activePage = null;
88
+ this.trackPathChange = this.trackPathChange.bind(this);
89
+ this.heartbeat = this.heartbeat.bind(this);
90
+ }
91
+ Lib.prototype.track = function (event) {
92
+ if (!this.canTrack()) {
93
+ return;
94
+ }
95
+ var data = __assign({ pid: this.projectID, pg: this.activePage, lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign() }, event);
96
+ this.sendRequest('custom', data);
97
+ };
98
+ Lib.prototype.trackPageViews = function (options) {
99
+ if (!this.canTrack()) {
100
+ return defaultPageActions;
101
+ }
102
+ if (this.pageData) {
103
+ return this.pageData.actions;
104
+ }
105
+ this.pageViewsOptions = options;
106
+ var hbInterval, interval;
107
+ if (!(options === null || options === void 0 ? void 0 : options.unique)) {
108
+ interval = setInterval(this.trackPathChange, 2000);
109
+ }
110
+ if (!(options === null || options === void 0 ? void 0 : options.noHeartbeat)) {
111
+ setTimeout(this.heartbeat, 3000);
112
+ hbInterval = setInterval(this.heartbeat, 28000);
113
+ }
114
+ var path = getPath();
115
+ this.pageData = {
116
+ path: path,
117
+ actions: {
118
+ stop: function () {
119
+ clearInterval(interval);
120
+ clearInterval(hbInterval);
121
+ },
122
+ },
123
+ };
124
+ this.trackPage(path, options === null || options === void 0 ? void 0 : options.unique);
125
+ return this.pageData.actions;
126
+ };
127
+ Lib.prototype.getPerformanceStats = function () {
128
+ var _a;
129
+ if (!this.canTrack() || this.perfStatsCollected || !((_a = window.performance) === null || _a === void 0 ? void 0 : _a.getEntriesByType)) {
130
+ return {};
131
+ }
132
+ var perf = window.performance.getEntriesByType('navigation')[0];
133
+ if (!perf) {
134
+ return {};
135
+ }
136
+ this.perfStatsCollected = true;
137
+ return {
138
+ // Network
139
+ // @ts-ignore
140
+ dns: perf.domainLookupEnd - perf.domainLookupStart,
141
+ // @ts-ignore
142
+ tls: perf.secureConnectionStart ? perf.requestStart - perf.secureConnectionStart : 0,
143
+ // @ts-ignore
144
+ conn: perf.secureConnectionStart ? perf.secureConnectionStart - perf.connectStart : perf.connectEnd - perf.connectStart,
145
+ // @ts-ignore
146
+ response: perf.responseEnd - perf.responseStart,
147
+ // Frontend
148
+ // @ts-ignore
149
+ render: perf.domComplete - perf.domContentLoadedEventEnd,
150
+ // @ts-ignore
151
+ dom_load: perf.domContentLoadedEventEnd - perf.responseEnd,
152
+ // @ts-ignore
153
+ page_load: perf.loadEventStart,
154
+ // Backend
155
+ // @ts-ignore
156
+ ttfb: perf.responseStart - perf.requestStart,
157
+ };
158
+ };
159
+ Lib.prototype.heartbeat = function () {
160
+ var _a;
161
+ if (!((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.heartbeatOnBackground) && document.visibilityState === 'hidden') {
162
+ return;
163
+ }
164
+ var data = {
165
+ pid: this.projectID,
166
+ };
167
+ this.sendRequest('hb', data);
168
+ };
169
+ Lib.prototype.checkIgnore = function (path) {
170
+ var _a;
171
+ var ignore = (_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.ignore;
172
+ if (Array.isArray(ignore)) {
173
+ for (var i = 0; i < ignore.length; ++i) {
174
+ if (ignore[i] === path)
175
+ return true;
176
+ // @ts-ignore
177
+ if (ignore[i] instanceof RegExp && ignore[i].test(path))
178
+ return true;
179
+ }
180
+ }
181
+ return false;
182
+ };
183
+ // Tracking path changes. If path changes -> calling this.trackPage method
184
+ Lib.prototype.trackPathChange = function () {
185
+ if (!this.pageData)
186
+ return;
187
+ var newPath = getPath();
188
+ var path = this.pageData.path;
189
+ if (path !== newPath) {
190
+ this.trackPage(newPath, false);
191
+ }
192
+ };
193
+ Lib.prototype.getPreviousPage = function () {
194
+ var _a, _b;
195
+ // Assuming that this function is called in trackPage and this.activePage is not overwritten by new value yet
196
+ // That method of getting previous page works for SPA websites
197
+ if (this.activePage) {
198
+ var shouldIgnore = this.checkIgnore(this.activePage);
199
+ if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise)) {
200
+ return null;
201
+ }
202
+ return shouldIgnore ? null : this.activePage;
203
+ }
204
+ // Checking if URL is supported by the browser (for example, IE11 does not support it)
205
+ if (typeof URL === 'function') {
206
+ // That method of getting previous page works for websites with page reloads
207
+ var referrer = getReferrer();
208
+ if (!referrer) {
209
+ return null;
210
+ }
211
+ var host = location.host;
212
+ try {
213
+ var url = new URL(referrer);
214
+ var refHost = url.host, pathname = url.pathname;
215
+ if (host !== refHost) {
216
+ return null;
217
+ }
218
+ var shouldIgnore = this.checkIgnore(pathname);
219
+ if (shouldIgnore && ((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.doNotAnonymise)) {
220
+ return null;
221
+ }
222
+ return shouldIgnore ? null : pathname;
223
+ }
224
+ catch (_c) {
225
+ return null;
226
+ }
227
+ }
228
+ return null;
229
+ };
230
+ Lib.prototype.trackPage = function (pg, unique) {
231
+ var _a, _b;
232
+ if (unique === void 0) { unique = false; }
233
+ if (!this.pageData)
234
+ return;
235
+ this.pageData.path = pg;
236
+ var shouldIgnore = this.checkIgnore(pg);
237
+ if (shouldIgnore && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.doNotAnonymise))
238
+ return;
239
+ var perf = this.getPerformanceStats();
240
+ var prev;
241
+ if (!((_b = this.pageViewsOptions) === null || _b === void 0 ? void 0 : _b.noUserFlow)) {
242
+ prev = this.getPreviousPage();
243
+ }
244
+ var data = {
245
+ pid: this.projectID,
246
+ lc: getLocale(),
247
+ tz: getTimezone(),
248
+ ref: getReferrer(),
249
+ so: getUTMSource(),
250
+ me: getUTMMedium(),
251
+ ca: getUTMCampaign(),
252
+ unique: unique,
253
+ pg: shouldIgnore ? null : pg,
254
+ perf: perf,
255
+ prev: prev,
256
+ };
257
+ this.activePage = pg;
258
+ this.sendRequest('', data);
259
+ };
260
+ Lib.prototype.debug = function (message) {
261
+ var _a;
262
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.debug) {
263
+ console.log('[Swetrix]', message);
264
+ }
265
+ };
266
+ Lib.prototype.canTrack = function () {
267
+ var _a, _b, _c, _d;
268
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.disabled) {
269
+ this.debug('Tracking disabled: the \'disabled\' setting is set to true.');
270
+ return false;
271
+ }
272
+ if (!isInBrowser()) {
273
+ this.debug('Tracking disabled: script does not run in browser environment.');
274
+ return false;
275
+ }
276
+ if (((_b = this.options) === null || _b === void 0 ? void 0 : _b.respectDNT) && ((_c = window.navigator) === null || _c === void 0 ? void 0 : _c.doNotTrack) === '1') {
277
+ this.debug('Tracking disabled: respecting user\'s \'Do Not Track\' preference.');
278
+ return false;
279
+ }
280
+ if (!((_d = this.options) === null || _d === void 0 ? void 0 : _d.debug) && isLocalhost()) {
281
+ return false;
282
+ }
283
+ if (isAutomated()) {
284
+ this.debug('Tracking disabled: navigation is automated by WebDriver.');
285
+ return false;
286
+ }
287
+ return true;
288
+ };
289
+ Lib.prototype.sendRequest = function (path, body) {
290
+ var _a;
291
+ var host = ((_a = this.options) === null || _a === void 0 ? void 0 : _a.apiURL) || DEFAULT_API_HOST;
292
+ var req = new XMLHttpRequest();
293
+ req.open('POST', "".concat(host, "/").concat(path), true);
294
+ req.setRequestHeader('Content-Type', 'application/json');
295
+ req.send(JSON.stringify(body));
296
+ };
297
+ return Lib;
283
298
  }());
284
299
 
285
- exports.LIB_INSTANCE = null;
286
- /**
287
- * Initialise the tracking library instance (other methods won't work if the library is not initialised).
288
- *
289
- * @param {string} pid The Project ID to link the instance of Swetrix.js to.
290
- * @param {LibOptions} options Options related to the tracking.
291
- * @returns {Lib} Instance of the Swetrix.js.
292
- */
293
- function init(pid, options) {
294
- if (!exports.LIB_INSTANCE) {
295
- exports.LIB_INSTANCE = new Lib(pid, options);
296
- }
297
- return exports.LIB_INSTANCE;
298
- }
299
- /**
300
- * With this function you are able to track any custom events you want.
301
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
302
- * The total number of track calls and their conversion rate will be saved.
303
- *
304
- * @param {TrackEventOptions} event The options related to the custom event.
305
- */
306
- function track(event) {
307
- if (!exports.LIB_INSTANCE)
308
- return;
309
- exports.LIB_INSTANCE.track(event);
310
- }
311
- /**
312
- * With this function you are able to track any custom events you want.
313
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
314
- * The total number of track calls and their conversion rate will be saved.
315
- *
316
- * @param {PageViewsOptions} options The options related to the custom event.
317
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
318
- */
319
- function trackViews(options) {
320
- return new Promise(function (resolve) {
321
- if (!exports.LIB_INSTANCE) {
322
- resolve(defaultPageActions);
323
- return;
324
- }
325
- // We need to verify that document.readyState is complete for the performance stats to be collected correctly.
326
- if (typeof document === 'undefined' || document.readyState === 'complete') {
327
- resolve(exports.LIB_INSTANCE.trackPageViews(options));
328
- }
329
- else {
330
- window.addEventListener('load', function () {
331
- // @ts-ignore
332
- resolve(exports.LIB_INSTANCE.trackPageViews(options));
333
- });
334
- }
335
- });
300
+ exports.LIB_INSTANCE = null;
301
+ /**
302
+ * Initialise the tracking library instance (other methods won't work if the library is not initialised).
303
+ *
304
+ * @param {string} pid The Project ID to link the instance of Swetrix.js to.
305
+ * @param {LibOptions} options Options related to the tracking.
306
+ * @returns {Lib} Instance of the Swetrix.js.
307
+ */
308
+ function init(pid, options) {
309
+ if (!exports.LIB_INSTANCE) {
310
+ exports.LIB_INSTANCE = new Lib(pid, options);
311
+ }
312
+ return exports.LIB_INSTANCE;
313
+ }
314
+ /**
315
+ * With this function you are able to track any custom events you want.
316
+ * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
317
+ * The total number of track calls and their conversion rate will be saved.
318
+ *
319
+ * @param {TrackEventOptions} event The options related to the custom event.
320
+ */
321
+ function track(event) {
322
+ if (!exports.LIB_INSTANCE)
323
+ return;
324
+ exports.LIB_INSTANCE.track(event);
325
+ }
326
+ /**
327
+ * With this function you are able to track any custom events you want.
328
+ * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
329
+ * The total number of track calls and their conversion rate will be saved.
330
+ *
331
+ * @param {PageViewsOptions} options The options related to the custom event.
332
+ * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
333
+ */
334
+ function trackViews(options) {
335
+ return new Promise(function (resolve) {
336
+ if (!exports.LIB_INSTANCE) {
337
+ resolve(defaultPageActions);
338
+ return;
339
+ }
340
+ // We need to verify that document.readyState is complete for the performance stats to be collected correctly.
341
+ if (typeof document === 'undefined' || document.readyState === 'complete') {
342
+ resolve(exports.LIB_INSTANCE.trackPageViews(options));
343
+ }
344
+ else {
345
+ window.addEventListener('load', function () {
346
+ // @ts-ignore
347
+ resolve(exports.LIB_INSTANCE.trackPageViews(options));
348
+ });
349
+ }
350
+ });
336
351
  }
337
352
 
338
353
  exports.init = init;