swetrix 3.1.1 → 3.2.1

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
@@ -1,4 +1,8 @@
1
- <img src="https://swetrix.com/assets/logo_blue.png" alt="" height="80" />
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset="https://swetrix.com/assets/logo_white.png">
3
+ <img alt="" src="https://swetrix.com/assets/logo_blue.png" height="80">
4
+ </picture>
5
+ <br /><br />
2
6
 
3
7
  [![JSDelivr hits](https://data.jsdelivr.com/v1/package/gh/Swetrix/swetrix-js/badge?style=rounded)](https://data.jsdelivr.com/v1/package/gh/Swetrix/swetrix-js/stats)
4
8
  [![Package size](https://img.shields.io/bundlephobia/minzip/swetrix)](https://bundlephobia.com/api/size?package=swetrix)
@@ -34,6 +34,10 @@ export interface IPageViewPayload {
34
34
  ca: string | undefined;
35
35
  pg: string | null | undefined;
36
36
  prev: string | null | undefined;
37
+ /** Pageview-related metadata object with string values. */
38
+ meta?: {
39
+ [key: string]: string;
40
+ };
37
41
  }
38
42
  export interface IErrorEventPayload {
39
43
  name: string;
@@ -143,7 +147,7 @@ export declare class Lib {
143
147
  private trackPathChange;
144
148
  private getPreviousPage;
145
149
  private trackPage;
146
- submitPageView(pg: string, prev: string | null | undefined, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
150
+ submitPageView(payload: Partial<IPageViewPayload>, unique: boolean, perf: IPerfPayload | {}, evokeCallback?: boolean): void;
147
151
  private canTrack;
148
152
  private sendRequest;
149
153
  }
@@ -202,11 +202,11 @@ export class Lib {
202
202
  return;
203
203
  this.pageData.path = pg;
204
204
  const perf = this.getPerformanceStats();
205
- const prev = this.getPreviousPage();
206
205
  this.activePage = pg;
207
- this.submitPageView(pg, prev, unique, perf, true);
206
+ this.submitPageView({ pg }, unique, perf, true);
208
207
  }
209
- submitPageView(pg, prev, unique, perf, evokeCallback) {
208
+ submitPageView(payload, unique, perf, evokeCallback) {
209
+ const prev = this.getPreviousPage();
210
210
  const privateData = {
211
211
  pid: this.projectID,
212
212
  perf,
@@ -219,8 +219,8 @@ export class Lib {
219
219
  so: getUTMSource(),
220
220
  me: getUTMMedium(),
221
221
  ca: getUTMCampaign(),
222
- pg,
223
222
  prev,
223
+ ...payload,
224
224
  };
225
225
  if (evokeCallback && this.pageViewsOptions?.callback) {
226
226
  const callbackResult = this.pageViewsOptions.callback(pvPayload);
@@ -1 +1 @@
1
- {"version":3,"file":"Lib.js","sourceRoot":"","sources":["../../src/Lib.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,WAAW,EACX,SAAS,EACT,WAAW,EACX,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,OAAO,GACR,MAAM,SAAS,CAAA;AAoJhB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,KAAI,CAAC;CACV,CAAA;AAED,MAAM,gBAAgB,GAAG,6BAA6B,CAAA;AAEtD,MAAM,OAAO,GAAG;IAQd,YAAoB,SAAiB,EAAU,OAAoB;QAA/C,cAAS,GAAT,SAAS,CAAQ;QAAU,YAAO,GAAP,OAAO,CAAa;QAP3D,aAAQ,GAAoB,IAAI,CAAA;QAChC,qBAAgB,GAAwC,IAAI,CAAA;QAC5D,kBAAa,GAAoC,IAAI,CAAA;QACrD,uBAAkB,GAAY,KAAK,CAAA;QACnC,eAAU,GAAkB,IAAI,CAAA;QAChC,wBAAmB,GAAG,KAAK,CAAA;QAGjC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAClD,CAAC;IAED,YAAY,CAAC,KA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Options, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload } from './Lib';
1
+ import { Lib, LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload } from './Lib';
2
2
  export declare let LIB_INSTANCE: Lib | null;
3
3
  /**
4
4
  * Initialise the tracking library instance (other methods won't work if the library is not initialised).
@@ -24,12 +24,10 @@ export declare function track(event: TrackEventOptions): void;
24
24
  */
25
25
  export declare function trackViews(options?: PageViewsOptions): Promise<PageActions>;
26
26
  /**
27
- * With this function you are able to track any custom events you want.
28
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
29
- * The total number of track calls and their conversion rate will be saved.
27
+ * This function is used to set up automatic error events tracking.
28
+ * It set's up an error listener, and whenever an error happens, it gets tracked.
30
29
  *
31
- * @param {PageViewsOptions} options The options related to the custom event.
32
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
30
+ * @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
33
31
  */
34
32
  export declare function trackErrors(options?: ErrorOptions): ErrorActions;
35
33
  /**
@@ -44,9 +42,16 @@ export declare function trackError(payload: IErrorEventPayload): void;
44
42
  * This function is used to manually track a page view event.
45
43
  * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
46
44
  *
47
- * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
45
+ * @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
46
+ * @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
48
47
  * @param prev Path of the previous page.
49
48
  * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
50
49
  * @returns void
51
50
  */
52
- export declare function trackPageview(path: string, prev?: string, unique?: boolean): void;
51
+ export declare function trackPageview(pg: string, prev?: string, unique?: boolean): void;
52
+ export interface IPageviewOptions {
53
+ payload: Partial<IPageViewPayload>;
54
+ unique?: boolean;
55
+ }
56
+ export declare function pageview(options: IPageviewOptions): void;
57
+ export { LibOptions, TrackEventOptions, PageViewsOptions, ErrorOptions, PageActions, ErrorActions, IErrorEventPayload, IPageViewPayload, };
@@ -50,12 +50,10 @@ export function trackViews(options) {
50
50
  });
51
51
  }
52
52
  /**
53
- * With this function you are able to track any custom events you want.
54
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
55
- * The total number of track calls and their conversion rate will be saved.
53
+ * This function is used to set up automatic error events tracking.
54
+ * It set's up an error listener, and whenever an error happens, it gets tracked.
56
55
  *
57
- * @param {PageViewsOptions} options The options related to the custom event.
58
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
56
+ * @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
59
57
  */
60
58
  export function trackErrors(options) {
61
59
  if (!LIB_INSTANCE) {
@@ -79,14 +77,20 @@ export function trackError(payload) {
79
77
  * This function is used to manually track a page view event.
80
78
  * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
81
79
  *
82
- * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
80
+ * @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
81
+ * @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
83
82
  * @param prev Path of the previous page.
84
83
  * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
85
84
  * @returns void
86
85
  */
87
- export function trackPageview(path, prev, unique) {
86
+ export function trackPageview(pg, prev, unique) {
87
+ if (!LIB_INSTANCE)
88
+ return;
89
+ LIB_INSTANCE.submitPageView({ pg, prev: prev || null }, Boolean(unique), {});
90
+ }
91
+ export function pageview(options) {
88
92
  if (!LIB_INSTANCE)
89
93
  return;
90
- LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
94
+ LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
91
95
  }
92
96
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,E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Data.path = pg;
292
292
  var perf = this.getPerformanceStats();
293
- var prev = this.getPreviousPage();
294
293
  this.activePage = pg;
295
- this.submitPageView(pg, prev, unique, perf, true);
294
+ this.submitPageView({ pg: pg }, unique, perf, true);
296
295
  };
297
- Lib.prototype.submitPageView = function (pg, prev, unique, perf, evokeCallback) {
296
+ Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
298
297
  var _a;
298
+ var prev = this.getPreviousPage();
299
299
  var privateData = {
300
300
  pid: this.projectID,
301
301
  perf: perf,
302
302
  unique: unique,
303
303
  };
304
- var pvPayload = {
305
- lc: getLocale(),
306
- tz: getTimezone(),
307
- ref: getReferrer(),
308
- so: getUTMSource(),
309
- me: getUTMMedium(),
310
- ca: getUTMCampaign(),
311
- pg: pg,
312
- prev: prev,
313
- };
304
+ var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), prev: prev }, payload);
314
305
  if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
315
306
  var callbackResult = this.pageViewsOptions.callback(pvPayload);
316
307
  if (callbackResult === false) {
@@ -396,12 +387,10 @@ function trackViews(options) {
396
387
  });
397
388
  }
398
389
  /**
399
- * With this function you are able to track any custom events you want.
400
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
401
- * The total number of track calls and their conversion rate will be saved.
390
+ * This function is used to set up automatic error events tracking.
391
+ * It set's up an error listener, and whenever an error happens, it gets tracked.
402
392
  *
403
- * @param {PageViewsOptions} options The options related to the custom event.
404
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
393
+ * @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
405
394
  */
406
395
  function trackErrors(options) {
407
396
  if (!exports.LIB_INSTANCE) {
@@ -425,18 +414,25 @@ function trackError(payload) {
425
414
  * This function is used to manually track a page view event.
426
415
  * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
427
416
  *
428
- * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
417
+ * @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
418
+ * @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
429
419
  * @param prev Path of the previous page.
430
420
  * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
431
421
  * @returns void
432
422
  */
433
- function trackPageview(path, prev, unique) {
423
+ function trackPageview(pg, prev, unique) {
424
+ if (!exports.LIB_INSTANCE)
425
+ return;
426
+ exports.LIB_INSTANCE.submitPageView({ pg: pg, prev: prev || null }, Boolean(unique), {});
427
+ }
428
+ function pageview(options) {
434
429
  if (!exports.LIB_INSTANCE)
435
430
  return;
436
- exports.LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
431
+ exports.LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
437
432
  }
438
433
 
439
434
  exports.init = init;
435
+ exports.pageview = pageview;
440
436
  exports.track = track;
441
437
  exports.trackError = trackError;
442
438
  exports.trackErrors = trackErrors;
@@ -286,27 +286,18 @@ var Lib = /** @class */ (function () {
286
286
  return;
287
287
  this.pageData.path = pg;
288
288
  var perf = this.getPerformanceStats();
289
- var prev = this.getPreviousPage();
290
289
  this.activePage = pg;
291
- this.submitPageView(pg, prev, unique, perf, true);
290
+ this.submitPageView({ pg: pg }, unique, perf, true);
292
291
  };
293
- Lib.prototype.submitPageView = function (pg, prev, unique, perf, evokeCallback) {
292
+ Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
294
293
  var _a;
294
+ var prev = this.getPreviousPage();
295
295
  var privateData = {
296
296
  pid: this.projectID,
297
297
  perf: perf,
298
298
  unique: unique,
299
299
  };
300
- var pvPayload = {
301
- lc: getLocale(),
302
- tz: getTimezone(),
303
- ref: getReferrer(),
304
- so: getUTMSource(),
305
- me: getUTMMedium(),
306
- ca: getUTMCampaign(),
307
- pg: pg,
308
- prev: prev,
309
- };
300
+ var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), prev: prev }, payload);
310
301
  if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
311
302
  var callbackResult = this.pageViewsOptions.callback(pvPayload);
312
303
  if (callbackResult === false) {
@@ -392,12 +383,10 @@ function trackViews(options) {
392
383
  });
393
384
  }
394
385
  /**
395
- * With this function you are able to track any custom events you want.
396
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
397
- * The total number of track calls and their conversion rate will be saved.
386
+ * This function is used to set up automatic error events tracking.
387
+ * It set's up an error listener, and whenever an error happens, it gets tracked.
398
388
  *
399
- * @param {PageViewsOptions} options The options related to the custom event.
400
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
389
+ * @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
401
390
  */
402
391
  function trackErrors(options) {
403
392
  if (!LIB_INSTANCE) {
@@ -421,15 +410,21 @@ function trackError(payload) {
421
410
  * This function is used to manually track a page view event.
422
411
  * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
423
412
  *
424
- * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
413
+ * @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
414
+ * @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
425
415
  * @param prev Path of the previous page.
426
416
  * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
427
417
  * @returns void
428
418
  */
429
- function trackPageview(path, prev, unique) {
419
+ function trackPageview(pg, prev, unique) {
420
+ if (!LIB_INSTANCE)
421
+ return;
422
+ LIB_INSTANCE.submitPageView({ pg: pg, prev: prev || null }, Boolean(unique), {});
423
+ }
424
+ function pageview(options) {
430
425
  if (!LIB_INSTANCE)
431
426
  return;
432
- LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
427
+ LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
433
428
  }
434
429
 
435
- export { LIB_INSTANCE, init, track, trackError, trackErrors, trackPageview, trackViews };
430
+ export { LIB_INSTANCE, init, pageview, track, trackError, trackErrors, trackPageview, trackViews };
package/dist/swetrix.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).swetrix={})}(this,function(o){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}function r(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language}function a(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function s(){return document.referrer||void 0}function c(){return t(e)}function u(){return t(p)}function l(){return t(n)}function i(t){var e,n=location.pathname||"";return t.hash&&(n+=-1<(e=location.hash.indexOf("?"))?location.hash.substring(0,e):location.hash),t.search&&(e=location.hash.indexOf("?"),n+=location.search||(-1<e?location.hash.substring(e):"")),n}var h=function(){return(h=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},e=/[?&](ref|source|utm_source)=([^?&]+)/,n=/[?&](utm_campaign)=([^?&]+)/,p=/[?&](utm_medium)=([^?&]+)/,d={stop:function(){}},f=(g.prototype.captureError=function(t){var e;"number"==typeof(null==(e=this.errorsOptions)?void 0:e.sampleRate)&&this.errorsOptions.sampleRate>Math.random()||this.submitError({filename:t.filename,lineno:t.lineno,colno:t.colno,name:(null==(e=t.error)?void 0:e.name)||"Error",message:(null==(e=t.error)?void 0:e.message)||t.message},!0)},g.prototype.trackErrors=function(t){var e=this;return this.errorListenerExists||!this.canTrack()?d:(this.errorsOptions=t,window.addEventListener("error",this.captureError),this.errorListenerExists=!0,{stop:function(){window.removeEventListener("error",e.captureError)}})},g.prototype.submitError=function(t,e){var n={pid:this.projectID},o=h({pg:this.activePage||i({hash:null==(o=this.pageViewsOptions)?void 0:o.hash,search:null==(o=this.pageViewsOptions)?void 0:o.search}),lc:r(),tz:a()},t);if(e&&null!=(t=this.errorsOptions)&&t.callback){e=this.errorsOptions.callback(o);if(!1===e)return;e&&"object"==typeof e&&Object.assign(o,e)}Object.assign(o,n),this.sendRequest("error",o)},g.prototype.track=function(t){this.canTrack()&&(t=h(h({},t),{pid:this.projectID,pg:this.activePage,lc:r(),tz:a(),ref:s(),so:c(),me:u(),ca:l()}),this.sendRequest("custom",t))},g.prototype.trackPageViews=function(t){var e,n,o;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(e=setInterval(this.trackPathChange,2e3)),setTimeout(this.heartbeat,3e3),n=setInterval(this.heartbeat,28e3),o=i({hash:null==t?void 0:t.hash,search:null==t?void 0:t.search}),this.pageData={path:o,actions:{stop:function(){clearInterval(e),clearInterval(n)}}},this.trackPage(o,null==t?void 0:t.unique)),this.pageData.actions):d},g.prototype.getPerformanceStats=function(){var t;return this.canTrack()&&!this.perfStatsCollected&&null!=(t=window.performance)&&t.getEntriesByType&&(t=window.performance.getEntriesByType("navigation")[0])?(this.perfStatsCollected=!0,{dns:t.domainLookupEnd-t.domainLookupStart,tls:t.secureConnectionStart?t.requestStart-t.secureConnectionStart:0,conn:t.secureConnectionStart?t.secureConnectionStart-t.connectStart:t.connectEnd-t.connectStart,response:t.responseEnd-t.responseStart,render:t.domComplete-t.domContentLoadedEventEnd,dom_load:t.domContentLoadedEventEnd-t.responseEnd,page_load:t.loadEventStart,ttfb:t.responseStart-t.requestStart}):{}},g.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},g.prototype.trackPathChange=function(){var t;this.pageData&&(t=i({hash:null==(t=this.pageViewsOptions)?void 0:t.hash,search:null==(t=this.pageViewsOptions)?void 0:t.search}),this.pageData.path!==t)&&this.trackPage(t,!1)},g.prototype.getPreviousPage=function(){if(this.activePage)return this.activePage;if("function"==typeof URL){var t=s();if(!t)return null;var e=location.host;try{var n=new URL(t),o=n.host,i=n.pathname;return e!==o?null:i}catch(t){}}return null},g.prototype.trackPage=function(t,e){var n,o;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,n=this.getPerformanceStats(),o=this.getPreviousPage(),this.activePage=t,this.submitPageView(t,o,e,n,!0))},g.prototype.submitPageView=function(t,e,n,o,i){o={pid:this.projectID,perf:o,unique:n},n={lc:r(),tz:a(),ref:s(),so:c(),me:u(),ca:l(),pg:t,prev:e};if(i&&null!=(t=this.pageViewsOptions)&&t.callback){e=this.pageViewsOptions.callback(n);if(!1===e)return;e&&"object"==typeof e&&Object.assign(n,e)}Object.assign(n,o),this.sendRequest("",n)},g.prototype.canTrack=function(){var t;return!(null!=(t=this.options)&&t.disabled||"undefined"==typeof window||null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)||(null==(t=this.options)||!t.devMode)&&("localhost"===(null===location||void 0===location?void 0:location.hostname)||"127.0.0.1"===(null===location||void 0===location?void 0:location.hostname)||""===(null===location||void 0===location?void 0:location.hostname))||null!==navigator&&void 0!==navigator&&navigator.webdriver)},g.prototype.sendRequest=function(t,e){var n=(null==(n=this.options)?void 0:n.apiURL)||"https://api.swetrix.com/log",o=new XMLHttpRequest;o.open("POST","".concat(n,"/").concat(t),!0),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify(e))},g);function g(t,e){this.projectID=t,this.options=e,this.pageData=null,this.pageViewsOptions=null,this.errorsOptions=null,this.perfStatsCollected=!1,this.activePage=null,this.errorListenerExists=!1,this.trackPathChange=this.trackPathChange.bind(this),this.heartbeat=this.heartbeat.bind(this),this.captureError=this.captureError.bind(this)}o.LIB_INSTANCE=null,o.init=function(t,e){return o.LIB_INSTANCE||(o.LIB_INSTANCE=new f(t,e)),o.LIB_INSTANCE},o.track=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.track(t)},o.trackError=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitError(t,!1)},o.trackErrors=function(t){return o.LIB_INSTANCE?o.LIB_INSTANCE.trackErrors(t):d},o.trackPageview=function(t,e,n){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView(t,e||null,Boolean(n),{})},o.trackViews=function(e){return new Promise(function(t){o.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(o.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(o.LIB_INSTANCE.trackPageViews(e))}):t(d)})},Object.defineProperty(o,"__esModule",{value:!0})});
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).swetrix={})}(this,function(o){"use strict";function t(t){return(t=location.search.match(t))&&t[2]||void 0}function r(){return void 0!==navigator.languages?navigator.languages[0]:navigator.language}function a(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch(t){}}function s(){return document.referrer||void 0}function c(){return t(e)}function u(){return t(p)}function l(){return t(n)}function i(t){var e,n=location.pathname||"";return t.hash&&(n+=-1<(e=location.hash.indexOf("?"))?location.hash.substring(0,e):location.hash),t.search&&(e=location.hash.indexOf("?"),n+=location.search||(-1<e?location.hash.substring(e):"")),n}var h=function(){return(h=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},e=/[?&](ref|source|utm_source)=([^?&]+)/,n=/[?&](utm_campaign)=([^?&]+)/,p=/[?&](utm_medium)=([^?&]+)/,d={stop:function(){}},f=(g.prototype.captureError=function(t){var e;"number"==typeof(null==(e=this.errorsOptions)?void 0:e.sampleRate)&&this.errorsOptions.sampleRate>Math.random()||this.submitError({filename:t.filename,lineno:t.lineno,colno:t.colno,name:(null==(e=t.error)?void 0:e.name)||"Error",message:(null==(e=t.error)?void 0:e.message)||t.message},!0)},g.prototype.trackErrors=function(t){var e=this;return this.errorListenerExists||!this.canTrack()?d:(this.errorsOptions=t,window.addEventListener("error",this.captureError),this.errorListenerExists=!0,{stop:function(){window.removeEventListener("error",e.captureError)}})},g.prototype.submitError=function(t,e){var n={pid:this.projectID},o=h({pg:this.activePage||i({hash:null==(o=this.pageViewsOptions)?void 0:o.hash,search:null==(o=this.pageViewsOptions)?void 0:o.search}),lc:r(),tz:a()},t);if(e&&null!=(t=this.errorsOptions)&&t.callback){e=this.errorsOptions.callback(o);if(!1===e)return;e&&"object"==typeof e&&Object.assign(o,e)}Object.assign(o,n),this.sendRequest("error",o)},g.prototype.track=function(t){this.canTrack()&&(t=h(h({},t),{pid:this.projectID,pg:this.activePage,lc:r(),tz:a(),ref:s(),so:c(),me:u(),ca:l()}),this.sendRequest("custom",t))},g.prototype.trackPageViews=function(t){var e,n,o;return this.canTrack()?(this.pageData||(null!=(this.pageViewsOptions=t)&&t.unique||(e=setInterval(this.trackPathChange,2e3)),setTimeout(this.heartbeat,3e3),n=setInterval(this.heartbeat,28e3),o=i({hash:null==t?void 0:t.hash,search:null==t?void 0:t.search}),this.pageData={path:o,actions:{stop:function(){clearInterval(e),clearInterval(n)}}},this.trackPage(o,null==t?void 0:t.unique)),this.pageData.actions):d},g.prototype.getPerformanceStats=function(){var t;return this.canTrack()&&!this.perfStatsCollected&&null!=(t=window.performance)&&t.getEntriesByType&&(t=window.performance.getEntriesByType("navigation")[0])?(this.perfStatsCollected=!0,{dns:t.domainLookupEnd-t.domainLookupStart,tls:t.secureConnectionStart?t.requestStart-t.secureConnectionStart:0,conn:t.secureConnectionStart?t.secureConnectionStart-t.connectStart:t.connectEnd-t.connectStart,response:t.responseEnd-t.responseStart,render:t.domComplete-t.domContentLoadedEventEnd,dom_load:t.domContentLoadedEventEnd-t.responseEnd,page_load:t.loadEventStart,ttfb:t.responseStart-t.requestStart}):{}},g.prototype.heartbeat=function(){var t;(null!=(t=this.pageViewsOptions)&&t.heartbeatOnBackground||"hidden"!==document.visibilityState)&&(t={pid:this.projectID},this.sendRequest("hb",t))},g.prototype.trackPathChange=function(){var t;this.pageData&&(t=i({hash:null==(t=this.pageViewsOptions)?void 0:t.hash,search:null==(t=this.pageViewsOptions)?void 0:t.search}),this.pageData.path!==t)&&this.trackPage(t,!1)},g.prototype.getPreviousPage=function(){if(this.activePage)return this.activePage;if("function"==typeof URL){var t=s();if(!t)return null;var e=location.host;try{var n=new URL(t),o=n.host,i=n.pathname;return e!==o?null:i}catch(t){}}return null},g.prototype.trackPage=function(t,e){var n;void 0===e&&(e=!1),this.pageData&&(this.pageData.path=t,n=this.getPerformanceStats(),this.activePage=t,this.submitPageView({pg:t},e,n,!0))},g.prototype.submitPageView=function(t,e,n,o){var i=this.getPreviousPage(),n={pid:this.projectID,perf:n,unique:e},e=h({lc:r(),tz:a(),ref:s(),so:c(),me:u(),ca:l(),prev:i},t);if(o&&null!=(i=this.pageViewsOptions)&&i.callback){t=this.pageViewsOptions.callback(e);if(!1===t)return;t&&"object"==typeof t&&Object.assign(e,t)}Object.assign(e,n),this.sendRequest("",e)},g.prototype.canTrack=function(){var t;return!(null!=(t=this.options)&&t.disabled||"undefined"==typeof window||null!=(t=this.options)&&t.respectDNT&&"1"===(null==(t=window.navigator)?void 0:t.doNotTrack)||(null==(t=this.options)||!t.devMode)&&("localhost"===(null===location||void 0===location?void 0:location.hostname)||"127.0.0.1"===(null===location||void 0===location?void 0:location.hostname)||""===(null===location||void 0===location?void 0:location.hostname))||null!==navigator&&void 0!==navigator&&navigator.webdriver)},g.prototype.sendRequest=function(t,e){var n=(null==(n=this.options)?void 0:n.apiURL)||"https://api.swetrix.com/log",o=new XMLHttpRequest;o.open("POST","".concat(n,"/").concat(t),!0),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify(e))},g);function g(t,e){this.projectID=t,this.options=e,this.pageData=null,this.pageViewsOptions=null,this.errorsOptions=null,this.perfStatsCollected=!1,this.activePage=null,this.errorListenerExists=!1,this.trackPathChange=this.trackPathChange.bind(this),this.heartbeat=this.heartbeat.bind(this),this.captureError=this.captureError.bind(this)}o.LIB_INSTANCE=null,o.init=function(t,e){return o.LIB_INSTANCE||(o.LIB_INSTANCE=new f(t,e)),o.LIB_INSTANCE},o.pageview=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView(t.payload,Boolean(t.unique),{})},o.track=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.track(t)},o.trackError=function(t){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitError(t,!1)},o.trackErrors=function(t){return o.LIB_INSTANCE?o.LIB_INSTANCE.trackErrors(t):d},o.trackPageview=function(t,e,n){o.LIB_INSTANCE&&o.LIB_INSTANCE.submitPageView({pg:t,prev:e||null},Boolean(n),{})},o.trackViews=function(e){return new Promise(function(t){o.LIB_INSTANCE?"undefined"==typeof document||"complete"===document.readyState?t(o.LIB_INSTANCE.trackPageViews(e)):window.addEventListener("load",function(){t(o.LIB_INSTANCE.trackPageViews(e))}):t(d)})},Object.defineProperty(o,"__esModule",{value:!0})});
@@ -292,27 +292,18 @@
292
292
  return;
293
293
  this.pageData.path = pg;
294
294
  var perf = this.getPerformanceStats();
295
- var prev = this.getPreviousPage();
296
295
  this.activePage = pg;
297
- this.submitPageView(pg, prev, unique, perf, true);
296
+ this.submitPageView({ pg: pg }, unique, perf, true);
298
297
  };
299
- Lib.prototype.submitPageView = function (pg, prev, unique, perf, evokeCallback) {
298
+ Lib.prototype.submitPageView = function (payload, unique, perf, evokeCallback) {
300
299
  var _a;
300
+ var prev = this.getPreviousPage();
301
301
  var privateData = {
302
302
  pid: this.projectID,
303
303
  perf: perf,
304
304
  unique: unique,
305
305
  };
306
- var pvPayload = {
307
- lc: getLocale(),
308
- tz: getTimezone(),
309
- ref: getReferrer(),
310
- so: getUTMSource(),
311
- me: getUTMMedium(),
312
- ca: getUTMCampaign(),
313
- pg: pg,
314
- prev: prev,
315
- };
306
+ var pvPayload = __assign({ lc: getLocale(), tz: getTimezone(), ref: getReferrer(), so: getUTMSource(), me: getUTMMedium(), ca: getUTMCampaign(), prev: prev }, payload);
316
307
  if (evokeCallback && ((_a = this.pageViewsOptions) === null || _a === void 0 ? void 0 : _a.callback)) {
317
308
  var callbackResult = this.pageViewsOptions.callback(pvPayload);
318
309
  if (callbackResult === false) {
@@ -398,12 +389,10 @@
398
389
  });
399
390
  }
400
391
  /**
401
- * With this function you are able to track any custom events you want.
402
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
403
- * The total number of track calls and their conversion rate will be saved.
392
+ * This function is used to set up automatic error events tracking.
393
+ * It set's up an error listener, and whenever an error happens, it gets tracked.
404
394
  *
405
- * @param {PageViewsOptions} options The options related to the custom event.
406
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
395
+ * @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
407
396
  */
408
397
  function trackErrors(options) {
409
398
  if (!exports.LIB_INSTANCE) {
@@ -427,18 +416,25 @@
427
416
  * This function is used to manually track a page view event.
428
417
  * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
429
418
  *
430
- * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
419
+ * @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
420
+ * @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
431
421
  * @param prev Path of the previous page.
432
422
  * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
433
423
  * @returns void
434
424
  */
435
- function trackPageview(path, prev, unique) {
425
+ function trackPageview(pg, prev, unique) {
426
+ if (!exports.LIB_INSTANCE)
427
+ return;
428
+ exports.LIB_INSTANCE.submitPageView({ pg: pg, prev: prev || null }, Boolean(unique), {});
429
+ }
430
+ function pageview(options) {
436
431
  if (!exports.LIB_INSTANCE)
437
432
  return;
438
- exports.LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {});
433
+ exports.LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {});
439
434
  }
440
435
 
441
436
  exports.init = init;
437
+ exports.pageview = pageview;
442
438
  exports.track = track;
443
439
  exports.trackError = trackError;
444
440
  exports.trackErrors = trackErrors;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swetrix",
3
- "version": "3.1.1",
3
+ "version": "3.2.1",
4
4
  "description": "The JavaScript analytics client for Swetrix Analytics",
5
5
  "main": "dist/swetrix.cjs.js",
6
6
  "module": "dist/swetrix.es5.js",
package/src/Lib.ts CHANGED
@@ -55,6 +55,11 @@ export interface IPageViewPayload {
55
55
  ca: string | undefined
56
56
  pg: string | null | undefined
57
57
  prev: string | null | undefined
58
+
59
+ /** Pageview-related metadata object with string values. */
60
+ meta?: {
61
+ [key: string]: string
62
+ }
58
63
  }
59
64
 
60
65
  // Partial user-editable error payload
@@ -412,24 +417,23 @@ export class Lib {
412
417
 
413
418
  const perf = this.getPerformanceStats()
414
419
 
415
- const prev = this.getPreviousPage()
416
-
417
420
  this.activePage = pg
418
- this.submitPageView(pg, prev, unique, perf, true)
421
+ this.submitPageView({ pg }, unique, perf, true)
419
422
  }
420
423
 
421
424
  submitPageView(
422
- pg: string,
423
- prev: string | null | undefined,
425
+ payload: Partial<IPageViewPayload>,
424
426
  unique: boolean,
425
427
  perf: IPerfPayload | {},
426
428
  evokeCallback?: boolean,
427
429
  ): void {
430
+ const prev = this.getPreviousPage()
428
431
  const privateData = {
429
432
  pid: this.projectID,
430
433
  perf,
431
434
  unique,
432
435
  }
436
+
433
437
  const pvPayload = {
434
438
  lc: getLocale(),
435
439
  tz: getTimezone(),
@@ -437,12 +441,12 @@ export class Lib {
437
441
  so: getUTMSource(),
438
442
  me: getUTMMedium(),
439
443
  ca: getUTMCampaign(),
440
- pg,
441
444
  prev,
445
+ ...payload,
442
446
  }
443
447
 
444
448
  if (evokeCallback && this.pageViewsOptions?.callback) {
445
- const callbackResult = this.pageViewsOptions.callback(pvPayload)
449
+ const callbackResult = this.pageViewsOptions.callback(pvPayload as IPageViewPayload)
446
450
 
447
451
  if (callbackResult === false) {
448
452
  return
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  ErrorActions,
9
9
  defaultActions,
10
10
  IErrorEventPayload,
11
+ IPageViewPayload,
11
12
  } from './Lib'
12
13
 
13
14
  export let LIB_INSTANCE: Lib | null = null
@@ -66,12 +67,10 @@ export function trackViews(options?: PageViewsOptions): Promise<PageActions> {
66
67
  }
67
68
 
68
69
  /**
69
- * With this function you are able to track any custom events you want.
70
- * You should never send any identifiable data (like User ID, email, session cookie, etc.) as an event name.
71
- * The total number of track calls and their conversion rate will be saved.
70
+ * This function is used to set up automatic error events tracking.
71
+ * It set's up an error listener, and whenever an error happens, it gets tracked.
72
72
  *
73
- * @param {PageViewsOptions} options The options related to the custom event.
74
- * @returns {PageActions} The actions related to the tracking. Used to stop tracking pages.
73
+ * @returns {ErrorActions} The actions related to the tracking. Used to stop tracking errors.
75
74
  */
76
75
  export function trackErrors(options?: ErrorOptions): ErrorActions {
77
76
  if (!LIB_INSTANCE) {
@@ -98,13 +97,36 @@ export function trackError(payload: IErrorEventPayload): void {
98
97
  * This function is used to manually track a page view event.
99
98
  * It's useful if your application uses esoteric routing which is not supported by Swetrix by default.
100
99
  *
101
- * @param path Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
100
+ * @deprecated This function is deprecated and will be removed soon, please use the `pageview` instead.
101
+ * @param pg Path of the page to track (this will be sent to the Swetrix API and displayed in the dashboard).
102
102
  * @param prev Path of the previous page.
103
103
  * @param unique If set to `true`, only 1 event with the same ID will be saved per user session.
104
104
  * @returns void
105
105
  */
106
- export function trackPageview(path: string, prev?: string, unique?: boolean): void {
106
+ export function trackPageview(pg: string, prev?: string, unique?: boolean): void {
107
+ if (!LIB_INSTANCE) return
108
+
109
+ LIB_INSTANCE.submitPageView({ pg, prev: prev || null }, Boolean(unique), {})
110
+ }
111
+
112
+ export interface IPageviewOptions {
113
+ payload: Partial<IPageViewPayload>
114
+ unique?: boolean
115
+ }
116
+
117
+ export function pageview(options: IPageviewOptions): void {
107
118
  if (!LIB_INSTANCE) return
108
119
 
109
- LIB_INSTANCE.submitPageView(path, prev || null, Boolean(unique), {})
120
+ LIB_INSTANCE.submitPageView(options.payload, Boolean(options.unique), {})
121
+ }
122
+
123
+ export {
124
+ LibOptions,
125
+ TrackEventOptions,
126
+ PageViewsOptions,
127
+ ErrorOptions,
128
+ PageActions,
129
+ ErrorActions,
130
+ IErrorEventPayload,
131
+ IPageViewPayload,
110
132
  }