@appbaseio/analytics
Advanced tools
Comparing version 1.0.0-alpha to 1.0.0-alpha.1
@@ -118,3 +118,4 @@ 'use strict'; | ||
this.searchState = null; | ||
this.filters = null; // custom headers | ||
this.filters = null; | ||
this.emptyQuery = config.emptyQuery !== undefined ? config.emptyQuery : true; // custom headers | ||
@@ -243,2 +244,12 @@ this.headers = null; | ||
AppbaseAnalytics.prototype.enableEmptyQuery = function () { | ||
this.emptyQuery = true; | ||
return this; | ||
}; | ||
AppbaseAnalytics.prototype.disableEmptyQuery = function () { | ||
this.emptyQuery = false; | ||
return this; | ||
}; | ||
AppbaseAnalytics.prototype.registerClick = function (clickPosition, isSuggestion) { | ||
@@ -276,4 +287,4 @@ if (Number.isNaN(parseInt(clickPosition, 10))) { | ||
AppbaseAnalytics.prototype.getAnalyticsHeaders = function () { | ||
return _extends({}, this.searchQuery !== undefined ? { | ||
'X-Search-Query': this.searchQuery | ||
return _extends({}, this.searchQuery || this.emptyQuery ? { | ||
'X-Search-Query': this.searchQuery || '' | ||
} : null, {}, this.searchID ? { | ||
@@ -280,0 +291,0 @@ 'X-Search-Id': this.searchID |
@@ -114,3 +114,4 @@ import fetch from 'cross-fetch'; | ||
this.searchState = null; | ||
this.filters = null; // custom headers | ||
this.filters = null; | ||
this.emptyQuery = config.emptyQuery !== undefined ? config.emptyQuery : true; // custom headers | ||
@@ -239,2 +240,12 @@ this.headers = null; | ||
AppbaseAnalytics.prototype.enableEmptyQuery = function () { | ||
this.emptyQuery = true; | ||
return this; | ||
}; | ||
AppbaseAnalytics.prototype.disableEmptyQuery = function () { | ||
this.emptyQuery = false; | ||
return this; | ||
}; | ||
AppbaseAnalytics.prototype.registerClick = function (clickPosition, isSuggestion) { | ||
@@ -272,4 +283,4 @@ if (Number.isNaN(parseInt(clickPosition, 10))) { | ||
AppbaseAnalytics.prototype.getAnalyticsHeaders = function () { | ||
return _extends({}, this.searchQuery !== undefined ? { | ||
'X-Search-Query': this.searchQuery | ||
return _extends({}, this.searchQuery || this.emptyQuery ? { | ||
'X-Search-Query': this.searchQuery || '' | ||
} : null, {}, this.searchID ? { | ||
@@ -276,0 +287,0 @@ 'X-Search-Id': this.searchID |
@@ -676,3 +676,4 @@ (function (global, factory) { | ||
this.searchState = null; | ||
this.filters = null; // custom headers | ||
this.filters = null; | ||
this.emptyQuery = config.emptyQuery !== undefined ? config.emptyQuery : true; // custom headers | ||
@@ -801,2 +802,12 @@ this.headers = null; | ||
AppbaseAnalytics.prototype.enableEmptyQuery = function () { | ||
this.emptyQuery = true; | ||
return this; | ||
}; | ||
AppbaseAnalytics.prototype.disableEmptyQuery = function () { | ||
this.emptyQuery = false; | ||
return this; | ||
}; | ||
AppbaseAnalytics.prototype.registerClick = function (clickPosition, isSuggestion) { | ||
@@ -834,4 +845,4 @@ if (Number.isNaN(parseInt(clickPosition, 10))) { | ||
AppbaseAnalytics.prototype.getAnalyticsHeaders = function () { | ||
return _extends({}, this.searchQuery !== undefined ? { | ||
'X-Search-Query': this.searchQuery | ||
return _extends({}, this.searchQuery || this.emptyQuery ? { | ||
'X-Search-Query': this.searchQuery || '' | ||
} : null, {}, this.searchID ? { | ||
@@ -838,0 +849,0 @@ 'X-Search-Id': this.searchID |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).aa=e()}(this,(function(){"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function e(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}function r(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function n(t){var e="";return t&&Object.keys(t).forEach((function(r,n){e+=r+"="+t[r],n<Object.keys(t).length-1&&(e+=",")})),e}function o(t){return t&&""!==t.trim()?t:"https://scalr.api.appbase.io"}function i(t){void 0===t&&(t="");for(var e,r=t,n="",o=0,i=0,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|i)||(s="=",i%1);n+=s.charAt(63&o>>8-i%1*8)){if((e=r.charCodeAt(i+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');o=o<<8|e}return n}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var a=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){var r=function(t){function e(){this.fetch=!1,this.DOMException=t.DOMException}return e.prototype=t,new e}("undefined"!=typeof self?self:s);!function(t){!function(e){var r={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(r.arrayBuffer)var n=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(t){return t&&n.indexOf(Object.prototype.toString.call(t))>-1};function i(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 s(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r.iterable&&(e[Symbol.iterator]=function(){return e}),e}function h(t){this.map={},t instanceof h?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function c(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function f(t){var e=new FileReader,r=c(e);return e.readAsArrayBuffer(t),r}function l(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:r.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():r.arrayBuffer&&r.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=l(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||o(t))?this._bodyArrayBuffer=l(t):this._bodyText=t=Object.prototype.toString.call(t):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):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var t=u(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?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var t,e,r,n=u(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=c(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(b)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,e){t=i(t),e=s(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},h.prototype.delete=function(t){delete this.map[i(t)]},h.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},h.prototype.set=function(t,e){this.map[i(t)]=s(e)},h.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),a(t)},h.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),a(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),a(t)},r.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var d=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var r,n,o=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),d.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function b(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function m(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},p.call(y.prototype),p.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},m.error=function(){var t=new m(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];m.redirect=function(t,e){if(-1===v.indexOf(e))throw new RangeError("Invalid status code");return new m(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function w(t,n){return new Promise((function(o,i){var s=new y(t,n);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var n="response"in a?a.response:a.responseText;o(new m(n,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&r.blob&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",u)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}w.polyfill=!0,t.fetch||(t.fetch=w,t.Headers=h,t.Request=y,t.Response=m),e.Headers=h,e.Request=y,e.Response=m,e.fetch=w}({})}(r),delete r.fetch.polyfill,(e=r.fetch).default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,t.exports=e}));a.fetch,a.Headers,a.Request,a.Response;function h(t){void 0===t&&(t={}),this.index=t.index,this.credentials=t.credentials,this.url=o(t.url),this.userID=t.userID,this.customEvents=t.customEvents,this.searchQuery=void 0,this.searchID=void 0,this.searchState=null,this.filters=null,this.headers=null}return function(s){void 0===s&&(s={});var u=new h(s);return h.prototype.setIndex=function(t){return this.index=t,this},h.prototype.setCredentials=function(t){return this.credentials=t,this},h.prototype.setURL=function(t){return this.url=o(t),this},h.prototype.setHeaders=function(t){return this.headers=t,this},h.prototype.setSearchQuery=function(t){return this.searchQuery=t,this},h.prototype.clearSearchQuery=function(){return this.searchQuery=void 0,this},h.prototype.setSearchID=function(t){return this.searchID=t,this},h.prototype.clearSearchID=function(){return this.searchID=void 0,this},h.prototype.setSearchState=function(t){return this.searchState=t,this},h.prototype.clearSearchState=function(){return this.searchState=null,this},h.prototype.setUserID=function(t){return this.userID=t,this},h.prototype.clearUserID=function(){return this.userID=null,this},h.prototype.setCustomEvents=function(t){return this.customEvents=t,this},h.prototype.clearCustomEvents=function(){return this.customEvents=null,this},h.prototype.addCustomEvent=function(e){return this.customEvents=t({},this.customEvents,{customEvent:e}),this},h.prototype.removeCustomEvent=function(t){var n=this.customEvents,o=(n[t],e(n,[t].map(r)));return this.customEvents=o,this},h.prototype.setFilters=function(t){return this.filters=t,this},h.prototype.clearFilters=function(){return this.filters=null,this},h.prototype.addFilter=function(e){return this.filters=t({},this.filters,{filter:e}),this},h.prototype.removeFilter=function(t){var n=this.filters,o=(n[t],e(n,[t].map(r)));return this.filters=o,this},h.prototype.registerClick=function(e,r){if(Number.isNaN(parseInt(e,10)))throw new Error("appbase-analytics: click position must be an integer.");var n=this._recordEventHeaders();return a(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:t({},n,{},r?{"X-Search-Suggestions-Click":!0,"X-Search-Suggestions-ClickPosition":e}:{"X-Search-Click":!0,"X-Search-ClickPosition":e})})},h.prototype.registerConversion=function(){var e=this._recordEventHeaders();return a(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:t({},e,{"X-Search-Conversion":!0})})},h.prototype.getAnalyticsHeaders=function(){return t({},void 0!==this.searchQuery?{"X-Search-Query":this.searchQuery}:null,{},this.searchID?{"X-Search-Id":this.searchID}:null,{},this.searchState?{"X-Search-State":JSON.stringify(this.searchState)}:null,{},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":n(this.customEvents)}:null,{},this.filters?{"X-Search-Filters":n(this.filters)}:null)},h.prototype._recordEventHeaders=function(){if(!this.index)throw new Error("appbase-analytics: A valid index must be present to record an event.");if(!this.credentials)throw new Error("appbase-analytics: Auth credentials is missing.");if(!this.searchID)throw new Error("appbase-analytics: searchID must be present to record an event.");return t({},this.headers,{"Content-Type":"application/json",Authorization:"Basic "+i(this.credentials),"X-Search-Id":this.searchID},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":n(this.customEvents)}:null)},u}})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).aa=e()}(this,(function(){"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function e(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)r=i[n],e.indexOf(r)>=0||(o[r]=t[r]);return o}function r(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function n(t){var e="";return t&&Object.keys(t).forEach((function(r,n){e+=r+"="+t[r],n<Object.keys(t).length-1&&(e+=",")})),e}function o(t){return t&&""!==t.trim()?t:"https://scalr.api.appbase.io"}function i(t){void 0===t&&(t="");for(var e,r=t,n="",o=0,i=0,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|i)||(s="=",i%1);n+=s.charAt(63&o>>8-i%1*8)){if((e=r.charCodeAt(i+=.75))>255)throw new Error('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');o=o<<8|e}return n}var s="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var a=function(t,e){return t(e={exports:{}},e.exports),e.exports}((function(t,e){var r=function(t){function e(){this.fetch=!1,this.DOMException=t.DOMException}return e.prototype=t,new e}("undefined"!=typeof self?self:s);!function(t){!function(e){var r={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(r.arrayBuffer)var n=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],o=ArrayBuffer.isView||function(t){return t&&n.indexOf(Object.prototype.toString.call(t))>-1};function i(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 s(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var e={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return r.iterable&&(e[Symbol.iterator]=function(){return e}),e}function u(t){this.map={},t instanceof u?t.forEach((function(t,e){this.append(e,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(e){this.append(e,t[e])}),this)}function h(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function c(t){return new Promise((function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}}))}function f(t){var e=new FileReader,r=c(e);return e.readAsArrayBuffer(t),r}function p(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){var e;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:r.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:r.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():r.arrayBuffer&&r.blob&&((e=t)&&DataView.prototype.isPrototypeOf(e))?(this._bodyArrayBuffer=p(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||o(t))?this._bodyArrayBuffer=p(t):this._bodyText=t=Object.prototype.toString.call(t):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):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var t=h(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?h(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(f)}),this.text=function(){var t,e,r,n=h(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=c(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},r.formData&&(this.formData=function(){return this.text().then(b)}),this.json=function(){return this.text().then(JSON.parse)},this}u.prototype.append=function(t,e){t=i(t),e=s(e);var r=this.map[t];this.map[t]=r?r+", "+e:e},u.prototype.delete=function(t){delete this.map[i(t)]},u.prototype.get=function(t){return t=i(t),this.has(t)?this.map[t]:null},u.prototype.has=function(t){return this.map.hasOwnProperty(i(t))},u.prototype.set=function(t,e){this.map[i(t)]=s(e)},u.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},u.prototype.keys=function(){var t=[];return this.forEach((function(e,r){t.push(r)})),a(t)},u.prototype.values=function(){var t=[];return this.forEach((function(e){t.push(e)})),a(t)},u.prototype.entries=function(){var t=[];return this.forEach((function(e,r){t.push([r,e])})),a(t)},r.iterable&&(u.prototype[Symbol.iterator]=u.prototype.entries);var d=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function y(t,e){var r,n,o=(e=e||{}).body;if(t instanceof y){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new u(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",!e.headers&&this.headers||(this.headers=new u(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),d.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function b(t){var e=new FormData;return t.trim().split("&").forEach((function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}})),e}function m(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new u(e.headers),this.url=e.url||"",this._initBody(t)}y.prototype.clone=function(){return new y(this,{body:this._bodyInit})},l.call(y.prototype),l.call(m.prototype),m.prototype.clone=function(){return new m(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new u(this.headers),url:this.url})},m.error=function(){var t=new m(null,{status:0,statusText:""});return t.type="error",t};var v=[301,302,303,307,308];m.redirect=function(t,e){if(-1===v.indexOf(e))throw new RangeError("Invalid status code");return new m(null,{status:e,headers:{location:t}})},e.DOMException=t.DOMException;try{new e.DOMException}catch(t){e.DOMException=function(t,e){this.message=t,this.name=e;var r=Error(t);this.stack=r.stack},e.DOMException.prototype=Object.create(Error.prototype),e.DOMException.prototype.constructor=e.DOMException}function E(t,n){return new Promise((function(o,i){var s=new y(t,n);if(s.signal&&s.signal.aborted)return i(new e.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function h(){a.abort()}a.onload=function(){var t,e,r={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",e=new u,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}})),e)};r.url="responseURL"in a?a.responseURL:r.headers.get("X-Request-URL");var n="response"in a?a.response:a.responseText;o(new m(n,r))},a.onerror=function(){i(new TypeError("Network request failed"))},a.ontimeout=function(){i(new TypeError("Network request failed"))},a.onabort=function(){i(new e.DOMException("Aborted","AbortError"))},a.open(s.method,s.url,!0),"include"===s.credentials?a.withCredentials=!0:"omit"===s.credentials&&(a.withCredentials=!1),"responseType"in a&&r.blob&&(a.responseType="blob"),s.headers.forEach((function(t,e){a.setRequestHeader(e,t)})),s.signal&&(s.signal.addEventListener("abort",h),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",h)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}E.polyfill=!0,t.fetch||(t.fetch=E,t.Headers=u,t.Request=y,t.Response=m),e.Headers=u,e.Request=y,e.Response=m,e.fetch=E}({})}(r),delete r.fetch.polyfill,(e=r.fetch).default=r.fetch,e.fetch=r.fetch,e.Headers=r.Headers,e.Request=r.Request,e.Response=r.Response,t.exports=e}));a.fetch,a.Headers,a.Request,a.Response;function u(t){void 0===t&&(t={}),this.index=t.index,this.credentials=t.credentials,this.url=o(t.url),this.userID=t.userID,this.customEvents=t.customEvents,this.searchQuery=void 0,this.searchID=void 0,this.searchState=null,this.filters=null,this.emptyQuery=void 0===t.emptyQuery||t.emptyQuery,this.headers=null}return function(s){void 0===s&&(s={});var h=new u(s);return u.prototype.setIndex=function(t){return this.index=t,this},u.prototype.setCredentials=function(t){return this.credentials=t,this},u.prototype.setURL=function(t){return this.url=o(t),this},u.prototype.setHeaders=function(t){return this.headers=t,this},u.prototype.setSearchQuery=function(t){return this.searchQuery=t,this},u.prototype.clearSearchQuery=function(){return this.searchQuery=void 0,this},u.prototype.setSearchID=function(t){return this.searchID=t,this},u.prototype.clearSearchID=function(){return this.searchID=void 0,this},u.prototype.setSearchState=function(t){return this.searchState=t,this},u.prototype.clearSearchState=function(){return this.searchState=null,this},u.prototype.setUserID=function(t){return this.userID=t,this},u.prototype.clearUserID=function(){return this.userID=null,this},u.prototype.setCustomEvents=function(t){return this.customEvents=t,this},u.prototype.clearCustomEvents=function(){return this.customEvents=null,this},u.prototype.addCustomEvent=function(e){return this.customEvents=t({},this.customEvents,{customEvent:e}),this},u.prototype.removeCustomEvent=function(t){var n=this.customEvents,o=(n[t],e(n,[t].map(r)));return this.customEvents=o,this},u.prototype.setFilters=function(t){return this.filters=t,this},u.prototype.clearFilters=function(){return this.filters=null,this},u.prototype.addFilter=function(e){return this.filters=t({},this.filters,{filter:e}),this},u.prototype.removeFilter=function(t){var n=this.filters,o=(n[t],e(n,[t].map(r)));return this.filters=o,this},u.prototype.enableEmptyQuery=function(){return this.emptyQuery=!0,this},u.prototype.disableEmptyQuery=function(){return this.emptyQuery=!1,this},u.prototype.registerClick=function(e,r){if(Number.isNaN(parseInt(e,10)))throw new Error("appbase-analytics: click position must be an integer.");var n=this._recordEventHeaders();return a(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:t({},n,{},r?{"X-Search-Suggestions-Click":!0,"X-Search-Suggestions-ClickPosition":e}:{"X-Search-Click":!0,"X-Search-ClickPosition":e})})},u.prototype.registerConversion=function(){var e=this._recordEventHeaders();return a(this.url+"/"+this.index+"/_analytics",{method:"POST",headers:t({},e,{"X-Search-Conversion":!0})})},u.prototype.getAnalyticsHeaders=function(){return t({},this.searchQuery||this.emptyQuery?{"X-Search-Query":this.searchQuery||""}:null,{},this.searchID?{"X-Search-Id":this.searchID}:null,{},this.searchState?{"X-Search-State":JSON.stringify(this.searchState)}:null,{},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":n(this.customEvents)}:null,{},this.filters?{"X-Search-Filters":n(this.filters)}:null)},u.prototype._recordEventHeaders=function(){if(!this.index)throw new Error("appbase-analytics: A valid index must be present to record an event.");if(!this.credentials)throw new Error("appbase-analytics: Auth credentials is missing.");if(!this.searchID)throw new Error("appbase-analytics: searchID must be present to record an event.");return t({},this.headers,{"Content-Type":"application/json",Authorization:"Basic "+i(this.credentials),"X-Search-Id":this.searchID},this.userID?{"X-User-Id":this.userID}:null,{},this.customEvents?{"X-Search-CustomEvent":n(this.customEvents)}:null)},h}})); | ||
//# sourceMappingURL=analytics.umd.min.js.map |
{ | ||
"name": "@appbaseio/analytics", | ||
"version": "1.0.0-alpha", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Universal analytics library for appbase.io apps", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
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
146916
1315