insights-js
Advanced tools
Comparing version 1.2.10 to 1.2.11
@@ -8,2 +8,4 @@ /** | ||
* This flag should be set to `true` for production systems. | ||
* | ||
* @deprecated No longer used by the server. | ||
*/ | ||
@@ -10,0 +12,0 @@ ignoreErrors?: boolean; |
import * as parameters from "./parameters"; | ||
import { isInBrowser, isReferrerSameHost, getHost } from "./utils"; | ||
import { getHost, isInBrowser, isReferrerSameHost } from "./utils"; | ||
/** | ||
@@ -7,2 +7,29 @@ * The default options. | ||
const defaultOptions = {}; | ||
// See https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API | ||
function addOnPageClose(handler) { | ||
// let hidden: string | undefined = undefined | ||
// let visibilityChange: string | undefined = undefined | ||
// const doc = document as any | ||
// if (typeof doc.hidden !== "undefined") { | ||
// // Opera 12.10 and Firefox 18 and later support | ||
// hidden = "hidden" | ||
// visibilityChange = "visibilitychange" | ||
// } else if (typeof doc.msHidden !== "undefined") { | ||
// hidden = "msHidden" | ||
// visibilityChange = "msvisibilitychange" | ||
// } else if (typeof doc.webkitHidden !== "undefined") { | ||
// hidden = "webkitHidden" | ||
// visibilityChange = "webkitvisibilitychange" | ||
// } | ||
// if (hidden) { | ||
// doc.addEventListener(visibilityChange, () => { | ||
// if (hidden && doc[hidden]) handler() | ||
// }) | ||
// } else if ("onpagehide" in window) { | ||
// // See https://stackoverflow.com/questions/6906146/how-to-detect-browser-support-for-pageshow-and-pagehide | ||
// window.addEventListener("pagehide", handler) | ||
// } else { | ||
// } | ||
window.addEventListener("unload", handler); | ||
} | ||
/** | ||
@@ -39,3 +66,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly. | ||
projectId: this.projectId, | ||
ignoreErrors: this.options.ignoreErrors || false | ||
}; | ||
@@ -81,8 +107,8 @@ if (event.remove) | ||
clearInterval(interval); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
// Track the first/current page view | ||
this.trackSinglePage(true, this.trackPageData.path); | ||
window.addEventListener("unload", this.trackLastPageTimeSpent); | ||
addOnPageClose(this.trackLastPageTimeSpent); | ||
return this.trackPageData.result; | ||
@@ -115,3 +141,3 @@ } | ||
const params = { | ||
path | ||
path, | ||
}; | ||
@@ -136,3 +162,3 @@ if (isOnFirstPage) { | ||
id: "page-views", | ||
parameters: params | ||
parameters: params, | ||
}); | ||
@@ -171,4 +197,3 @@ } | ||
parameters: params, | ||
ignoreErrors: this.options.ignoreErrors || false, | ||
update: true | ||
update: true, | ||
})); | ||
@@ -175,0 +200,0 @@ } |
@@ -31,4 +31,4 @@ import * as parameters from "./parameters"; | ||
export function init(projectId, options) { | ||
if (!isInBrowser() || !!DEFAULT_APP) { | ||
throw new Error("Already initialized!"); | ||
if (!isInBrowser() || DEFAULT_APP) { | ||
return DEFAULT_APP; | ||
} | ||
@@ -35,0 +35,0 @@ DEFAULT_APP = new App(projectId, options); |
@@ -65,1 +65,26 @@ /** | ||
}; | ||
/** | ||
* Track the operating system of the user, here are the most common values: | ||
* | ||
* - Windows | ||
* - Mac OS X | ||
* - Android | ||
* - Linux | ||
* - iOS | ||
*/ | ||
export declare function os(): { | ||
type: string; | ||
}; | ||
/** | ||
* Track the browser of the user, here are the most common values: | ||
* | ||
* - Chrome | ||
* - Firefox | ||
* - Safari | ||
* - Mobile Chrome | ||
* - Mobile Firefox | ||
* - Mobile Safari | ||
*/ | ||
export declare function browser(): { | ||
type: string; | ||
}; |
@@ -132,2 +132,27 @@ import { isInBrowser, isReferrerSameHost } from "./utils"; | ||
} | ||
/** | ||
* Track the operating system of the user, here are the most common values: | ||
* | ||
* - Windows | ||
* - Mac OS X | ||
* - Android | ||
* - Linux | ||
* - iOS | ||
*/ | ||
export function os() { | ||
return { type: "os" }; | ||
} | ||
/** | ||
* Track the browser of the user, here are the most common values: | ||
* | ||
* - Chrome | ||
* - Firefox | ||
* - Safari | ||
* - Mobile Chrome | ||
* - Mobile Firefox | ||
* - Mobile Safari | ||
*/ | ||
export function browser() { | ||
return { type: "browser" }; | ||
} | ||
//# sourceMappingURL=parameters.js.map |
@@ -158,2 +158,27 @@ 'use strict'; | ||
} | ||
/** | ||
* Track the operating system of the user, here are the most common values: | ||
* | ||
* - Windows | ||
* - Mac OS X | ||
* - Android | ||
* - Linux | ||
* - iOS | ||
*/ | ||
function os() { | ||
return { type: "os" }; | ||
} | ||
/** | ||
* Track the browser of the user, here are the most common values: | ||
* | ||
* - Chrome | ||
* - Firefox | ||
* - Safari | ||
* - Mobile Chrome | ||
* - Mobile Firefox | ||
* - Mobile Safari | ||
*/ | ||
function browser() { | ||
return { type: "browser" }; | ||
} | ||
@@ -167,3 +192,5 @@ var parameters = /*#__PURE__*/Object.freeze({ | ||
transition: transition, | ||
durationInterval: durationInterval | ||
durationInterval: durationInterval, | ||
os: os, | ||
browser: browser | ||
}); | ||
@@ -175,2 +202,29 @@ | ||
var defaultOptions = {}; | ||
// See https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API | ||
function addOnPageClose(handler) { | ||
// let hidden: string | undefined = undefined | ||
// let visibilityChange: string | undefined = undefined | ||
// const doc = document as any | ||
// if (typeof doc.hidden !== "undefined") { | ||
// // Opera 12.10 and Firefox 18 and later support | ||
// hidden = "hidden" | ||
// visibilityChange = "visibilitychange" | ||
// } else if (typeof doc.msHidden !== "undefined") { | ||
// hidden = "msHidden" | ||
// visibilityChange = "msvisibilitychange" | ||
// } else if (typeof doc.webkitHidden !== "undefined") { | ||
// hidden = "webkitHidden" | ||
// visibilityChange = "webkitvisibilitychange" | ||
// } | ||
// if (hidden) { | ||
// doc.addEventListener(visibilityChange, () => { | ||
// if (hidden && doc[hidden]) handler() | ||
// }) | ||
// } else if ("onpagehide" in window) { | ||
// // See https://stackoverflow.com/questions/6906146/how-to-detect-browser-support-for-pageshow-and-pagehide | ||
// window.addEventListener("pagehide", handler) | ||
// } else { | ||
// } | ||
window.addEventListener("unload", handler); | ||
} | ||
/** | ||
@@ -208,3 +262,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly. | ||
projectId: this.projectId, | ||
ignoreErrors: this.options.ignoreErrors || false | ||
}; | ||
@@ -250,8 +303,8 @@ if (event.remove) | ||
clearInterval(interval); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
// Track the first/current page view | ||
this.trackSinglePage(true, this.trackPageData.path); | ||
window.addEventListener("unload", this.trackLastPageTimeSpent); | ||
addOnPageClose(this.trackLastPageTimeSpent); | ||
return this.trackPageData.result; | ||
@@ -284,3 +337,3 @@ }; | ||
var params = { | ||
path: path | ||
path: path, | ||
}; | ||
@@ -305,3 +358,3 @@ if (isOnFirstPage) { | ||
id: "page-views", | ||
parameters: params | ||
parameters: params, | ||
}); | ||
@@ -340,4 +393,3 @@ }; | ||
parameters: params, | ||
ignoreErrors: this.options.ignoreErrors || false, | ||
update: true | ||
update: true, | ||
})); | ||
@@ -373,4 +425,4 @@ }; | ||
function init(projectId, options) { | ||
if (!isInBrowser() || !!exports.DEFAULT_APP) { | ||
throw new Error("Already initialized!"); | ||
if (!isInBrowser() || exports.DEFAULT_APP) { | ||
return exports.DEFAULT_APP; | ||
} | ||
@@ -377,0 +429,0 @@ exports.DEFAULT_APP = new App(projectId, options); |
@@ -154,2 +154,27 @@ function isInBrowser() { | ||
} | ||
/** | ||
* Track the operating system of the user, here are the most common values: | ||
* | ||
* - Windows | ||
* - Mac OS X | ||
* - Android | ||
* - Linux | ||
* - iOS | ||
*/ | ||
function os() { | ||
return { type: "os" }; | ||
} | ||
/** | ||
* Track the browser of the user, here are the most common values: | ||
* | ||
* - Chrome | ||
* - Firefox | ||
* - Safari | ||
* - Mobile Chrome | ||
* - Mobile Firefox | ||
* - Mobile Safari | ||
*/ | ||
function browser() { | ||
return { type: "browser" }; | ||
} | ||
@@ -163,3 +188,5 @@ var parameters = /*#__PURE__*/Object.freeze({ | ||
transition: transition, | ||
durationInterval: durationInterval | ||
durationInterval: durationInterval, | ||
os: os, | ||
browser: browser | ||
}); | ||
@@ -171,2 +198,29 @@ | ||
var defaultOptions = {}; | ||
// See https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API | ||
function addOnPageClose(handler) { | ||
// let hidden: string | undefined = undefined | ||
// let visibilityChange: string | undefined = undefined | ||
// const doc = document as any | ||
// if (typeof doc.hidden !== "undefined") { | ||
// // Opera 12.10 and Firefox 18 and later support | ||
// hidden = "hidden" | ||
// visibilityChange = "visibilitychange" | ||
// } else if (typeof doc.msHidden !== "undefined") { | ||
// hidden = "msHidden" | ||
// visibilityChange = "msvisibilitychange" | ||
// } else if (typeof doc.webkitHidden !== "undefined") { | ||
// hidden = "webkitHidden" | ||
// visibilityChange = "webkitvisibilitychange" | ||
// } | ||
// if (hidden) { | ||
// doc.addEventListener(visibilityChange, () => { | ||
// if (hidden && doc[hidden]) handler() | ||
// }) | ||
// } else if ("onpagehide" in window) { | ||
// // See https://stackoverflow.com/questions/6906146/how-to-detect-browser-support-for-pageshow-and-pagehide | ||
// window.addEventListener("pagehide", handler) | ||
// } else { | ||
// } | ||
window.addEventListener("unload", handler); | ||
} | ||
/** | ||
@@ -204,3 +258,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly. | ||
projectId: this.projectId, | ||
ignoreErrors: this.options.ignoreErrors || false | ||
}; | ||
@@ -246,8 +299,8 @@ if (event.remove) | ||
clearInterval(interval); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
// Track the first/current page view | ||
this.trackSinglePage(true, this.trackPageData.path); | ||
window.addEventListener("unload", this.trackLastPageTimeSpent); | ||
addOnPageClose(this.trackLastPageTimeSpent); | ||
return this.trackPageData.result; | ||
@@ -280,3 +333,3 @@ }; | ||
var params = { | ||
path: path | ||
path: path, | ||
}; | ||
@@ -301,3 +354,3 @@ if (isOnFirstPage) { | ||
id: "page-views", | ||
parameters: params | ||
parameters: params, | ||
}); | ||
@@ -336,4 +389,3 @@ }; | ||
parameters: params, | ||
ignoreErrors: this.options.ignoreErrors || false, | ||
update: true | ||
update: true, | ||
})); | ||
@@ -369,4 +421,4 @@ }; | ||
function init(projectId, options) { | ||
if (!isInBrowser() || !!DEFAULT_APP) { | ||
throw new Error("Already initialized!"); | ||
if (!isInBrowser() || DEFAULT_APP) { | ||
return DEFAULT_APP; | ||
} | ||
@@ -373,0 +425,0 @@ DEFAULT_APP = new App(projectId, options); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.insights = {})); | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.insights = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -160,2 +160,27 @@ | ||
} | ||
/** | ||
* Track the operating system of the user, here are the most common values: | ||
* | ||
* - Windows | ||
* - Mac OS X | ||
* - Android | ||
* - Linux | ||
* - iOS | ||
*/ | ||
function os() { | ||
return { type: "os" }; | ||
} | ||
/** | ||
* Track the browser of the user, here are the most common values: | ||
* | ||
* - Chrome | ||
* - Firefox | ||
* - Safari | ||
* - Mobile Chrome | ||
* - Mobile Firefox | ||
* - Mobile Safari | ||
*/ | ||
function browser() { | ||
return { type: "browser" }; | ||
} | ||
@@ -169,3 +194,5 @@ var parameters = /*#__PURE__*/Object.freeze({ | ||
transition: transition, | ||
durationInterval: durationInterval | ||
durationInterval: durationInterval, | ||
os: os, | ||
browser: browser | ||
}); | ||
@@ -177,2 +204,29 @@ | ||
var defaultOptions = {}; | ||
// See https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API | ||
function addOnPageClose(handler) { | ||
// let hidden: string | undefined = undefined | ||
// let visibilityChange: string | undefined = undefined | ||
// const doc = document as any | ||
// if (typeof doc.hidden !== "undefined") { | ||
// // Opera 12.10 and Firefox 18 and later support | ||
// hidden = "hidden" | ||
// visibilityChange = "visibilitychange" | ||
// } else if (typeof doc.msHidden !== "undefined") { | ||
// hidden = "msHidden" | ||
// visibilityChange = "msvisibilitychange" | ||
// } else if (typeof doc.webkitHidden !== "undefined") { | ||
// hidden = "webkitHidden" | ||
// visibilityChange = "webkitvisibilitychange" | ||
// } | ||
// if (hidden) { | ||
// doc.addEventListener(visibilityChange, () => { | ||
// if (hidden && doc[hidden]) handler() | ||
// }) | ||
// } else if ("onpagehide" in window) { | ||
// // See https://stackoverflow.com/questions/6906146/how-to-detect-browser-support-for-pageshow-and-pagehide | ||
// window.addEventListener("pagehide", handler) | ||
// } else { | ||
// } | ||
window.addEventListener("unload", handler); | ||
} | ||
/** | ||
@@ -210,3 +264,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly. | ||
projectId: this.projectId, | ||
ignoreErrors: this.options.ignoreErrors || false | ||
}; | ||
@@ -252,8 +305,8 @@ if (event.remove) | ||
clearInterval(interval); | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
// Track the first/current page view | ||
this.trackSinglePage(true, this.trackPageData.path); | ||
window.addEventListener("unload", this.trackLastPageTimeSpent); | ||
addOnPageClose(this.trackLastPageTimeSpent); | ||
return this.trackPageData.result; | ||
@@ -286,3 +339,3 @@ }; | ||
var params = { | ||
path: path | ||
path: path, | ||
}; | ||
@@ -307,3 +360,3 @@ if (isOnFirstPage) { | ||
id: "page-views", | ||
parameters: params | ||
parameters: params, | ||
}); | ||
@@ -342,4 +395,3 @@ }; | ||
parameters: params, | ||
ignoreErrors: this.options.ignoreErrors || false, | ||
update: true | ||
update: true, | ||
})); | ||
@@ -375,4 +427,4 @@ }; | ||
function init(projectId, options) { | ||
if (!isInBrowser() || !!exports.DEFAULT_APP) { | ||
throw new Error("Already initialized!"); | ||
if (!isInBrowser() || exports.DEFAULT_APP) { | ||
return exports.DEFAULT_APP; | ||
} | ||
@@ -379,0 +431,0 @@ exports.DEFAULT_APP = new App(projectId, options); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).insights={})}(this,function(a){"use strict";function s(){return"undefined"!=typeof window}function u(){return location.protocol+"//"+location.host}function c(){if(s()){var t=document.referrer||"",e=u();return t.substr(0,e.length)===e}}function p(){return s()?{type:"locale",value:('"'===(t=void 0!==navigator.languages?navigator.languages[0]:navigator.language)[0]&&(t=t.substr(1)),0<t.length&&'"'===t[t.length-1]&&(t=t.substr(0,t.length-1)),(t&&5===t.length&&"-"===t[2]?t.substr(0,3)+t.substr(3).toLocaleUpperCase():t)||"<none>")}:{type:"locale",value:"<not-in-browser>"};var t}function h(){return s()?{type:"screen-type",value:(t=window.innerWidth)<=414?"XS":t<=800?"S":t<=1200?"M":t<=1600?"L":"XL"}:{type:"screen-type",value:"<not-in-browser>"};var t}function g(){return s()?c()?{type:"referrer",value:"<none>"}:{type:"referrer",value:document.referrer||"<none>"}:{type:"referrer",value:"<not-in-browser>"}}function l(t,e){if(void 0===t&&(t=!1),void 0===e&&(e=!1),!s())return{type:"path",value:"<not-in-browser>"};var a=window.location.pathname,r=window.location.hash,n=window.location.search;return t&&e?a+=r:t?a+=r.substr(0,r.length-n.length):e&&(a+=n),{type:"path",value:a}}function v(t,e){return{type:"transition",value:t+" -> "+e}}function d(t,e){return void 0===e&&(e=""),t<5e3?{type:"duration-interval",value:e+"< 5s"}:t<15e3?{type:"duration-interval",value:e+"< 15s"}:t<3e4?{type:"duration-interval",value:e+"< 30s"}:t<6e4?{type:"duration-interval",value:e+"< 1m"}:t<3e5?{type:"duration-interval",value:e+"< 5m"}:{type:"duration-interval",value:e+"> 5m"}}var t=Object.freeze({__proto__:null,locale:p,screenType:h,referrer:g,path:l,transition:v,durationInterval:d}),r={},n=(e.prototype.track=function(t){if(this.options.disabled||!s())return Promise.resolve();if(t.unique){var e=JSON.stringify(t);if(this.uniques[e])return Promise.resolve();this.uniques[e]=!0}var a={id:t.id,projectId:this.projectId,ignoreErrors:this.options.ignoreErrors||!1};t.remove&&(a.remove=!0),t.parameters&&(a.parameters=t.parameters),t.update&&(a.update=!0);var r=new XMLHttpRequest;r.open("post","https://getinsights.io/app/tics",!0),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(a))},e.prototype.trackPages=function(t){if(!s())return{stop:function(){}};if(this.trackPageData)return this.trackPageData.result;var e=setInterval(this.trackPageChange,2e3),a=t||{},r=a.hash,n=void 0!==r&&r,i=a.search,o=void 0!==i&&i;return this.trackPageData={hash:n,search:o,path:l(n,o).value,isOnFirstPage:!0,time:Date.now(),result:{stop:function(){clearInterval(e)}}},this.trackSinglePage(!0,this.trackPageData.path),window.addEventListener("unload",this.trackLastPageTimeSpent),this.trackPageData.result},e.prototype.getPreviousPage=function(t){var e=this.trackPageData&&this.trackPageData.path;return!t&&e?e:c()?document.referrer.replace(u(),""):document.referrer},e.prototype.trackPageChange=function(){if(this.trackPageData){var t=this.trackPageData,e=l(t.hash,t.search).value;e!==this.trackPageData.path&&this.trackSinglePage(!1,e)}},e.prototype.trackSinglePage=function(t,e){if(this.trackPageData){this.trackPageData.isOnFirstPage=t&&!c();var a=this.trackPageData,r=a.time,n=a.isOnFirstPage,i={path:e};n&&(i.uniqueViews=e,i.referrer=g(),i.locale=p(),i.screenType=h());var o=this.getPreviousPage(t);if(o&&o!==e&&(i.transitions=v(o,e),!n)){var s=Date.now();this.trackPageData.time=s,i.duration=d(s-r,o+" - ")}this.trackPageData.path=e,this.track({id:"page-views",parameters:i})}},e.prototype.trackLastPageTimeSpent=function(){var t=this.trackPageData&&this.trackPageData.time;if(t&&"function"==typeof navigator.sendBeacon&&!this.options.disabled&&this.trackPageData){var e=this.trackPageData,a=e.isOnFirstPage,r=e.path,n={};n.duration=d(Date.now()-t,r+" - ");var i=document.activeElement&&document.activeElement.href||"",o=u();i?"/"!==i[0]&&i.substr(0,o.length)!==u()&&(n.transitions=v(r,i)):n.bounces=a?"Yes":"No",navigator.sendBeacon=navigator.sendBeacon||function(t,e){var a=new XMLHttpRequest;a.open("post",t,!1),a.send(e)},navigator.sendBeacon("https://getinsights.io/app/tics",JSON.stringify({id:"page-views",projectId:this.projectId,parameters:n,ignoreErrors:this.options.ignoreErrors||!1,update:!0}))}},e);function e(t,e){void 0===e&&(e=r),this.projectId=t,this.options=e,this.uniques={},this.trackPageData=null,this.trackPageChange=this.trackPageChange.bind(this),this.trackLastPageTimeSpent=this.trackLastPageTimeSpent.bind(this)}a.DEFAULT_APP=null,a.App=n,a.init=function(t,e){if(!s()||a.DEFAULT_APP)throw new Error("Already initialized!");return a.DEFAULT_APP=new n(t,e),a.DEFAULT_APP},a.parameters=t,a.track=function(t){a.DEFAULT_APP&&s()&&a.DEFAULT_APP.track(t)},a.trackPages=function(t){return a.DEFAULT_APP&&s()?a.DEFAULT_APP.trackPages(t):{stop:function(){}}},Object.defineProperty(a,"__esModule",{value:!0})}); | ||
!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).insights={})}(this,function(a){"use strict";function u(){return"undefined"!=typeof window}function s(){return location.protocol+"//"+location.host}function c(){if(u()){var t=document.referrer||"",e=s();return t.substr(0,e.length)===e}}function p(){return u()?{type:"locale",value:('"'===(t=void 0!==navigator.languages?navigator.languages[0]:navigator.language)[0]&&(t=t.substr(1)),0<t.length&&'"'===t[t.length-1]&&(t=t.substr(0,t.length-1)),(t&&5===t.length&&"-"===t[2]?t.substr(0,3)+t.substr(3).toLocaleUpperCase():t)||"<none>")}:{type:"locale",value:"<not-in-browser>"};var t}function h(){return u()?{type:"screen-type",value:(t=window.innerWidth)<=414?"XS":t<=800?"S":t<=1200?"M":t<=1600?"L":"XL"}:{type:"screen-type",value:"<not-in-browser>"};var t}function l(){return u()?c()?{type:"referrer",value:"<none>"}:{type:"referrer",value:document.referrer||"<none>"}:{type:"referrer",value:"<not-in-browser>"}}function g(t,e){if(void 0===t&&(t=!1),void 0===e&&(e=!1),!u())return{type:"path",value:"<not-in-browser>"};var a=window.location.pathname,r=window.location.hash,n=window.location.search;return t&&e?a+=r:t?a+=r.substr(0,r.length-n.length):e&&(a+=n),{type:"path",value:a}}function v(t,e){return{type:"transition",value:t+" -> "+e}}function d(t,e){return void 0===e&&(e=""),t<5e3?{type:"duration-interval",value:e+"< 5s"}:t<15e3?{type:"duration-interval",value:e+"< 15s"}:t<3e4?{type:"duration-interval",value:e+"< 30s"}:t<6e4?{type:"duration-interval",value:e+"< 1m"}:t<3e5?{type:"duration-interval",value:e+"< 5m"}:{type:"duration-interval",value:e+"> 5m"}}var t=Object.freeze({__proto__:null,locale:p,screenType:h,referrer:l,path:g,transition:v,durationInterval:d,os:function(){return{type:"os"}},browser:function(){return{type:"browser"}}}),r={};var n=(e.prototype.track=function(t){if(this.options.disabled||!u())return Promise.resolve();if(t.unique){var e=JSON.stringify(t);if(this.uniques[e])return Promise.resolve();this.uniques[e]=!0}var a={id:t.id,projectId:this.projectId};t.remove&&(a.remove=!0),t.parameters&&(a.parameters=t.parameters),t.update&&(a.update=!0);var r=new XMLHttpRequest;r.open("post","https://getinsights.io/app/tics",!0),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(a))},e.prototype.trackPages=function(t){if(!u())return{stop:function(){}};if(this.trackPageData)return this.trackPageData.result;var e,a=setInterval(this.trackPageChange,2e3),r=t||{},n=r.hash,i=void 0!==n&&n,o=r.search,s=void 0!==o&&o;return this.trackPageData={hash:i,search:s,path:g(i,s).value,isOnFirstPage:!0,time:Date.now(),result:{stop:function(){clearInterval(a)}}},this.trackSinglePage(!0,this.trackPageData.path),e=this.trackLastPageTimeSpent,window.addEventListener("unload",e),this.trackPageData.result},e.prototype.getPreviousPage=function(t){var e=this.trackPageData&&this.trackPageData.path;return!t&&e?e:c()?document.referrer.replace(s(),""):document.referrer},e.prototype.trackPageChange=function(){if(this.trackPageData){var t=this.trackPageData,e=g(t.hash,t.search).value;e!==this.trackPageData.path&&this.trackSinglePage(!1,e)}},e.prototype.trackSinglePage=function(t,e){if(this.trackPageData){this.trackPageData.isOnFirstPage=t&&!c();var a=this.trackPageData,r=a.time,n=a.isOnFirstPage,i={path:e};n&&(i.uniqueViews=e,i.referrer=l(),i.locale=p(),i.screenType=h());var o=this.getPreviousPage(t);if(o&&o!==e&&(i.transitions=v(o,e),!n)){var s=Date.now();this.trackPageData.time=s,i.duration=d(s-r,o+" - ")}this.trackPageData.path=e,this.track({id:"page-views",parameters:i})}},e.prototype.trackLastPageTimeSpent=function(){var t=this.trackPageData&&this.trackPageData.time;if(t&&"function"==typeof navigator.sendBeacon&&!this.options.disabled&&this.trackPageData){var e=this.trackPageData,a=e.isOnFirstPage,r=e.path,n={};n.duration=d(Date.now()-t,r+" - ");var i=document.activeElement&&document.activeElement.href||"",o=s();i?"/"!==i[0]&&i.substr(0,o.length)!==s()&&(n.transitions=v(r,i)):n.bounces=a?"Yes":"No",navigator.sendBeacon=navigator.sendBeacon||function(t,e){var a=new XMLHttpRequest;a.open("post",t,!1),a.send(e)},navigator.sendBeacon("https://getinsights.io/app/tics",JSON.stringify({id:"page-views",projectId:this.projectId,parameters:n,update:!0}))}},e);function e(t,e){void 0===e&&(e=r),this.projectId=t,this.options=e,this.uniques={},this.trackPageData=null,this.trackPageChange=this.trackPageChange.bind(this),this.trackLastPageTimeSpent=this.trackLastPageTimeSpent.bind(this)}a.DEFAULT_APP=null,a.App=n,a.init=function(t,e){return!u()||a.DEFAULT_APP||(a.DEFAULT_APP=new n(t,e)),a.DEFAULT_APP},a.parameters=t,a.track=function(t){a.DEFAULT_APP&&u()&&a.DEFAULT_APP.track(t)},a.trackPages=function(t){return a.DEFAULT_APP&&u()?a.DEFAULT_APP.trackPages(t):{stop:function(){}}},Object.defineProperty(a,"__esModule",{value:!0})}); |
{ | ||
"name": "insights-js", | ||
"version": "1.2.10", | ||
"version": "1.2.11", | ||
"description": "Javascript client for getinsights.io", | ||
"keywords": [], | ||
"keywords": [ | ||
"insights" | ||
], | ||
"main": "dist/insights-js.cjs.js", | ||
@@ -26,25 +28,21 @@ "module": "dist/insights-js.es5.js", | ||
"docs": "rimraf docs && typedoc src/index.ts", | ||
"tsc": "tsc -p tsconfig.esnext.json" | ||
"tsc": "tsc -p tsconfig.esnext.json", | ||
"playground": "npm run build && cp dist/insights-js.umd.js playground/public/insights.js && cd playground && npm start" | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"printWidth": 120 | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/node": "13.7.4", | ||
"@types/node-fetch": "2.5.4", | ||
"prettier": "1.19.1", | ||
"@types/node": "14.14.13", | ||
"@types/node-fetch": "2.5.7", | ||
"prettier": "2.2.1", | ||
"rimraf": "3.0.2", | ||
"rollup": "1.31.1", | ||
"rollup": "2.35.0", | ||
"rollup-plugin-commonjs": "10.1.0", | ||
"rollup-plugin-json": "4.0.0", | ||
"rollup-plugin-node-resolve": "5.2.0", | ||
"rollup-plugin-sourcemaps": "0.5.0", | ||
"rollup-plugin-typescript2": "0.26.0", | ||
"rollup-plugin-sourcemaps": "0.6.3", | ||
"rollup-plugin-typescript2": "0.29.0", | ||
"rollup-plugin-uglify": "6.0.4", | ||
"typedoc": "0.16.10", | ||
"typedoc-plugin-markdown": "2.2.16", | ||
"typescript": "3.8.2" | ||
"typedoc": "0.19.2", | ||
"typedoc-plugin-markdown": "3.1.1", | ||
"typescript": "4.1.3" | ||
} | ||
} |
@@ -41,4 +41,4 @@ # Insights-js | ||
parameters: { | ||
plan: "Startup" | ||
} | ||
plan: "Startup", | ||
}, | ||
}) | ||
@@ -63,4 +63,4 @@ ``` | ||
parameters: { | ||
plan: "Startup" | ||
} | ||
plan: "Startup", | ||
}, | ||
}) | ||
@@ -81,4 +81,4 @@ </script> | ||
method: "google", | ||
from: "top-link" | ||
} | ||
from: "top-link", | ||
}, | ||
}) | ||
@@ -103,4 +103,4 @@ ``` | ||
// this will track the type of screen on which the user reads the post, useful for useability | ||
screenSize: parameters.screenType() | ||
} | ||
screenSize: parameters.screenType(), | ||
}, | ||
}) | ||
@@ -134,4 +134,4 @@ ``` | ||
parameters: { | ||
plan: "Startup" | ||
} | ||
plan: "Startup", | ||
}, | ||
}) | ||
@@ -143,5 +143,5 @@ | ||
parameters: { | ||
plan: "Startup" | ||
plan: "Startup", | ||
}, | ||
remove: true | ||
remove: true, | ||
}) | ||
@@ -193,4 +193,4 @@ ``` | ||
method: "google", | ||
from: "top-link" | ||
} | ||
from: "top-link", | ||
}, | ||
}) | ||
@@ -205,4 +205,4 @@ | ||
// this will track the type of screen on which the user reads the post, useful for useability | ||
screenSize: parameters.screenType() | ||
} | ||
screenSize: parameters.screenType(), | ||
}, | ||
}) | ||
@@ -231,7 +231,2 @@ ``` | ||
`options.ignoreErrors: boolean` | ||
_Optional_ | ||
_Default value:_ `false` | ||
When set to `true` any error that may occur when tracking events will be ignored. It is reccomended to set this flag to `true` on production. | ||
`options.disabled: boolean` | ||
@@ -301,4 +296,4 @@ _Optional_ | ||
parameters: { | ||
provider: "email" | ||
} | ||
provider: "email", | ||
}, | ||
}) | ||
@@ -310,4 +305,4 @@ | ||
parameters: { | ||
provider: "facebook" | ||
} | ||
provider: "facebook", | ||
}, | ||
}) | ||
@@ -320,4 +315,4 @@ | ||
product: product.name, | ||
currency: customer.currency | ||
} | ||
currency: customer.currency, | ||
}, | ||
}) | ||
@@ -331,4 +326,4 @@ | ||
screenType: parameters.screenType(), | ||
referrer: parameters.referrer() | ||
} | ||
referrer: parameters.referrer(), | ||
}, | ||
}) | ||
@@ -335,0 +330,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97176
2139
430