Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

insights-js

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

insights-js - npm Package Compare versions

Comparing version 1.2.5 to 1.2.6

26

dist/insights-js.cjs.js

@@ -22,3 +22,3 @@ 'use strict';

var host = getHost();
return referrer.startsWith(host);
return referrer.substr(0, host.length) === host;
}

@@ -163,4 +163,2 @@

function unfetch(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return {ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(JSON.parse(s.responseText))},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t;}),t(a());},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null);})}
/**

@@ -170,3 +168,2 @@ * The default options.

var defaultOptions = {};
function ignore() { }
/**

@@ -190,4 +187,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly.

* @param event {TrackEventPayload} The event to track.
*
* @returns {Promise} a promise that resolves when the call to the API resolves.
*/

@@ -215,6 +210,6 @@ App.prototype.track = function (event) {

body.update = true;
return unfetch("https://getinsights.io/app/tics", {
method: "post",
body: JSON.stringify(body)
}).then(ignore);
// do not use fetch, for IE compatibility
var request = new XMLHttpRequest();
request.open("post", "https://getinsights.io/app/tics", true);
request.send(JSON.stringify(body));
};

@@ -314,2 +309,3 @@ /**

var nextUrl = (document.activeElement && document.activeElement.href) || "";
var host = getHost();
if (!nextUrl) {

@@ -319,6 +315,14 @@ // user closed the window

}
else if (!nextUrl.startsWith("/") && !nextUrl.startsWith(getHost())) {
else if (nextUrl[0] !== "/" && nextUrl.substr(0, host.length) !== getHost()) {
// link outside of the app
params.transitions = transition(path, nextUrl);
}
// polyfil for IE, this won't always work, but it's better than nothing.
navigator.sendBeacon =
navigator.sendBeacon ||
function (url, body) {
var request = new XMLHttpRequest();
request.open("post", url, false);
request.send(body);
};
navigator.sendBeacon("https://getinsights.io/app/tics", JSON.stringify({

@@ -325,0 +329,0 @@ id: "page-views",

@@ -18,3 +18,3 @@ function isInBrowser() {

var host = getHost();
return referrer.startsWith(host);
return referrer.substr(0, host.length) === host;
}

@@ -159,4 +159,2 @@

function unfetch(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return {ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(JSON.parse(s.responseText))},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t;}),t(a());},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null);})}
/**

@@ -166,3 +164,2 @@ * The default options.

var defaultOptions = {};
function ignore() { }
/**

@@ -186,4 +183,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly.

* @param event {TrackEventPayload} The event to track.
*
* @returns {Promise} a promise that resolves when the call to the API resolves.
*/

@@ -211,6 +206,6 @@ App.prototype.track = function (event) {

body.update = true;
return unfetch("https://getinsights.io/app/tics", {
method: "post",
body: JSON.stringify(body)
}).then(ignore);
// do not use fetch, for IE compatibility
var request = new XMLHttpRequest();
request.open("post", "https://getinsights.io/app/tics", true);
request.send(JSON.stringify(body));
};

@@ -310,2 +305,3 @@ /**

var nextUrl = (document.activeElement && document.activeElement.href) || "";
var host = getHost();
if (!nextUrl) {

@@ -315,6 +311,14 @@ // user closed the window

}
else if (!nextUrl.startsWith("/") && !nextUrl.startsWith(getHost())) {
else if (nextUrl[0] !== "/" && nextUrl.substr(0, host.length) !== getHost()) {
// link outside of the app
params.transitions = transition(path, nextUrl);
}
// polyfil for IE, this won't always work, but it's better than nothing.
navigator.sendBeacon =
navigator.sendBeacon ||
function (url, body) {
var request = new XMLHttpRequest();
request.open("post", url, false);
request.send(body);
};
navigator.sendBeacon("https://getinsights.io/app/tics", JSON.stringify({

@@ -321,0 +325,0 @@ id: "page-views",

@@ -24,3 +24,3 @@ (function (global, factory) {

var host = getHost();
return referrer.startsWith(host);
return referrer.substr(0, host.length) === host;
}

@@ -165,4 +165,2 @@

function unfetch(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return {ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(JSON.parse(s.responseText))},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t;}),t(a());},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null);})}
/**

@@ -172,3 +170,2 @@ * The default options.

var defaultOptions = {};
function ignore() { }
/**

@@ -192,4 +189,2 @@ * A class that contains a `projectId` and related configuration to track events painlessly.

* @param event {TrackEventPayload} The event to track.
*
* @returns {Promise} a promise that resolves when the call to the API resolves.
*/

@@ -217,6 +212,6 @@ App.prototype.track = function (event) {

body.update = true;
return unfetch("https://getinsights.io/app/tics", {
method: "post",
body: JSON.stringify(body)
}).then(ignore);
// do not use fetch, for IE compatibility
var request = new XMLHttpRequest();
request.open("post", "https://getinsights.io/app/tics", true);
request.send(JSON.stringify(body));
};

@@ -316,2 +311,3 @@ /**

var nextUrl = (document.activeElement && document.activeElement.href) || "";
var host = getHost();
if (!nextUrl) {

@@ -321,6 +317,14 @@ // user closed the window

}
else if (!nextUrl.startsWith("/") && !nextUrl.startsWith(getHost())) {
else if (nextUrl[0] !== "/" && nextUrl.substr(0, host.length) !== getHost()) {
// link outside of the app
params.transitions = transition(path, nextUrl);
}
// polyfil for IE, this won't always work, but it's better than nothing.
navigator.sendBeacon =
navigator.sendBeacon ||
function (url, body) {
var request = new XMLHttpRequest();
request.open("post", url, false);
request.send(body);
};
navigator.sendBeacon("https://getinsights.io/app/tics", JSON.stringify({

@@ -327,0 +331,0 @@ id: "page-views",

@@ -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={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.transitions=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(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())return!1;var t=document.referrer||"",e=u();return t.substr(0,e.length)===e}function p(){return s()?{type:"locale",value:function(){var t=void 0!==navigator.languages?navigator.languages[0]:navigator.language;return t&&5===t.length&&"-"===t[2]?t.substr(0,3)+t.substr(3).toLocaleUpperCase():t}()||"<none>"}:{type:"locale",value:"<not-in-browser>"}}function h(){return s()?{type:"screen-type",value:function(){var t=window.innerWidth;return t<=414?"XS":t<=800?"S":t<=1200?"M":t<=1600?"L":"XL"}()}:{type:"screen-type",value:"<not-in-browser>"}}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({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.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={path:e};a.isOnFirstPage&&(n.uniqueViews=e,n.referrer=g(),n.locale=p(),n.screenType=h());var i=this.getPreviousPage(t);if(i&&i!==e&&(n.transitions=v(i,e)),!t){var o=Date.now();this.trackPageData.time=o,n.duration=d(o-r,e+" - ")}this.trackPageData.path=e,this.track({id:"page-views",parameters:n})}},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})});

@@ -182,6 +182,4 @@ /**

* @param event {TrackEventPayload} The event to track.
*
* @returns {Promise} a promise that resolves when the call to the API resolves.
*/
track(event: TrackEventPayload): Promise<void>;
track(event: TrackEventPayload): Promise<void> | undefined;
/**

@@ -188,0 +186,0 @@ * Tracks page views. This method checks if the URL changed every so often and tracks new pages accordingly.

{
"name": "insights-js",
"version": "1.2.5",
"version": "1.2.6",
"description": "Javascript client for getinsights.io",

@@ -30,6 +30,3 @@ "keywords": [],

},
"dependencies": {
"isomorphic-unfetch": "3.0.0",
"unfetch": "4.1.0"
},
"dependencies": {},
"devDependencies": {

@@ -36,0 +33,0 @@ "@types/node": "12.7.4",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc