insights-js
Advanced tools
Comparing version 1.2.3 to 1.2.4
@@ -276,9 +276,9 @@ 'use strict'; | ||
var params = { | ||
path: path, | ||
referrer: referrer(), | ||
locale: locale(), | ||
screenType: screenType() | ||
path: path | ||
}; | ||
if (isOnFirstPage) { | ||
params.uniqueViews = path; | ||
params.referrer = referrer(); | ||
params.locale = locale(); | ||
params.screenType = screenType(); | ||
} | ||
@@ -285,0 +285,0 @@ var previous = this.getPreviousPage(first); |
@@ -272,9 +272,9 @@ function isInBrowser() { | ||
var params = { | ||
path: path, | ||
referrer: referrer(), | ||
locale: locale(), | ||
screenType: screenType() | ||
path: path | ||
}; | ||
if (isOnFirstPage) { | ||
params.uniqueViews = path; | ||
params.referrer = referrer(); | ||
params.locale = locale(); | ||
params.screenType = screenType(); | ||
} | ||
@@ -281,0 +281,0 @@ var previous = this.getPreviousPage(first); |
@@ -278,9 +278,9 @@ (function (global, factory) { | ||
var params = { | ||
path: path, | ||
referrer: referrer(), | ||
locale: locale(), | ||
screenType: screenType() | ||
path: path | ||
}; | ||
if (isOnFirstPage) { | ||
params.uniqueViews = path; | ||
params.referrer = referrer(); | ||
params.locale = locale(); | ||
params.screenType = screenType(); | ||
} | ||
@@ -287,0 +287,0 @@ var previous = this.getPreviousPage(first); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).insights={})}(this,function(r){"use strict";function s(){return"undefined"!=typeof window}function o(){return location.protocol+"//"+location.host}function u(){if(!s())return!1;var e=document.referrer||"",t=o();return e.startsWith(t)}function c(){return s()?{type:"locale",value:function(){var e=void 0!==navigator.languages?navigator.languages[0]:navigator.language;return e&&5===e.length&&"-"===e[2]?e.substr(0,3)+e.substr(3).toLocaleUpperCase():e}()||"<none>"}:{type:"locale",value:"<not-in-browser>"}}function p(){return s()?{type:"screen-type",value:function(){var e=window.innerWidth;return e<=414?"XS":e<=800?"S":e<=1200?"M":e<=1600?"L":"XL"}()}:{type:"screen-type",value:"<not-in-browser>"}}function h(){return s()?u()?{type:"referrer",value:"<none>"}:{type:"referrer",value:document.referrer||"<none>"}:{type:"referrer",value:"<not-in-browser>"}}function l(e,t){if(void 0===e&&(e=!1),void 0===t&&(t=!1),!s())return{type:"path",value:"<not-in-browser>"};var r=window.location.pathname,a=window.location.hash,n=window.location.search;return e&&t?r+=a:e?r+=a.substr(0,a.length-n.length):t&&(r+=n),{type:"path",value:r}}function g(e,t){return{type:"transition",value:e+" -> "+t}}function f(e,t){return void 0===t&&(t=""),e<5e3?{type:"duration-interval",value:t+"< 5s"}:e<15e3?{type:"duration-interval",value:t+"< 15s"}:e<3e4?{type:"duration-interval",value:t+"< 30s"}:e<6e4?{type:"duration-interval",value:t+"< 1m"}:e<3e5?{type:"duration-interval",value:t+"< 5m"}:{type:"duration-interval",value:t+"> 5m"}}var e=Object.freeze({locale:c,screenType:p,referrer:h,path:l,transition:g,durationInterval:f});var a={};function n(){}var i=(t.prototype.track=function(e){if(this.options.disabled||!s())return Promise.resolve();if(e.unique){var t=JSON.stringify(e);if(this.uniques[t])return Promise.resolve();this.uniques[t]=!0}var r={id:e.id,projectId:this.projectId,ignoreErrors:this.options.ignoreErrors||!1};return e.remove&&(r.remove=!0),e.parameters&&(r.parameters=e.parameters),e.update&&(r.update=!0),function(u,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,a=[],n=[],i={},o=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(JSON.parse(r.responseText))},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:o,headers:{keys:function(){return a},entries:function(){return n},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var s in r.open(c.method||"get",u,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){a.push(t=t.toLowerCase()),n.push([t,r]),i[t]=i[t]?i[t]+","+r:r}),e(o())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(s,c.headers[s]);r.send(c.body||null)})}("https://getinsights.io/app/tics",{method:"post",body:JSON.stringify(r)}).then(n)},t.prototype.trackPages=function(e){if(!s())return{stop:function(){}};if(this.trackPageData)return this.trackPageData.result;var t=setInterval(this.trackPageChange,2e3),r=e||{},a=r.hash,n=void 0!==a&&a,i=r.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(t)}}},this.trackSinglePage(!0,this.trackPageData.path),window.addEventListener("unload",this.trackLastPageTimeSpent),this.trackPageData.result},t.prototype.getPreviousPage=function(e){var t=this.trackPageData&&this.trackPageData.path;return!e&&t?t:u()?document.referrer.replace(o(),""):document.referrer},t.prototype.trackPageChange=function(){if(this.trackPageData){var e=this.trackPageData,t=l(e.hash,e.search).value;t!==this.trackPageData.path&&this.trackSinglePage(!1,t)}},t.prototype.trackSinglePage=function(e,t){if(this.trackPageData){this.trackPageData.isOnFirstPage=e&&!u();var r=this.trackPageData,a=r.time,n=r.isOnFirstPage,i={path:t,referrer:h(),locale:c(),screenType:p()};n&&(i.uniqueViews=t);var o=this.getPreviousPage(e);if(o&&o!==t&&(i.transitions=g(o,t)),!e){var s=Date.now();this.trackPageData.time=s,i.duration=f(s-a,t+" - ")}this.trackPageData.path=t,this.track({id:"page-views",parameters:i})}},t.prototype.trackLastPageTimeSpent=function(){var e=this.trackPageData&&this.trackPageData.time;if(e&&"function"==typeof navigator.sendBeacon&&!this.options.disabled&&this.trackPageData){var t=this.trackPageData,r=t.isOnFirstPage,a=t.path,n={};n.duration=f(Date.now()-e,a+" - ");var i=document.activeElement&&document.activeElement.href||"";i?i.startsWith("/")||i.startsWith(o())||(n.transition=g(a,i)):n.bounces=r?"Yes":"No",navigator.sendBeacon("https://getinsights.io/app/tics",JSON.stringify({id:"page-views",projectId:this.projectId,parameters:n,ignoreErrors:this.options.ignoreErrors||!1,update:!0}))}},t);function t(e,t){void 0===t&&(t=a),this.projectId=e,this.options=t,this.uniques={},this.trackPageData=null,this.trackPageChange=this.trackPageChange.bind(this),this.trackLastPageTimeSpent=this.trackLastPageTimeSpent.bind(this)}r.DEFAULT_APP=null,r.App=i,r.init=function(e,t){if(!s()||r.DEFAULT_APP)throw new Error("Already initialized!");return r.DEFAULT_APP=new i(e,t),r.DEFAULT_APP},r.parameters=e,r.track=function(e){r.DEFAULT_APP&&s()&&r.DEFAULT_APP.track(e)},r.trackPages=function(e){return r.DEFAULT_APP&&s()?r.DEFAULT_APP.trackPages(e):{stop:function(){}}},Object.defineProperty(r,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).insights={})}(this,function(r){"use strict";function s(){return"undefined"!=typeof window}function o(){return location.protocol+"//"+location.host}function u(){if(!s())return!1;var e=document.referrer||"",t=o();return e.startsWith(t)}function c(){return s()?{type:"locale",value:function(){var e=void 0!==navigator.languages?navigator.languages[0]:navigator.language;return e&&5===e.length&&"-"===e[2]?e.substr(0,3)+e.substr(3).toLocaleUpperCase():e}()||"<none>"}:{type:"locale",value:"<not-in-browser>"}}function p(){return s()?{type:"screen-type",value:function(){var e=window.innerWidth;return e<=414?"XS":e<=800?"S":e<=1200?"M":e<=1600?"L":"XL"}()}:{type:"screen-type",value:"<not-in-browser>"}}function h(){return s()?u()?{type:"referrer",value:"<none>"}:{type:"referrer",value:document.referrer||"<none>"}:{type:"referrer",value:"<not-in-browser>"}}function l(e,t){if(void 0===e&&(e=!1),void 0===t&&(t=!1),!s())return{type:"path",value:"<not-in-browser>"};var r=window.location.pathname,a=window.location.hash,n=window.location.search;return e&&t?r+=a:e?r+=a.substr(0,a.length-n.length):t&&(r+=n),{type:"path",value:r}}function g(e,t){return{type:"transition",value:e+" -> "+t}}function f(e,t){return void 0===t&&(t=""),e<5e3?{type:"duration-interval",value:t+"< 5s"}:e<15e3?{type:"duration-interval",value:t+"< 15s"}:e<3e4?{type:"duration-interval",value:t+"< 30s"}:e<6e4?{type:"duration-interval",value:t+"< 1m"}:e<3e5?{type:"duration-interval",value:t+"< 5m"}:{type:"duration-interval",value:t+"> 5m"}}var e=Object.freeze({locale:c,screenType:p,referrer:h,path:l,transition:g,durationInterval:f});var a={};function n(){}var i=(t.prototype.track=function(e){if(this.options.disabled||!s())return Promise.resolve();if(e.unique){var t=JSON.stringify(e);if(this.uniques[t])return Promise.resolve();this.uniques[t]=!0}var r={id:e.id,projectId:this.projectId,ignoreErrors:this.options.ignoreErrors||!1};return e.remove&&(r.remove=!0),e.parameters&&(r.parameters=e.parameters),e.update&&(r.update=!0),function(u,c){return c=c||{},new Promise(function(e,t){var r=new XMLHttpRequest,a=[],n=[],i={},o=function(){return{ok:2==(r.status/100|0),statusText:r.statusText,status:r.status,url:r.responseURL,text:function(){return Promise.resolve(r.responseText)},json:function(){return Promise.resolve(JSON.parse(r.responseText))},blob:function(){return Promise.resolve(new Blob([r.response]))},clone:o,headers:{keys:function(){return a},entries:function(){return n},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var s in r.open(c.method||"get",u,!0),r.onload=function(){r.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,t,r){a.push(t=t.toLowerCase()),n.push([t,r]),i[t]=i[t]?i[t]+","+r:r}),e(o())},r.onerror=t,r.withCredentials="include"==c.credentials,c.headers)r.setRequestHeader(s,c.headers[s]);r.send(c.body||null)})}("https://getinsights.io/app/tics",{method:"post",body:JSON.stringify(r)}).then(n)},t.prototype.trackPages=function(e){if(!s())return{stop:function(){}};if(this.trackPageData)return this.trackPageData.result;var t=setInterval(this.trackPageChange,2e3),r=e||{},a=r.hash,n=void 0!==a&&a,i=r.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(t)}}},this.trackSinglePage(!0,this.trackPageData.path),window.addEventListener("unload",this.trackLastPageTimeSpent),this.trackPageData.result},t.prototype.getPreviousPage=function(e){var t=this.trackPageData&&this.trackPageData.path;return!e&&t?t:u()?document.referrer.replace(o(),""):document.referrer},t.prototype.trackPageChange=function(){if(this.trackPageData){var e=this.trackPageData,t=l(e.hash,e.search).value;t!==this.trackPageData.path&&this.trackSinglePage(!1,t)}},t.prototype.trackSinglePage=function(e,t){if(this.trackPageData){this.trackPageData.isOnFirstPage=e&&!u();var r=this.trackPageData,a=r.time,n={path:t};r.isOnFirstPage&&(n.uniqueViews=t,n.referrer=h(),n.locale=c(),n.screenType=p());var i=this.getPreviousPage(e);if(i&&i!==t&&(n.transitions=g(i,t)),!e){var o=Date.now();this.trackPageData.time=o,n.duration=f(o-a,t+" - ")}this.trackPageData.path=t,this.track({id:"page-views",parameters:n})}},t.prototype.trackLastPageTimeSpent=function(){var e=this.trackPageData&&this.trackPageData.time;if(e&&"function"==typeof navigator.sendBeacon&&!this.options.disabled&&this.trackPageData){var t=this.trackPageData,r=t.isOnFirstPage,a=t.path,n={};n.duration=f(Date.now()-e,a+" - ");var i=document.activeElement&&document.activeElement.href||"";i?i.startsWith("/")||i.startsWith(o())||(n.transition=g(a,i)):n.bounces=r?"Yes":"No",navigator.sendBeacon("https://getinsights.io/app/tics",JSON.stringify({id:"page-views",projectId:this.projectId,parameters:n,ignoreErrors:this.options.ignoreErrors||!1,update:!0}))}},t);function t(e,t){void 0===t&&(t=a),this.projectId=e,this.options=t,this.uniques={},this.trackPageData=null,this.trackPageChange=this.trackPageChange.bind(this),this.trackLastPageTimeSpent=this.trackLastPageTimeSpent.bind(this)}r.DEFAULT_APP=null,r.App=i,r.init=function(e,t){if(!s()||r.DEFAULT_APP)throw new Error("Already initialized!");return r.DEFAULT_APP=new i(e,t),r.DEFAULT_APP},r.parameters=e,r.track=function(e){r.DEFAULT_APP&&s()&&r.DEFAULT_APP.track(e)},r.trackPages=function(e){return r.DEFAULT_APP&&s()?r.DEFAULT_APP.trackPages(e):{stop:function(){}}},Object.defineProperty(r,"__esModule",{value:!0})}); |
{ | ||
"name": "insights-js", | ||
"version": "1.2.3", | ||
"version": "1.2.4", | ||
"description": "Javascript client for getinsights.io", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
68929