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

coveo.analytics

Package Overview
Dependencies
Maintainers
4
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coveo.analytics - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

dist/library.d.ts

12

dist/analytics.js
"use strict";
const history_1 = require('./history');
const detector_1 = require('./detector');
exports.Version = 'v15';

@@ -47,2 +49,12 @@ exports.Endpoints = {

}
if (detector_1.hasDocumentLocation()) {
const store = new history_1.HistoryStore();
const historyElement = {
name: 'PageView',
value: document.location.toString(),
time: JSON.stringify(new Date()),
title: document.title
};
store.addElement(historyElement);
}
return this.sendEvent('view', request).then(defaultResponseTransformer);

@@ -49,0 +61,0 @@ }

1

dist/browser.d.ts
export interface CoveoUAGlobal {
(action: string, ...params: string[]): void;
q?: string[][];
disableAutoHistory: boolean;
}
declare const coveoua: CoveoUAGlobal;
export default coveoua;
"use strict";
const simpleanalytics_1 = require('./simpleanalytics');
const analytics = require('./index');
const history_1 = require('./history');
const coveoua = global.coveoua || {};

@@ -11,14 +10,4 @@ global.coveoua = simpleanalytics_1.default;

}
if (!coveoua.disableAutoHistory) {
const store = new history_1.HistoryStore();
let historyElement = {
name: 'PageView',
value: document.location.toString(),
time: JSON.stringify(new Date()),
title: document.title
};
store.addElement(historyElement);
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = coveoua;
//# sourceMappingURL=browser.js.map

@@ -1,2 +0,2 @@

!function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return t[o].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){(function(t){"use strict";var o=n(1),r=n(6),i=n(7),s=t.coveoua||{};if(t.coveoua=o["default"],t.coveoanalytics=r,s.q&&s.q.forEach(function(t){return o["default"].apply(void 0,t)}),!s.disableAutoHistory){var a=new i.HistoryStore,u={name:"PageView",value:document.location.toString(),time:JSON.stringify(new Date),title:document.title};a.addElement(u)}Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=s}).call(e,function(){return this}())},function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),s=n(2),a=n(4),u=n(5),c=function(){function t(){o(this,t)}return i(t,[{key:"init",value:function(t,e){if("undefined"==typeof t)throw new Error("You must pass your token when you call 'init'");if("string"==typeof t)e=e||s.Endpoints["default"],this.client=new s.Client({token:t,endpoint:e});else{if("object"!==("undefined"==typeof t?"undefined":r(t))||"undefined"==typeof t.sendEvent)throw new Error("You must pass either your token or a valid object when you call 'init'");this.client=t}}},{key:"send",value:function(t,e){if("undefined"==typeof this.client)throw new Error("You must call init before sending an event");switch(e=a["default"]({},{hash:window.location.hash},e),t){case"pageview":return void this.client.sendViewEvent({location:window.location.toString(),referrer:document.referrer,language:document.documentElement.lang,title:document.title,contentIdKey:u.popFromObject(e,"contentIdKey"),contentIdValue:u.popFromObject(e,"contentIdValue"),contentType:u.popFromObject(e,"contentType"),customData:e});default:throw new Error("Event type: '"+t+"' not implemented")}}},{key:"onLoad",value:function(t){if("undefined"==typeof t)throw new Error("You must pass a function when you call 'onLoad'");t()}}]),t}();e.SimpleAPI=c;var l=new c;e.SimpleAnalytics=function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;o<e;o++)n[o-1]=arguments[o];var r=l[t];if(r)return r.apply(l,n)},Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=e.SimpleAnalytics},function(t,e,n){(function(t){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function o(t){return t.json().then(function(e){return e.raw=t,e})}var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}();e.Version="v15",e.Endpoints={"default":"https://usageanalytics.coveo.com",production:"https://usageanalytics.coveo.com",dev:"https://usageanalyticsdev.coveo.com",staging:"https://usageanalyticsstaging.coveo.com"};var i=function(){function i(t){if(n(this,i),"undefined"==typeof t)throw new Error("You have to pass options to this constructor");this.endpoint=t.endpoint||e.Endpoints["default"],this.token=t.token,this.version=t.version||e.Version}return r(i,[{key:"sendEvent",value:function(e,n){return t(this.getRestEndpoint()+"/analytics/"+e,{method:"POST",headers:this.getHeaders(),mode:"cors",body:JSON.stringify(n),credentials:"include"})}},{key:"sendSearchEvent",value:function(t){return this.sendEvent("search",t).then(o)}},{key:"sendClickEvent",value:function(t){return this.sendEvent("click",t).then(o)}},{key:"sendCustomEvent",value:function(t){return this.sendEvent("custom",t).then(o)}},{key:"sendViewEvent",value:function(t){return""===t.referrer&&delete t.referrer,this.sendEvent("view",t).then(o)}},{key:"getVisit",value:function(){return t(this.getRestEndpoint()+"/analytics/visit").then(o)}},{key:"getHealth",value:function(){return t(this.getRestEndpoint()+"/analytics/monitoring/health").then(o)}},{key:"getRestEndpoint",value:function(){return this.endpoint+"/rest/"+this.version}},{key:"getHeaders",value:function(){var t={"Content-Type":"application/json"};return this.token&&(t.Authorization="Bearer "+this.token),t}}]),i}();e.Client=i,Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}).call(e,n(3))},function(t,e){!function(t){"use strict";function e(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function n(t){return"string"!=typeof t&&(t=String(t)),t}function o(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return y.iterable&&(e[Symbol.iterator]=function(){return e}),e}function r(t){this.map={},t instanceof r?t.forEach(function(t,e){this.append(e,t)},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function i(t){return t.bodyUsed?Promise.reject(new TypeError("Already read")):void(t.bodyUsed=!0)}function s(t){return new Promise(function(e,n){t.onload=function(){e(t.result)},t.onerror=function(){n(t.error)}})}function a(t){var e=new FileReader;return e.readAsArrayBuffer(t),s(e)}function u(t){var e=new FileReader;return e.readAsText(t),s(e)}function c(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,"string"==typeof t)this._bodyText=t;else if(y.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(y.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(y.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(t){if(!y.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t))throw new Error("unsupported BodyInit type")}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):y.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},y.blob?(this.blob=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this.blob().then(a)},this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return u(this._bodyBlob);if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)}):this.text=function(){var t=i(this);return t?t:Promise.resolve(this._bodyText)},y.formData&&(this.formData=function(){return this.text().then(h)}),this.json=function(){return this.text().then(JSON.parse)},this}function l(t){var e=t.toUpperCase();return v.indexOf(e)>-1?e:t}function f(t,e){e=e||{};var n=e.body;if(f.prototype.isPrototypeOf(t)){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new r(t.headers)),this.method=t.method,this.mode=t.mode,n||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=t;if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new r(e.headers)),this.method=l(e.method||this.method||"GET"),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function h(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var n=t.split("="),o=n.shift().replace(/\+/g," "),r=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(o),decodeURIComponent(r))}}),e}function d(t){var e=new r,n=(t.getAllResponseHeaders()||"").trim().split("\n");return n.forEach(function(t){var n=t.trim().split(":"),o=n.shift().trim(),r=n.join(":").trim();e.append(o,r)}),e}function p(t,e){e||(e={}),this.type="default",this.status=e.status,this.ok=this.status>=200&&this.status<300,this.statusText=e.statusText,this.headers=e.headers instanceof r?e.headers:new r(e.headers),this.url=e.url||"",this._initBody(t)}if(!t.fetch){var y={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};r.prototype.append=function(t,o){t=e(t),o=n(o);var r=this.map[t];r||(r=[],this.map[t]=r),r.push(o)},r.prototype["delete"]=function(t){delete this.map[e(t)]},r.prototype.get=function(t){var n=this.map[e(t)];return n?n[0]:null},r.prototype.getAll=function(t){return this.map[e(t)]||[]},r.prototype.has=function(t){return this.map.hasOwnProperty(e(t))},r.prototype.set=function(t,o){this.map[e(t)]=[n(o)]},r.prototype.forEach=function(t,e){Object.getOwnPropertyNames(this.map).forEach(function(n){this.map[n].forEach(function(o){t.call(e,o,n,this)},this)},this)},r.prototype.keys=function(){var t=[];return this.forEach(function(e,n){t.push(n)}),o(t)},r.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),o(t)},r.prototype.entries=function(){var t=[];return this.forEach(function(e,n){t.push([n,e])}),o(t)},y.iterable&&(r.prototype[Symbol.iterator]=r.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];f.prototype.clone=function(){return new f(this)},c.call(f.prototype),c.call(p.prototype),p.prototype.clone=function(){return new p(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new r(this.headers),url:this.url})},p.error=function(){var t=new p(null,{status:0,statusText:""});return t.type="error",t};var m=[301,302,303,307,308];p.redirect=function(t,e){if(m.indexOf(e)===-1)throw new RangeError("Invalid status code");return new p(null,{status:e,headers:{location:t}})},t.Headers=r,t.Request=f,t.Response=p,t.fetch=function(t,e){return new Promise(function(n,o){function r(){return"responseURL"in s?s.responseURL:/^X-Request-URL:/m.test(s.getAllResponseHeaders())?s.getResponseHeader("X-Request-URL"):void 0}var i;i=f.prototype.isPrototypeOf(t)&&!e?t:new f(t,e);var s=new XMLHttpRequest;s.onload=function(){var t={status:s.status,statusText:s.statusText,headers:d(s),url:r()},e="response"in s?s.response:s.responseText;n(new p(e,t))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.open(i.method,i.url,!0),"include"===i.credentials&&(s.withCredentials=!0),"responseType"in s&&y.blob&&(s.responseType="blob"),i.headers.forEach(function(t,e){s.setRequestHeader(e,t)}),s.send("undefined"==typeof i._bodyInit?null:i._bodyInit)})},t.fetch.polyfill=!0}}("undefined"!=typeof self?self:this),t.exports=self.fetch},function(t,e){"use strict";var n=Object.prototype.hasOwnProperty,o=Object.getOwnPropertySymbols,r=Object.prototype.propertyIsEnumerable,i=function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),s=1;s<e;s++)i[s-1]=arguments[s];if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");var a=Object(t);return i.forEach(function(t){var e=Object(t);for(var i in e)n.call(e,i)&&(a[i]=e[i]);if(o){var s=o(e);s.forEach(function(t){r.call(e,t)&&(a[t]=e[t])})}}),a};e.ponyfill=i,e.assign="function"==typeof Object.assign?Object.assign:i,Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=e.assign},function(t,e){"use strict";function n(t,e){if(t){var n=t[e];return delete t[e],n}}e.popFromObject=n},function(t,e,n){"use strict";var o=n(2);e.analytics=o;var r=n(1);e.SimpleAnalytics=r;var i=n(7);e.history=i;var s=n(11);e.donottrack=s},function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),i=n(8);e.STORE_KEY="__coveo.analytics.history",e.MAX_NUMBER_OF_HISTORY_ELEMENTS=20;var s=function(){function t(e){o(this,t),this.store=e||i.getAvailableStorage()}return r(t,[{key:"addElement",value:function(t){null!=this.getHistory()?this.setHistory([t].concat(this.getHistory())):this.setHistory([t])}},{key:"getHistory",value:function(){try{return JSON.parse(this.store.getItem(e.STORE_KEY))}catch(t){return[]}}},{key:"setHistory",value:function(t){try{this.store.setItem(e.STORE_KEY,JSON.stringify(t.slice(0,e.MAX_NUMBER_OF_HISTORY_ELEMENTS)))}catch(n){}}},{key:"clear",value:function(){try{this.store.removeItem(e.STORE_KEY)}catch(t){}}}]),t}();e.HistoryStore=s,Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=s},function(t,e,n){"use strict";function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(){return s.hasCookieStorage()?new u:s.hasSessionStorage()?sessionStorage:s.hasLocalStorage()?localStorage:new c}var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),s=n(9),a=n(10);e.getAvailableStorage=r;var u=function(){function t(){o(this,t)}return i(t,[{key:"getItem",value:function(t){return a.Cookie.get(t)}},{key:"removeItem",value:function(t){a.Cookie.erase(t)}},{key:"setItem",value:function(t,e){a.Cookie.set(t,e)}}]),t}();e.CookieStorage=u;var c=function(){function t(){o(this,t)}return i(t,[{key:"getItem",value:function(t){return""}},{key:"removeItem",value:function(t){}},{key:"setItem",value:function(t,e){}}]),t}();e.NullStorage=c},function(t,e){"use strict";function n(){try{return"localStorage"in window&&null!==window.localStorage}catch(t){return!1}}function o(){try{return"sessionStorage"in window&&null!==window.sessionStorage}catch(t){return!1}}function r(){return navigator.cookieEnabled}e.hasLocalStorage=n,e.hasSessionStorage=o,e.hasCookieStorage=r},function(t,e){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var o=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),r=function(){function t(){n(this,t)}return o(t,null,[{key:"set",value:function(e,n,o){var r,i,s,a,u;o?(s=new Date,s.setTime(s.getTime()+o),a="; expires="+s.toGMTString()):a="",u=location.hostname,u.indexOf(".")===-1?document.cookie=e+"="+n+a+"; path=/":(i=u.split("."),i.shift(),r="."+i.join("."),document.cookie=e+"="+n+a+"; path=/; domain="+r,null!=t.get(e)&&t.get(e)==n||(r="."+u,document.cookie=e+"="+n+a+"; path=/; domain="+r))}},{key:"get",value:function(t){for(var e=t+"=",n=document.cookie.split(";"),o=0;o<n.length;o++){var r=n[o];if(r=r.replace(/^\s+/,""),0==r.indexOf(e))return r.substring(e.length,r.length)}return null}},{key:"erase",value:function(e){t.set(e,"",-1)}}]),t}();e.Cookie=r},function(t,e){"use strict";e.doNotTrack=[!0,"yes","1"].indexOf(navigator.doNotTrack||navigator.msDoNotTrack||window.doNotTrack),Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=e.doNotTrack}]);
!function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){(function(e){"use strict";var r=n(1),o=n(10),i=e.coveoua||{};e.coveoua=r["default"],e.coveoanalytics=o,i.q&&i.q.forEach(function(e){return r["default"].apply(void 0,e)}),Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i}).call(t,function(){return this}())},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(2),s=n(8),u=n(9),c=function(){function e(){r(this,e)}return i(e,[{key:"init",value:function(e,t){if("undefined"==typeof e)throw new Error("You must pass your token when you call 'init'");if("string"==typeof e)t=t||a.Endpoints["default"],this.client=new a.Client({token:e,endpoint:t});else{if("object"!==("undefined"==typeof e?"undefined":o(e))||"undefined"==typeof e.sendEvent)throw new Error("You must pass either your token or a valid object when you call 'init'");this.client=e}}},{key:"send",value:function(e,t){if("undefined"==typeof this.client)throw new Error("You must call init before sending an event");switch(t=s["default"]({},{hash:window.location.hash},t),e){case"pageview":return void this.client.sendViewEvent({location:window.location.toString(),referrer:document.referrer,language:document.documentElement.lang,title:document.title,contentIdKey:u.popFromObject(t,"contentIdKey"),contentIdValue:u.popFromObject(t,"contentIdValue"),contentType:u.popFromObject(t,"contentType"),customData:t});default:throw new Error("Event type: '"+e+"' not implemented")}}},{key:"onLoad",value:function(e){if("undefined"==typeof e)throw new Error("You must pass a function when you call 'onLoad'");e()}}]),e}();t.SimpleAPI=c;var l=new c;t.SimpleAnalytics=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=l[e];if(o)return o.apply(l,n)},Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=t.SimpleAnalytics},function(e,t,n){(function(e){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){return e.json().then(function(t){return t.raw=e,t})}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(4),s=n(6);t.Version="v15",t.Endpoints={"default":"https://usageanalytics.coveo.com",production:"https://usageanalytics.coveo.com",dev:"https://usageanalyticsdev.coveo.com",staging:"https://usageanalyticsstaging.coveo.com"};var u=function(){function n(e){if(r(this,n),"undefined"==typeof e)throw new Error("You have to pass options to this constructor");this.endpoint=e.endpoint||t.Endpoints["default"],this.token=e.token,this.version=e.version||t.Version}return i(n,[{key:"sendEvent",value:function(t,n){return e(this.getRestEndpoint()+"/analytics/"+t,{method:"POST",headers:this.getHeaders(),mode:"cors",body:JSON.stringify(n),credentials:"include"})}},{key:"sendSearchEvent",value:function(e){return this.sendEvent("search",e).then(o)}},{key:"sendClickEvent",value:function(e){return this.sendEvent("click",e).then(o)}},{key:"sendCustomEvent",value:function(e){return this.sendEvent("custom",e).then(o)}},{key:"sendViewEvent",value:function(e){if(""===e.referrer&&delete e.referrer,s.hasDocumentLocation()){var t=new a.HistoryStore,n={name:"PageView",value:document.location.toString(),time:JSON.stringify(new Date),title:document.title};t.addElement(n)}return this.sendEvent("view",e).then(o)}},{key:"getVisit",value:function(){return e(this.getRestEndpoint()+"/analytics/visit").then(o)}},{key:"getHealth",value:function(){return e(this.getRestEndpoint()+"/analytics/monitoring/health").then(o)}},{key:"getRestEndpoint",value:function(){return this.endpoint+"/rest/"+this.version}},{key:"getHeaders",value:function(){var e={"Content-Type":"application/json"};return this.token&&(e.Authorization="Bearer "+this.token),e}}]),n}();t.Client=u,Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=u}).call(t,n(3))},function(e,t){!function(e){"use strict";function t(e){if("string"!=typeof e&&(e=String(e)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(e))throw new TypeError("Invalid character in header field name");return e.toLowerCase()}function n(e){return"string"!=typeof e&&(e=String(e)),e}function r(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return y.iterable&&(t[Symbol.iterator]=function(){return t}),t}function o(e){this.map={},e instanceof o?e.forEach(function(e,t){this.append(t,e)},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}function i(e){return e.bodyUsed?Promise.reject(new TypeError("Already read")):void(e.bodyUsed=!0)}function a(e){return new Promise(function(t,n){e.onload=function(){t(e.result)},e.onerror=function(){n(e.error)}})}function s(e){var t=new FileReader;return t.readAsArrayBuffer(e),a(t)}function u(e){var t=new FileReader;return t.readAsText(e),a(t)}function c(){return this.bodyUsed=!1,this._initBody=function(e){if(this._bodyInit=e,"string"==typeof e)this._bodyText=e;else if(y.blob&&Blob.prototype.isPrototypeOf(e))this._bodyBlob=e;else if(y.formData&&FormData.prototype.isPrototypeOf(e))this._bodyFormData=e;else if(y.searchParams&&URLSearchParams.prototype.isPrototypeOf(e))this._bodyText=e.toString();else if(e){if(!y.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(e))throw new Error("unsupported BodyInit type")}else this._bodyText="";this.headers.get("content-type")||("string"==typeof e?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):y.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},y.blob?(this.blob=function(){var e=i(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this.blob().then(s)},this.text=function(){var e=i(this);if(e)return e;if(this._bodyBlob)return u(this._bodyBlob);if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)}):this.text=function(){var e=i(this);return e?e:Promise.resolve(this._bodyText)},y.formData&&(this.formData=function(){return this.text().then(h)}),this.json=function(){return this.text().then(JSON.parse)},this}function l(e){var t=e.toUpperCase();return v.indexOf(t)>-1?t:e}function f(e,t){t=t||{};var n=t.body;if(f.prototype.isPrototypeOf(e)){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new o(e.headers)),this.method=e.method,this.mode=e.mode,n||(n=e._bodyInit,e.bodyUsed=!0)}else this.url=e;if(this.credentials=t.credentials||this.credentials||"omit",!t.headers&&this.headers||(this.headers=new o(t.headers)),this.method=l(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function h(e){var t=new FormData;return e.trim().split("&").forEach(function(e){if(e){var n=e.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(r),decodeURIComponent(o))}}),t}function d(e){var t=new o,n=(e.getAllResponseHeaders()||"").trim().split("\n");return n.forEach(function(e){var n=e.trim().split(":"),r=n.shift().trim(),o=n.join(":").trim();t.append(r,o)}),t}function p(e,t){t||(t={}),this.type="default",this.status=t.status,this.ok=this.status>=200&&this.status<300,this.statusText=t.statusText,this.headers=t.headers instanceof o?t.headers:new o(t.headers),this.url=t.url||"",this._initBody(e)}if(!e.fetch){var y={searchParams:"URLSearchParams"in e,iterable:"Symbol"in e&&"iterator"in Symbol,blob:"FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),formData:"FormData"in e,arrayBuffer:"ArrayBuffer"in e};o.prototype.append=function(e,r){e=t(e),r=n(r);var o=this.map[e];o||(o=[],this.map[e]=o),o.push(r)},o.prototype["delete"]=function(e){delete this.map[t(e)]},o.prototype.get=function(e){var n=this.map[t(e)];return n?n[0]:null},o.prototype.getAll=function(e){return this.map[t(e)]||[]},o.prototype.has=function(e){return this.map.hasOwnProperty(t(e))},o.prototype.set=function(e,r){this.map[t(e)]=[n(r)]},o.prototype.forEach=function(e,t){Object.getOwnPropertyNames(this.map).forEach(function(n){this.map[n].forEach(function(r){e.call(t,r,n,this)},this)},this)},o.prototype.keys=function(){var e=[];return this.forEach(function(t,n){e.push(n)}),r(e)},o.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),r(e)},o.prototype.entries=function(){var e=[];return this.forEach(function(t,n){e.push([n,t])}),r(e)},y.iterable&&(o.prototype[Symbol.iterator]=o.prototype.entries);var v=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];f.prototype.clone=function(){return new f(this)},c.call(f.prototype),c.call(p.prototype),p.prototype.clone=function(){return new p(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new o(this.headers),url:this.url})},p.error=function(){var e=new p(null,{status:0,statusText:""});return e.type="error",e};var m=[301,302,303,307,308];p.redirect=function(e,t){if(m.indexOf(t)===-1)throw new RangeError("Invalid status code");return new p(null,{status:t,headers:{location:e}})},e.Headers=o,e.Request=f,e.Response=p,e.fetch=function(e,t){return new Promise(function(n,r){function o(){return"responseURL"in a?a.responseURL:/^X-Request-URL:/m.test(a.getAllResponseHeaders())?a.getResponseHeader("X-Request-URL"):void 0}var i;i=f.prototype.isPrototypeOf(e)&&!t?e:new f(e,t);var a=new XMLHttpRequest;a.onload=function(){var e={status:a.status,statusText:a.statusText,headers:d(a),url:o()},t="response"in a?a.response:a.responseText;n(new p(t,e))},a.onerror=function(){r(new TypeError("Network request failed"))},a.ontimeout=function(){r(new TypeError("Network request failed"))},a.open(i.method,i.url,!0),"include"===i.credentials&&(a.withCredentials=!0),"responseType"in a&&y.blob&&(a.responseType="blob"),i.headers.forEach(function(e,t){a.setRequestHeader(t,e)}),a.send("undefined"==typeof i._bodyInit?null:i._bodyInit)})},e.fetch.polyfill=!0}}("undefined"!=typeof self?self:this),e.exports=self.fetch},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=n(5);t.STORE_KEY="__coveo.analytics.history",t.MAX_NUMBER_OF_HISTORY_ELEMENTS=20,t.MIN_THRESHOLD_FOR_DUPLICATE_VALUE=6e4;var a=function(){function e(t){r(this,e),this.store=t||i.getAvailableStorage()}return o(e,[{key:"addElement",value:function(e){e.internalTime=(new Date).getTime();var t=this.getHistory();null!=t?this.isValidEntry(e)&&this.setHistory([e].concat(t)):this.setHistory([e])}},{key:"getHistory",value:function(){try{return JSON.parse(this.store.getItem(t.STORE_KEY))}catch(e){return[]}}},{key:"setHistory",value:function(e){try{this.store.setItem(t.STORE_KEY,JSON.stringify(e.slice(0,t.MAX_NUMBER_OF_HISTORY_ELEMENTS)))}catch(n){}}},{key:"clear",value:function(){try{this.store.removeItem(t.STORE_KEY)}catch(e){}}},{key:"getMostRecentElement",value:function(){var e=this.getHistory();if(null!=e){var t=e.sort(function(e,t){return null==e.internalTime&&null==t.internalTime?0:null==e.internalTime&&null!=t.internalTime?1:null!=e.internalTime&&null==t.internalTime?-1:t.internalTime-e.internalTime});return t[0]}return null}},{key:"isValidEntry",value:function(e){var n=this.getMostRecentElement();return!n||n.value!=e.value||e.internalTime-n.internalTime>t.MIN_THRESHOLD_FOR_DUPLICATE_VALUE}}]),e}();t.HistoryStore=a,Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=a},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(){return a.hasCookieStorage()?new u:a.hasSessionStorage()?sessionStorage:a.hasLocalStorage()?localStorage:new c}var i=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(6),s=n(7);t.getAvailableStorage=o;var u=function(){function e(){r(this,e)}return i(e,[{key:"getItem",value:function(e){return s.Cookie.get(e)}},{key:"removeItem",value:function(e){s.Cookie.erase(e)}},{key:"setItem",value:function(e,t){s.Cookie.set(e,t)}}]),e}();t.CookieStorage=u;var c=function(){function e(){r(this,e)}return i(e,[{key:"getItem",value:function(e){return null}},{key:"removeItem",value:function(e){}},{key:"setItem",value:function(e,t){}}]),e}();t.NullStorage=c},function(e,t){"use strict";function n(){try{return"localStorage"in window&&null!==window.localStorage}catch(e){return!1}}function r(){try{return"sessionStorage"in window&&null!==window.sessionStorage}catch(e){return!1}}function o(){return navigator.cookieEnabled}function i(){return null!==document}function a(){return i()&&null!==document.location}t.hasLocalStorage=n,t.hasSessionStorage=r,t.hasCookieStorage=o,t.hasDocument=i,t.hasDocumentLocation=a},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),o=function(){function e(){n(this,e)}return r(e,null,[{key:"set",value:function(t,n,r){var o,i,a,s,u;r?(a=new Date,a.setTime(a.getTime()+r),s="; expires="+a.toGMTString()):s="",u=location.hostname,u.indexOf(".")===-1?document.cookie=t+"="+n+s+"; path=/":(i=u.split("."),i.shift(),o="."+i.join("."),document.cookie=t+"="+n+s+"; path=/; domain="+o,null!=e.get(t)&&e.get(t)==n||(o="."+u,document.cookie=t+"="+n+s+"; path=/; domain="+o))}},{key:"get",value:function(e){for(var t=e+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){var o=n[r];if(o=o.replace(/^\s+/,""),0==o.indexOf(t))return o.substring(t.length,o.length)}return null}},{key:"erase",value:function(t){e.set(t,"",-1)}}]),e}();t.Cookie=o},function(e,t){"use strict";var n=Object.prototype.hasOwnProperty,r=Object.getOwnPropertySymbols,o=Object.prototype.propertyIsEnumerable,i=function(e){for(var t=arguments.length,i=Array(t>1?t-1:0),a=1;a<t;a++)i[a-1]=arguments[a];if(void 0===e||null===e)throw new TypeError("Cannot convert undefined or null to object");var s=Object(e);return i.forEach(function(e){var t=Object(e);for(var i in t)n.call(t,i)&&(s[i]=t[i]);if(r){var a=r(t);a.forEach(function(e){o.call(t,e)&&(s[e]=t[e])})}}),s};t.ponyfill=i,t.assign="function"==typeof Object.assign?Object.assign:i,Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=t.assign},function(e,t){"use strict";function n(e,t){if(e){var n=e[t];return delete e[t],n}}t.popFromObject=n},function(e,t,n){"use strict";var r=n(2);t.analytics=r;var o=n(1);t.SimpleAnalytics=o;var i=n(4);t.history=i;var a=n(11);t.donottrack=a},function(e,t){"use strict";t.doNotTrack=[!0,"yes","1"].indexOf(navigator.doNotTrack||navigator.msDoNotTrack||window.doNotTrack),Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=t.doNotTrack}]);
//# sourceMappingURL=coveoua.js.map
export declare function hasLocalStorage(): boolean;
export declare function hasSessionStorage(): boolean;
export declare function hasCookieStorage(): boolean;
export declare function hasDocument(): boolean;
export declare function hasDocumentLocation(): boolean;

@@ -27,2 +27,12 @@ "use strict";

;
function hasDocument() {
return document !== null;
}
exports.hasDocument = hasDocument;
;
function hasDocumentLocation() {
return hasDocument() && document.location !== null;
}
exports.hasDocumentLocation = hasDocumentLocation;
;
//# sourceMappingURL=detector.js.map
import { WebStorage } from './storage';
export declare const STORE_KEY: string;
export declare const MAX_NUMBER_OF_HISTORY_ELEMENTS: number;
export declare const MIN_THRESHOLD_FOR_DUPLICATE_VALUE: number;
export declare class HistoryStore {

@@ -11,2 +12,4 @@ private store;

clear(): void;
getMostRecentElement(): HistoryElement;
private isValidEntry(elem);
}

@@ -17,2 +20,3 @@ export interface HistoryElement {

time: string;
internalTime?: number;
}

@@ -19,0 +23,0 @@ export interface HistoryViewElement extends HistoryElement {

@@ -5,2 +5,3 @@ "use strict";

exports.MAX_NUMBER_OF_HISTORY_ELEMENTS = 20;
exports.MIN_THRESHOLD_FOR_DUPLICATE_VALUE = 1000 * 60;
class HistoryStore {

@@ -12,4 +13,8 @@ constructor(store) {

addElement(elem) {
if (this.getHistory() != null) {
this.setHistory([elem].concat(this.getHistory()));
elem.internalTime = new Date().getTime();
let currentHistory = this.getHistory();
if (currentHistory != null) {
if (this.isValidEntry(elem)) {
this.setHistory([elem].concat(currentHistory));
}
}

@@ -40,2 +45,28 @@ else {

}
getMostRecentElement() {
let currentHistory = this.getHistory();
if (currentHistory != null) {
const sorted = currentHistory.sort((first, second) => {
if (first.internalTime == null && second.internalTime == null) {
return 0;
}
if (first.internalTime == null && second.internalTime != null) {
return 1;
}
if (first.internalTime != null && second.internalTime == null) {
return -1;
}
return second.internalTime - first.internalTime;
});
return sorted[0];
}
return null;
}
isValidEntry(elem) {
let lastEntry = this.getMostRecentElement();
if (lastEntry && lastEntry.value == elem.value) {
return elem.internalTime - lastEntry.internalTime > exports.MIN_THRESHOLD_FOR_DUPLICATE_VALUE;
}
return true;
}
}

@@ -42,0 +73,0 @@ exports.HistoryStore = HistoryStore;

@@ -30,3 +30,3 @@ "use strict";

class NullStorage {
getItem(key) { return ''; }
getItem(key) { return null; }
removeItem(key) { }

@@ -33,0 +33,0 @@ setItem(key, data) { }

{
"name": "coveo.analytics",
"version": "0.4.0",
"version": "0.5.0",
"description": "📈 Coveo analytics client (node and browser compatible) ",

@@ -11,6 +11,7 @@ "main": "dist/index.js",

"build:tsc": "tsc",
"build": "npm run-script lint && npm run-script build:webpack && npm run-script build:tsc",
"test": "tsc -p tsconfig.test.json && nyc ava \"**/*test.js\"",
"build": "npm run-script lint && npm run-script build:webpack && npm run-script build:tsc && npm run-script definitions",
"test": "tsc -p tsconfig.test.json && nyc ava \"./dist_test/**/*test.js\"",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"clean": "rm -rf dist/*"
"clean": "rm -rf dist/*",
"definitions": "cp src/library.d.ts dist/library.d.ts && tsc --target es6 --types whatwg-fetch dist/library.d.ts"
},

@@ -42,4 +43,4 @@ "author": "Pierre-Alexandre St-Jean <pastjean@coveo.com>",

"isomorphic-fetch": "2.2.1",
"jsdom": "9.8.0",
"nyc": "8.3.0",
"jsdom": "9.8.2",
"nyc": "8.3.2",
"sinon": "1.17.6",

@@ -64,3 +65,6 @@ "ts-loader": "^0.9.3",

]
},
"dependencies": {
"whatwg-fetch": "^1.0.0"
}
}

@@ -9,2 +9,4 @@ import {

import { AnalyticsClient } from './analyticsclient';
import { HistoryStore } from './history';
import { hasDocumentLocation } from './detector';

@@ -72,2 +74,15 @@ export const Version = 'v15';

if (request.referrer === '') { delete request.referrer; }
// Check if we are in a browser env
if (hasDocumentLocation()) {
const store = new HistoryStore();
const historyElement = {
name: 'PageView',
value: document.location.toString(),
time: JSON.stringify(new Date()),
title: document.title
};
store.addElement(historyElement);
}
return this.sendEvent('view', request).then(defaultResponseTransformer);

@@ -74,0 +89,0 @@ }

@@ -13,3 +13,2 @@ import SimpleAnalytics from './simpleanalytics';

q?: string[][];
disableAutoHistory: boolean;
}

@@ -32,17 +31,2 @@

// According to the Mozilla Do Not Track Field Guide
// (https://developer.mozilla.org/en-US/docs/Web/Security/Do_not_track_field_guide),
// gathering data of actions of an user as long as it is not associated to the
// identity of that user, doNotTrack is not enabled here.
if (!coveoua.disableAutoHistory) {
const store = new HistoryStore();
let historyElement: HistoryViewElement = {
name: 'PageView',
value: document.location.toString(),
time: JSON.stringify(new Date()),
title: document.title
};
store.addElement(historyElement);
}
export default coveoua;

@@ -20,1 +20,9 @@ export function hasLocalStorage(): boolean {

};
export function hasDocument(): boolean {
return document !== null;
};
export function hasDocumentLocation(): boolean {
return hasDocument() && document.location !== null;
};

@@ -5,2 +5,3 @@ import {WebStorage, getAvailableStorage} from './storage';

export const MAX_NUMBER_OF_HISTORY_ELEMENTS: number = 20;
export const MIN_THRESHOLD_FOR_DUPLICATE_VALUE: number = 1000 * 60;

@@ -14,4 +15,9 @@ export class HistoryStore {

addElement(elem: HistoryElement) {
if (this.getHistory() != null) {
this.setHistory([elem].concat(this.getHistory()));
elem.internalTime = new Date().getTime();
let currentHistory = this.getHistory();
if (currentHistory != null) {
if (this.isValidEntry(elem)) {
this.setHistory([elem].concat(currentHistory));
}
} else {

@@ -44,2 +50,33 @@ this.setHistory([elem]);

}
getMostRecentElement(): HistoryElement {
let currentHistory = this.getHistory();
if (currentHistory != null) {
const sorted = currentHistory.sort((first: HistoryElement, second: HistoryElement) => {
// Internal time might not be set for all history element (on upgrade).
// Ensure to return the most recent element for which we have a value for internalTime.
if (first.internalTime == null && second.internalTime == null) {
return 0;
}
if (first.internalTime == null && second.internalTime != null) {
return 1;
}
if (first.internalTime != null && second.internalTime == null) {
return -1;
}
return second.internalTime - first.internalTime;
});
return sorted[0];
}
return null;
}
private isValidEntry(elem: HistoryElement): boolean {
let lastEntry = this.getMostRecentElement();
if (lastEntry && lastEntry.value == elem.value) {
return elem.internalTime - lastEntry.internalTime > MIN_THRESHOLD_FOR_DUPLICATE_VALUE;
}
return true;
}
}

@@ -51,2 +88,3 @@

time: string;
internalTime?: number;
};

@@ -53,0 +91,0 @@

@@ -36,5 +36,5 @@ import * as detector from './detector';

export class NullStorage implements WebStorage {
getItem(key: string): string { return ''; }
getItem(key: string): string { return null; }
removeItem(key: string) {/**/}
setItem(key: string, data: string): void {/**/}
}

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

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

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