coveo.analytics
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -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(10),i=t.coveoua||{};t.coveoua=o["default"],t.coveoanalytics=r,i.q&&i.q.forEach(function(t){return o["default"].apply(void 0,t)}),Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=i}).call(e,function(){return this}())},function(t,e,n){"use strict";var o="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},r=n(2),i=n(8),s=n(9),a=function(){function t(){}return t.prototype.init=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||r.Endpoints["default"],this.client=new r.Client({token:t,endpoint:e});else{if("object"!==("undefined"==typeof t?"undefined":o(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}},t.prototype.send=function(t,e){if("undefined"==typeof this.client)throw new Error("You must call init before sending an event");switch(e=i["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:s.popFromObject(e,"contentIdKey"),contentIdValue:s.popFromObject(e,"contentIdValue"),contentType:s.popFromObject(e,"contentType"),customData:e});default:throw new Error("Event type: '"+t+"' not implemented")}},t.prototype.onLoad=function(t){if("undefined"==typeof t)throw new Error("You must pass a function when you call 'onLoad'");t()},t}();e.SimpleAPI=a;var u=new a;e.SimpleAnalytics=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=u[t];if(o)return o.apply(u,e)},Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=e.SimpleAnalytics},function(t,e,n){(function(t){"use strict";function o(t){return t.json().then(function(e){return e.raw=t,e})}var r=n(4),i=n(6);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 s=function(){function n(t){if("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 n.prototype.sendEvent=function(e,n){return t(this.getRestEndpoint()+"/analytics/"+e,{method:"POST",headers:this.getHeaders(),mode:"cors",body:JSON.stringify(n),credentials:"include"})},n.prototype.sendSearchEvent=function(t){return this.sendEvent("search",t).then(o)},n.prototype.sendClickEvent=function(t){return this.sendEvent("click",t).then(o)},n.prototype.sendCustomEvent=function(t){return this.sendEvent("custom",t).then(o)},n.prototype.sendViewEvent=function(t){if(""===t.referrer&&delete t.referrer,i.hasDocumentLocation()){var e=new r.HistoryStore,n={name:"PageView",value:document.location.toString(),time:JSON.stringify(new Date),title:document.title};e.addElement(n)}return this.sendEvent("view",t).then(o)},n.prototype.getVisit=function(){return t(this.getRestEndpoint()+"/analytics/visit").then(o)},n.prototype.getHealth=function(){return t(this.getRestEndpoint()+"/analytics/monitoring/health").then(o)},n.prototype.getRestEndpoint=function(){return this.endpoint+"/rest/"+this.version},n.prototype.getHeaders=function(){var t={"Content-Type":"application/json"};return this.token&&(t.Authorization="Bearer "+this.token),t},n}();e.Client=s,Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=s}).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(p)}),this.json=function(){return this.text().then(JSON.parse)},this}function l(t){var e=t.toUpperCase();return m.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 p(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 h(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 m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];f.prototype.clone=function(){return new f(this)},c.call(f.prototype),c.call(h.prototype),h.prototype.clone=function(){return new h(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new r(this.headers),url:this.url})},h.error=function(){var t=new h(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];h.redirect=function(t,e){if(v.indexOf(e)===-1)throw new RangeError("Invalid status code");return new h(null,{status:e,headers:{location:t}})},t.Headers=r,t.Request=f,t.Response=h,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 h(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,n){"use strict";var o=n(5);e.STORE_KEY="__coveo.analytics.history",e.MAX_NUMBER_OF_HISTORY_ELEMENTS=20,e.MIN_THRESHOLD_FOR_DUPLICATE_VALUE=6e4;var r=function(){function t(t){this.store=t||o.getAvailableStorage()}return t.prototype.addElement=function(t){t.internalTime=(new Date).getTime();var e=this.getHistory();null!=e?this.isValidEntry(t)&&this.setHistory([t].concat(e)):this.setHistory([t])},t.prototype.getHistory=function(){try{return JSON.parse(this.store.getItem(e.STORE_KEY))}catch(t){return[]}},t.prototype.setHistory=function(t){try{this.store.setItem(e.STORE_KEY,JSON.stringify(t.slice(0,e.MAX_NUMBER_OF_HISTORY_ELEMENTS)))}catch(n){}},t.prototype.clear=function(){try{this.store.removeItem(e.STORE_KEY)}catch(t){}},t.prototype.getMostRecentElement=function(){var t=this.getHistory();if(null!=t){var e=t.sort(function(t,e){return null==t.internalTime&&null==e.internalTime?0:null==t.internalTime&&null!=e.internalTime?1:null!=t.internalTime&&null==e.internalTime?-1:e.internalTime-t.internalTime});return e[0]}return null},t.prototype.isValidEntry=function(t){var n=this.getMostRecentElement();return!n||n.value!=t.value||t.internalTime-n.internalTime>e.MIN_THRESHOLD_FOR_DUPLICATE_VALUE},t}();e.HistoryStore=r,Object.defineProperty(e,"__esModule",{value:!0}),e["default"]=r},function(t,e,n){"use strict";function o(){return r.hasCookieStorage()?new s:r.hasSessionStorage()?sessionStorage:r.hasLocalStorage()?localStorage:new a}var r=n(6),i=n(7);e.getAvailableStorage=o;var s=function(){function t(){}return t.prototype.getItem=function(t){return i.Cookie.get(t)},t.prototype.removeItem=function(t){i.Cookie.erase(t)},t.prototype.setItem=function(t,e){i.Cookie.set(t,e)},t}();e.CookieStorage=s;var a=function(){function t(){}return t.prototype.getItem=function(t){return null},t.prototype.removeItem=function(t){},t.prototype.setItem=function(t,e){},t}();e.NullStorage=a},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}function i(){return null!==document}function s(){return i()&&null!==document.location}e.hasLocalStorage=n,e.hasSessionStorage=o,e.hasCookieStorage=r,e.hasDocument=i,e.hasDocumentLocation=s},function(t,e){"use strict";var n=function(){function t(){}return t.set=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))},t.get=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},t.erase=function(e){t.set(e,"",-1)},t}();e.Cookie=n},function(t,e){"use strict";var n=Object.prototype.hasOwnProperty,o=Object.getOwnPropertySymbols,r=Object.prototype.propertyIsEnumerable,i=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");var s=Object(t);return e.forEach(function(t){var e=Object(t);for(var i in e)n.call(e,i)&&(s[i]=e[i]);if(o){var a=o(e);a.forEach(function(t){r.call(e,t)&&(s[t]=e[t])})}}),s};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(4);e.history=i;var s=n(11);e.donottrack=s},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(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return t[r].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){(function(t){"use strict";var r=n(1),o=n(10),i=t.coveoua||{};t.coveoua=r.default,t.coveoanalytics=o,i.q&&i.q.forEach(function(t){return r.default.apply(void 0,t)}),Object.defineProperty(e,"__esModule",{value:!0}),e.default=i}).call(e,function(){return this}())},function(t,e,n){"use strict";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},o=n(2),i=n(8),s=n(9),a=function(){function t(){}return t.prototype.init=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||o.Endpoints.default,this.client=new o.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}},t.prototype.send=function(t,e){if("undefined"==typeof this.client)throw new Error("You must call init before sending an event");switch(e=i.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:s.popFromObject(e,"contentIdKey"),contentIdValue:s.popFromObject(e,"contentIdValue"),contentType:s.popFromObject(e,"contentType"),customData:e});default:throw new Error("Event type: '"+t+"' not implemented")}},t.prototype.onLoad=function(t){if("undefined"==typeof t)throw new Error("You must pass a function when you call 'onLoad'");t()},t}();e.SimpleAPI=a;var u=new a;e.SimpleAnalytics=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=u[t];if(r)return r.apply(u,e)},Object.defineProperty(e,"__esModule",{value:!0}),e.default=e.SimpleAnalytics},function(t,e,n){(function(t){"use strict";function r(t){return t.json().then(function(e){return e.raw=t,e})}var o=n(4),i=n(6);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 s=function(){function n(t){if("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 n.prototype.sendEvent=function(e,n){return t(this.getRestEndpoint()+"/analytics/"+e,{method:"POST",headers:this.getHeaders(),mode:"cors",body:JSON.stringify(n),credentials:"include"})},n.prototype.sendSearchEvent=function(t){return this.sendEvent("search",t).then(r)},n.prototype.sendClickEvent=function(t){return this.sendEvent("click",t).then(r)},n.prototype.sendCustomEvent=function(t){return this.sendEvent("custom",t).then(r)},n.prototype.sendViewEvent=function(t){if(""===t.referrer&&delete t.referrer,i.hasDocumentLocation()){var e=new o.HistoryStore,n={name:"PageView",value:document.location.toString(),time:JSON.stringify(new Date),title:document.title};e.addElement(n)}return this.sendEvent("view",t).then(r)},n.prototype.getVisit=function(){return t(this.getRestEndpoint()+"/analytics/visit").then(r)},n.prototype.getHealth=function(){return t(this.getRestEndpoint()+"/analytics/monitoring/health").then(r)},n.prototype.getRestEndpoint=function(){return this.endpoint+"/rest/"+this.version},n.prototype.getHeaders=function(){var t={"Content-Type":"application/json"};return this.token&&(t.Authorization="Bearer "+this.token),t},n}();e.Client=s,Object.defineProperty(e,"__esModule",{value:!0}),e.default=s}).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 r(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return v.iterable&&(e[Symbol.iterator]=function(){return e}),e}function o(t){this.map={},t instanceof o?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,n=s(e);return e.readAsArrayBuffer(t),n}function u(t){var e=new FileReader,n=s(e);return e.readAsText(t),n}function c(t){for(var e=new Uint8Array(t),n=new Array(e.length),r=0;r<e.length;r++)n[r]=String.fromCharCode(e[r]);return n.join("")}function f(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function l(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(v.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(v.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(v.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(v.arrayBuffer&&v.blob&&w(t))this._bodyArrayBuffer=f(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!v.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!g(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=f(t)}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):v.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},v.blob&&(this.blob=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));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._bodyArrayBuffer?i(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(a)}),this.text=function(){var t=i(this);if(t)return t;if(this._bodyBlob)return u(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(c(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},v.formData&&(this.formData=function(){return this.text().then(p)}),this.json=function(){return this.text().then(JSON.parse)},this}function d(t){var e=t.toUpperCase();return E.indexOf(e)>-1?e:t}function h(t,e){e=e||{};var n=e.body;if("string"==typeof t)this.url=t;else{if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new o(t.headers)),this.method=t.method,this.mode=t.mode,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new o(e.headers)),this.method=d(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 p(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var n=t.split("="),r=n.shift().replace(/\+/g," "),o=n.join("=").replace(/\+/g," ");e.append(decodeURIComponent(r),decodeURIComponent(o))}}),e}function y(t){var e=new o;return t.split("\r\n").forEach(function(t){var n=t.split(":"),r=n.shift().trim();if(r){var o=n.join(":").trim();e.append(r,o)}}),e}function m(t,e){e||(e={}),this.type="default",this.status="status"in e?e.status:200,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new o(e.headers),this.url=e.url||"",this._initBody(t)}if(!t.fetch){var v={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};if(v.arrayBuffer)var b=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],w=function(t){return t&&DataView.prototype.isPrototypeOf(t)},g=ArrayBuffer.isView||function(t){return t&&b.indexOf(Object.prototype.toString.call(t))>-1};o.prototype.append=function(t,r){t=e(t),r=n(r);var o=this.map[t];this.map[t]=o?o+","+r:r},o.prototype.delete=function(t){delete this.map[e(t)]},o.prototype.get=function(t){return t=e(t),this.has(t)?this.map[t]:null},o.prototype.has=function(t){return this.map.hasOwnProperty(e(t))},o.prototype.set=function(t,r){this.map[e(t)]=n(r)},o.prototype.forEach=function(t,e){for(var n in this.map)this.map.hasOwnProperty(n)&&t.call(e,this.map[n],n,this)},o.prototype.keys=function(){var t=[];return this.forEach(function(e,n){t.push(n)}),r(t)},o.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),r(t)},o.prototype.entries=function(){var t=[];return this.forEach(function(e,n){t.push([n,e])}),r(t)},v.iterable&&(o.prototype[Symbol.iterator]=o.prototype.entries);var E=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];h.prototype.clone=function(){return new h(this,{body:this._bodyInit})},l.call(h.prototype),l.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new o(this.headers),url:this.url})},m.error=function(){var t=new m(null,{status:0,statusText:""});return t.type="error",t};var _=[301,302,303,307,308];m.redirect=function(t,e){if(_.indexOf(e)===-1)throw new RangeError("Invalid status code");return new m(null,{status:e,headers:{location:t}})},t.Headers=o,t.Request=h,t.Response=m,t.fetch=function(t,e){return new Promise(function(n,r){var o=new h(t,e),i=new XMLHttpRequest;i.onload=function(){var t={status:i.status,statusText:i.statusText,headers:y(i.getAllResponseHeaders()||"")};t.url="responseURL"in i?i.responseURL:t.headers.get("X-Request-URL");var e="response"in i?i.response:i.responseText;n(new m(e,t))},i.onerror=function(){r(new TypeError("Network request failed"))},i.ontimeout=function(){r(new TypeError("Network request failed"))},i.open(o.method,o.url,!0),"include"===o.credentials&&(i.withCredentials=!0),"responseType"in i&&v.blob&&(i.responseType="blob"),o.headers.forEach(function(t,e){i.setRequestHeader(e,t)}),i.send("undefined"==typeof o._bodyInit?null:o._bodyInit)})},t.fetch.polyfill=!0}}("undefined"!=typeof self?self:this),t.exports=self.fetch},function(t,e,n){"use strict";var r=n(5),o=n(6);e.STORE_KEY="__coveo.analytics.history",e.MAX_NUMBER_OF_HISTORY_ELEMENTS=20,e.MIN_THRESHOLD_FOR_DUPLICATE_VALUE=6e4,e.MAX_VALUE_SIZE=75;var i=function(){function t(t){this.store=t||r.getAvailableStorage(),this.store instanceof r.CookieStorage||!o.hasCookieStorage()||(new r.CookieStorage).removeItem(e.STORE_KEY)}return t.prototype.addElement=function(t){t.internalTime=(new Date).getTime(),this.cropQueryElement(t);var e=this.getHistory();null!=e?this.isValidEntry(t)&&this.setHistory([t].concat(e)):this.setHistory([t])},t.prototype.getHistory=function(){try{return JSON.parse(this.store.getItem(e.STORE_KEY))}catch(t){return[]}},t.prototype.setHistory=function(t){try{this.store.setItem(e.STORE_KEY,JSON.stringify(t.slice(0,e.MAX_NUMBER_OF_HISTORY_ELEMENTS)))}catch(t){}},t.prototype.clear=function(){try{this.store.removeItem(e.STORE_KEY)}catch(t){}},t.prototype.getMostRecentElement=function(){var t=this.getHistory();if(null!=t){var e=t.sort(function(t,e){return null==t.internalTime&&null==e.internalTime?0:null==t.internalTime&&null!=e.internalTime?1:null!=t.internalTime&&null==e.internalTime?-1:e.internalTime-t.internalTime});return e[0]}return null},t.prototype.cropQueryElement=function(t){t.name&&"query"==t.name.toLowerCase()&&null!=t.value&&(t.value=t.value.slice(0,e.MAX_VALUE_SIZE))},t.prototype.isValidEntry=function(t){var n=this.getMostRecentElement();return!n||n.value!=t.value||t.internalTime-n.internalTime>e.MIN_THRESHOLD_FOR_DUPLICATE_VALUE},t}();e.HistoryStore=i,Object.defineProperty(e,"__esModule",{value:!0}),e.default=i},function(t,e,n){"use strict";function r(){return e.preferredStorage?e.preferredStorage:o.hasLocalStorage()?localStorage:o.hasCookieStorage()?new s:o.hasSessionStorage()?sessionStorage:new a}var o=n(6),i=n(7);e.preferredStorage=null,e.getAvailableStorage=r;var s=function(){function t(){}return t.prototype.getItem=function(t){return i.Cookie.get(t)},t.prototype.removeItem=function(t){i.Cookie.erase(t)},t.prototype.setItem=function(t,e){i.Cookie.set(t,e)},t}();e.CookieStorage=s;var a=function(){function t(){}return t.prototype.getItem=function(t){return null},t.prototype.removeItem=function(t){},t.prototype.setItem=function(t,e){},t}();e.NullStorage=a},function(t,e){"use strict";function n(){try{return"localStorage"in window&&null!==window.localStorage}catch(t){return!1}}function r(){try{return"sessionStorage"in window&&null!==window.sessionStorage}catch(t){return!1}}function o(){return navigator.cookieEnabled}function i(){return null!==document}function s(){return i()&&null!==document.location}e.hasLocalStorage=n,e.hasSessionStorage=r,e.hasCookieStorage=o,e.hasDocument=i,e.hasDocumentLocation=s},function(t,e){"use strict";var n=function(){function t(){}return t.set=function(e,n,r){var o,i,s,a,u;r?(s=new Date,s.setTime(s.getTime()+r),a="; expires="+s.toGMTString()):a="",u=location.hostname,u.indexOf(".")===-1?document.cookie=e+"="+n+a+"; path=/":(i=u.split("."),i.shift(),o="."+i.join("."),document.cookie=e+"="+n+a+"; path=/; domain="+o,null!=t.get(e)&&t.get(e)==n||(o="."+u,document.cookie=e+"="+n+a+"; path=/; domain="+o))},t.get=function(t){for(var e=t+"=",n=document.cookie.split(";"),r=0;r<n.length;r++){var o=n[r];if(o=o.replace(/^\s+/,""),0==o.indexOf(e))return o.substring(e.length,o.length)}return null},t.erase=function(e){t.set(e,"",-1)},t}();e.Cookie=n},function(t,e){"use strict";var n=Object.prototype.hasOwnProperty,r=Object.getOwnPropertySymbols,o=Object.prototype.propertyIsEnumerable,i=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];if(void 0===t||null===t)throw new TypeError("Cannot convert undefined or null to object");var s=Object(t);return e.forEach(function(t){var e=Object(t);for(var i in e)n.call(e,i)&&(s[i]=e[i]);if(r){var a=r(e);a.forEach(function(t){o.call(e,t)&&(s[t]=e[t])})}}),s};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 r=n(2);e.analytics=r;var o=n(1);e.SimpleAnalytics=o;var i=n(4);e.history=i;var s=n(11);e.donottrack=s;var a=n(5);e.storage=a},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}]); | ||
//# sourceMappingURL=coveoua.js.map |
@@ -5,2 +5,3 @@ import { WebStorage } from './storage'; | ||
export declare const MIN_THRESHOLD_FOR_DUPLICATE_VALUE: number; | ||
export declare const MAX_VALUE_SIZE: number; | ||
export declare class HistoryStore { | ||
@@ -14,2 +15,3 @@ private store; | ||
getMostRecentElement(): HistoryElement; | ||
private cropQueryElement(elem); | ||
private isValidEntry(elem); | ||
@@ -16,0 +18,0 @@ } |
"use strict"; | ||
var storage_1 = require('./storage'); | ||
var detector = require('./detector'); | ||
exports.STORE_KEY = '__coveo.analytics.history'; | ||
exports.MAX_NUMBER_OF_HISTORY_ELEMENTS = 20; | ||
exports.MIN_THRESHOLD_FOR_DUPLICATE_VALUE = 1000 * 60; | ||
exports.MAX_VALUE_SIZE = 75; | ||
var HistoryStore = (function () { | ||
function HistoryStore(store) { | ||
this.store = store || storage_1.getAvailableStorage(); | ||
if (!(this.store instanceof storage_1.CookieStorage) && detector.hasCookieStorage()) { | ||
new storage_1.CookieStorage().removeItem(exports.STORE_KEY); | ||
} | ||
} | ||
@@ -13,2 +18,3 @@ ; | ||
elem.internalTime = new Date().getTime(); | ||
this.cropQueryElement(elem); | ||
var currentHistory = this.getHistory(); | ||
@@ -63,2 +69,7 @@ if (currentHistory != null) { | ||
}; | ||
HistoryStore.prototype.cropQueryElement = function (elem) { | ||
if (elem.name && elem.name.toLowerCase() == 'query' && elem.value != null) { | ||
elem.value = elem.value.slice(0, exports.MAX_VALUE_SIZE); | ||
} | ||
}; | ||
HistoryStore.prototype.isValidEntry = function (elem) { | ||
@@ -65,0 +76,0 @@ var lastEntry = this.getMostRecentElement(); |
@@ -5,2 +5,3 @@ import * as analytics from './analytics'; | ||
import * as donottrack from './donottrack'; | ||
export { analytics, donottrack, history, SimpleAnalytics }; | ||
import * as storage from './storage'; | ||
export { analytics, donottrack, history, SimpleAnalytics, storage }; |
@@ -10,2 +10,4 @@ "use strict"; | ||
exports.donottrack = donottrack; | ||
var storage = require('./storage'); | ||
exports.storage = storage; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
export declare let preferredStorage: WebStorage; | ||
export interface WebStorage { | ||
@@ -2,0 +3,0 @@ getItem(key: string): string; |
"use strict"; | ||
var detector = require('./detector'); | ||
var cookieutils_1 = require('./cookieutils'); | ||
exports.preferredStorage = null; | ||
function getAvailableStorage() { | ||
if (exports.preferredStorage) { | ||
return exports.preferredStorage; | ||
} | ||
if (detector.hasLocalStorage()) { | ||
return localStorage; | ||
} | ||
if (detector.hasCookieStorage()) { | ||
@@ -11,5 +18,2 @@ return new CookieStorage(); | ||
} | ||
if (detector.hasLocalStorage()) { | ||
return localStorage; | ||
} | ||
return new NullStorage(); | ||
@@ -16,0 +20,0 @@ } |
{ | ||
"name": "coveo.analytics", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "📈 Coveo analytics client (node and browser compatible) ", | ||
@@ -37,3 +37,3 @@ "main": "dist/index.js", | ||
"body-parser": "1.15.1", | ||
"coveralls": "2.11.14", | ||
"coveralls": "2.11.15", | ||
"es6-promise": "4.0.2", | ||
@@ -44,9 +44,9 @@ "exports-loader": "0.6.3", | ||
"jsdom": "9.8.2", | ||
"nyc": "8.3.2", | ||
"nyc": "9.0.1", | ||
"sinon": "1.17.6", | ||
"ts-loader": "^0.9.3", | ||
"ts-loader": "^1.2.0", | ||
"tslint": "3.15.1", | ||
"tslint-loader": "2.1.5", | ||
"typescript": "2.0.3", | ||
"webpack": "1.13.2" | ||
"typescript": "2.0.10", | ||
"webpack": "1.13.3" | ||
}, | ||
@@ -67,4 +67,4 @@ "files": [ | ||
"dependencies": { | ||
"whatwg-fetch": "^1.0.0" | ||
"whatwg-fetch": "^2.0.0" | ||
} | ||
} |
@@ -97,2 +97,15 @@ # ![coveo.analytics](./assets/coveo.analytics.js.png) | ||
### Choosing the type of storage for page view events | ||
There are 3 available storage you can use to store view events client side. | ||
- Cookie storage, which supports top level domain storage. This means that events from a.foo.com will be available from b.foo.com. | ||
Cookies have the limitation of not being able to store a lot of data, especially if your page view that are stored are long. | ||
- Local storage, which allows to store much more information client side, but has the drawback of not being able to acess data | ||
across multiple top level domain. | ||
- Session storage, which has roughly the same limitation and capability as Local storage, except that it is cleared when the web browser tab is closed. | ||
By default, the local storage option will automatically be chosen as the default storage, unless specified manually. | ||
### Contributing | ||
@@ -99,0 +112,0 @@ |
@@ -1,2 +0,3 @@ | ||
import {WebStorage, getAvailableStorage} from './storage'; | ||
import {WebStorage, getAvailableStorage, CookieStorage} from './storage'; | ||
import * as detector from './detector'; | ||
@@ -6,2 +7,3 @@ export const STORE_KEY: string = '__coveo.analytics.history'; | ||
export const MIN_THRESHOLD_FOR_DUPLICATE_VALUE: number = 1000 * 60; | ||
export const MAX_VALUE_SIZE = 75; | ||
@@ -12,2 +14,7 @@ export class HistoryStore { | ||
this.store = store || getAvailableStorage(); | ||
// cleanup any old cookie that we might have added | ||
// eg : we used cookies before, but switched to local storage | ||
if (!(this.store instanceof CookieStorage) && detector.hasCookieStorage()) { | ||
new CookieStorage().removeItem(STORE_KEY); | ||
} | ||
}; | ||
@@ -17,2 +24,3 @@ | ||
elem.internalTime = new Date().getTime(); | ||
this.cropQueryElement(elem); | ||
let currentHistory = this.getHistory(); | ||
@@ -74,2 +82,8 @@ if (currentHistory != null) { | ||
private cropQueryElement(elem: HistoryElement) { | ||
if (elem.name && elem.name.toLowerCase() == 'query' && elem.value != null) { | ||
elem.value = elem.value.slice(0, MAX_VALUE_SIZE); | ||
} | ||
} | ||
private isValidEntry(elem: HistoryElement): boolean { | ||
@@ -76,0 +90,0 @@ let lastEntry = this.getMostRecentElement(); |
@@ -5,2 +5,3 @@ import * as analytics from './analytics'; | ||
import * as donottrack from './donottrack'; | ||
import * as storage from './storage'; | ||
export { | ||
@@ -10,3 +11,4 @@ analytics, | ||
history, | ||
SimpleAnalytics | ||
SimpleAnalytics, | ||
storage | ||
} |
import * as detector from './detector'; | ||
import { Cookie } from './cookieutils'; | ||
export let preferredStorage: WebStorage = null; | ||
export interface WebStorage { | ||
@@ -11,2 +13,8 @@ getItem(key: string): string; | ||
export function getAvailableStorage(): WebStorage { | ||
if (preferredStorage) { | ||
return preferredStorage; | ||
} | ||
if (detector.hasLocalStorage()) { | ||
return localStorage; | ||
} | ||
if (detector.hasCookieStorage()) { | ||
@@ -18,5 +26,2 @@ return new CookieStorage(); | ||
} | ||
if (detector.hasLocalStorage()) { | ||
return localStorage; | ||
} | ||
return new NullStorage(); | ||
@@ -23,0 +28,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
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
177292
1519
128
+ Addedwhatwg-fetch@2.0.4(transitive)
- Removedwhatwg-fetch@1.1.1(transitive)
Updatedwhatwg-fetch@^2.0.0