@appbaseio/analytics
Advanced tools
Comparing version 2.1.0-beta to 2.1.1-beta
@@ -152,3 +152,4 @@ 'use strict'; | ||
filters: searchConfig.filters, | ||
hits: searchConfig.hits | ||
total_hits: searchConfig.totalHits, | ||
impressions: searchConfig.impressions | ||
}; | ||
@@ -155,0 +156,0 @@ |
@@ -148,3 +148,4 @@ import fetch from 'cross-fetch'; | ||
filters: searchConfig.filters, | ||
hits: searchConfig.hits | ||
total_hits: searchConfig.totalHits, | ||
impressions: searchConfig.impressions | ||
}; | ||
@@ -151,0 +152,0 @@ |
@@ -710,3 +710,4 @@ (function (global, factory) { | ||
filters: searchConfig.filters, | ||
hits: searchConfig.hits | ||
total_hits: searchConfig.totalHits, | ||
impressions: searchConfig.impressions | ||
}; | ||
@@ -713,0 +714,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).aa=t()}(this,(function(){"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function t(e){void 0===e&&(e="");for(var t,r=e,n="",o=0,i=0,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|i)||(s="=",i%1);n+=s.charAt(63&o>>8-i%1*8)){if((t=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|t}return n}var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var n=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){var n=function(e){function t(){this.fetch=!1,this.DOMException=e.DOMException}return t.prototype=e,new t}("undefined"!=typeof self?self:r);!function(e){!function(t){var r={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};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(e){return e&&n.indexOf(Object.prototype.toString.call(e))>-1};function i(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 s(e){return"string"!=typeof e&&(e=String(e)),e}function a(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r.iterable&&(t[Symbol.iterator]=function(){return t}),t}function u(e){this.map={},e instanceof u?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function c(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function h(e){var t=new FileReader,r=f(t);return t.readAsArrayBuffer(e),r}function l(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:r.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:r.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r.arrayBuffer&&r.blob&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=l(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=l(e):this._bodyText=e=Object.prototype.toString.call(e):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):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var e=c(this);if(e)return e;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?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(h)}),this.text=function(){var e,t,r,n=c(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=f(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[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(e,t){e=i(e),t=s(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},u.prototype.delete=function(e){delete this.map[i(e)]},u.prototype.get=function(e){return e=i(e),this.has(e)?this.map[e]:null},u.prototype.has=function(e){return this.map.hasOwnProperty(i(e))},u.prototype.set=function(e,t){this.map[i(e)]=s(t)},u.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},u.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),a(e)},u.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),a(e)},u.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),a(e)},r.iterable&&(u.prototype[Symbol.iterator]=u.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function p(e,t){var r,n,o=(t=t||{}).body;if(e instanceof p){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new u(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new u(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),y.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.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(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}})),t}function m(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new u(t.headers),this.url=t.url||"",this._initBody(e)}p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},d.call(p.prototype),d.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 e=new m(null,{status:0,statusText:""});return e.type="error",e};var v=[301,302,303,307,308];m.redirect=function(e,t){if(-1===v.indexOf(t))throw new RangeError("Invalid status code");return new m(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function w(e,n){return new Promise((function(o,i){var s=new p(e,n);if(s.signal&&s.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var e,t,r={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new u,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}})),t)};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 t.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(e,t){a.setRequestHeader(t,e)})),s.signal&&(s.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",c)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}w.polyfill=!0,e.fetch||(e.fetch=w,e.Headers=u,e.Request=p,e.Response=m),t.Headers=u,t.Request=p,t.Response=m,t.fetch=w}({})}(n),delete n.fetch.polyfill,(t=n.fetch).default=n.fetch,t.fetch=n.fetch,t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response,e.exports=t}));n.fetch,n.Headers,n.Request,n.Response;function o(e,t){if(null==e&&!t)throw new Error("appbase-analytics: query or queryID must be present to register a click/conversion event")}return{init:function(r){void 0===r&&(r={});var i={credentials:r.credentials,index:r.index,url:r.url,userID:r.userID,globalEventData:r.globalEventData,queryID:"",headers:null};return function(e){if(!e)throw new Error("appbase-analytics: A valid index must be present to record analytics events.")}(i.index),function(e){if(!e)throw new Error("appbase-analytics: Auth credentials is missing.")}(i.credentials),function(e){if(!e)throw new Error("appbase-analytics: URL is missing.")}(i.url),i._request=function(r,o,s){var a=e({},o,{user_id:i.userID,event_data:e({},o&&o.event_data,{},i.globalEventData)});return n(i.url+"/"+i.index+"/_analytics/"+r,{method:"PUT",headers:e({},i.headers,{"Content-Type":"application/json",Authorization:"Basic "+t(i.credentials)}),body:JSON.stringify(a)}).then((function(e){s&&s(null,e)})).catch((function(e){console.error(e),s&&s(e,null)}))},i.search=function(e,t){o(e.query,e.queryID);if(i._request){var r={query:e.query,query_id:e.queryID,event_data:e.eventData,filters:e.filters,hits:e.hits};i._request("search",r,(function(e,r){r&&r.json().then((function(e){e&&e.query_id&&(i.queryID=e.query_id)})).catch((function(e){console.error(e)})),t&&t(e,r)}))}},i.click=function(e,t){if(o(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),i._request){var r={click_on:e.objects,click_type:e.isSuggestionClick?"suggestion":"result",query:e.query,query_id:e.queryID,event_data:e.eventData};i._request("click",r,t)}},i.conversion=function(e,t){if(o(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),i._request){var r={conversion_on:e.objects,query:e.query,query_id:e.queryID,event_data:e.eventData};i._request("conversion",r,t)}},i.setUserID=function(e){i.userID=e},i.setGlobalEventData=function(e){i.globalEventData=e},i.setHeaders=function(e){i.headers=e},i}}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).aa=t()}(this,(function(){"use strict";function e(){return(e=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function t(e){void 0===e&&(e="");for(var t,r=e,n="",o=0,i=0,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|i)||(s="=",i%1);n+=s.charAt(63&o>>8-i%1*8)){if((t=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|t}return n}var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};var n=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){var n=function(e){function t(){this.fetch=!1,this.DOMException=e.DOMException}return t.prototype=e,new t}("undefined"!=typeof self?self:r);!function(e){!function(t){var r={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};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(e){return e&&n.indexOf(Object.prototype.toString.call(e))>-1};function i(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 s(e){return"string"!=typeof e&&(e=String(e)),e}function a(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return r.iterable&&(t[Symbol.iterator]=function(){return t}),t}function u(e){this.map={},e instanceof u?e.forEach((function(e,t){this.append(t,e)}),this):Array.isArray(e)?e.forEach((function(e){this.append(e[0],e[1])}),this):e&&Object.getOwnPropertyNames(e).forEach((function(t){this.append(t,e[t])}),this)}function c(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function f(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function h(e){var t=new FileReader,r=f(t);return t.readAsArrayBuffer(e),r}function l(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function d(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:r.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:r.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():r.arrayBuffer&&r.blob&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=l(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):r.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||o(e))?this._bodyArrayBuffer=l(e):this._bodyText=e=Object.prototype.toString.call(e):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):r.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},r.blob&&(this.blob=function(){var e=c(this);if(e)return e;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?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(h)}),this.text=function(){var e,t,r,n=c(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=f(t),t.readAsText(e),r;if(this._bodyArrayBuffer)return Promise.resolve(function(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[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(e,t){e=i(e),t=s(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},u.prototype.delete=function(e){delete this.map[i(e)]},u.prototype.get=function(e){return e=i(e),this.has(e)?this.map[e]:null},u.prototype.has=function(e){return this.map.hasOwnProperty(i(e))},u.prototype.set=function(e,t){this.map[i(e)]=s(t)},u.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},u.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),a(e)},u.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),a(e)},u.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),a(e)},r.iterable&&(u.prototype[Symbol.iterator]=u.prototype.entries);var y=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function p(e,t){var r,n,o=(t=t||{}).body;if(e instanceof p){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new u(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,o||null==e._bodyInit||(o=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",!t.headers&&this.headers||(this.headers=new u(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),y.indexOf(n)>-1?n:r),this.mode=t.mode||this.mode||null,this.signal=t.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(e){var t=new FormData;return e.trim().split("&").forEach((function(e){if(e){var r=e.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");t.append(decodeURIComponent(n),decodeURIComponent(o))}})),t}function m(e,t){t||(t={}),this.type="default",this.status=void 0===t.status?200:t.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in t?t.statusText:"OK",this.headers=new u(t.headers),this.url=t.url||"",this._initBody(e)}p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},d.call(p.prototype),d.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 e=new m(null,{status:0,statusText:""});return e.type="error",e};var v=[301,302,303,307,308];m.redirect=function(e,t){if(-1===v.indexOf(t))throw new RangeError("Invalid status code");return new m(null,{status:t,headers:{location:e}})},t.DOMException=e.DOMException;try{new t.DOMException}catch(e){t.DOMException=function(e,t){this.message=e,this.name=t;var r=Error(e);this.stack=r.stack},t.DOMException.prototype=Object.create(Error.prototype),t.DOMException.prototype.constructor=t.DOMException}function w(e,n){return new Promise((function(o,i){var s=new p(e,n);if(s.signal&&s.signal.aborted)return i(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function c(){a.abort()}a.onload=function(){var e,t,r={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new u,e.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(e){var r=e.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();t.append(n,o)}})),t)};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 t.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(e,t){a.setRequestHeader(t,e)})),s.signal&&(s.signal.addEventListener("abort",c),a.onreadystatechange=function(){4===a.readyState&&s.signal.removeEventListener("abort",c)}),a.send(void 0===s._bodyInit?null:s._bodyInit)}))}w.polyfill=!0,e.fetch||(e.fetch=w,e.Headers=u,e.Request=p,e.Response=m),t.Headers=u,t.Request=p,t.Response=m,t.fetch=w}({})}(n),delete n.fetch.polyfill,(t=n.fetch).default=n.fetch,t.fetch=n.fetch,t.Headers=n.Headers,t.Request=n.Request,t.Response=n.Response,e.exports=t}));n.fetch,n.Headers,n.Request,n.Response;function o(e,t){if(null==e&&!t)throw new Error("appbase-analytics: query or queryID must be present to register a click/conversion event")}return{init:function(r){void 0===r&&(r={});var i={credentials:r.credentials,index:r.index,url:r.url,userID:r.userID,globalEventData:r.globalEventData,queryID:"",headers:null};return function(e){if(!e)throw new Error("appbase-analytics: A valid index must be present to record analytics events.")}(i.index),function(e){if(!e)throw new Error("appbase-analytics: Auth credentials is missing.")}(i.credentials),function(e){if(!e)throw new Error("appbase-analytics: URL is missing.")}(i.url),i._request=function(r,o,s){var a=e({},o,{user_id:i.userID,event_data:e({},o&&o.event_data,{},i.globalEventData)});return n(i.url+"/"+i.index+"/_analytics/"+r,{method:"PUT",headers:e({},i.headers,{"Content-Type":"application/json",Authorization:"Basic "+t(i.credentials)}),body:JSON.stringify(a)}).then((function(e){s&&s(null,e)})).catch((function(e){console.error(e),s&&s(e,null)}))},i.search=function(e,t){o(e.query,e.queryID);if(i._request){var r={query:e.query,query_id:e.queryID,event_data:e.eventData,filters:e.filters,total_hits:e.totalHits,impressions:e.impressions};i._request("search",r,(function(e,r){r&&r.json().then((function(e){e&&e.query_id&&(i.queryID=e.query_id)})).catch((function(e){console.error(e)})),t&&t(e,r)}))}},i.click=function(e,t){if(o(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),i._request){var r={click_on:e.objects,click_type:e.isSuggestionClick?"suggestion":"result",query:e.query,query_id:e.queryID,event_data:e.eventData};i._request("click",r,t)}},i.conversion=function(e,t){if(o(e.query,e.queryID),function(e){if(!e||Object.keys(e).length<1)throw new Error("appbase-analytics: at least one click object must be present to register a click event")}(e.objects),i._request){var r={conversion_on:e.objects,query:e.query,query_id:e.queryID,event_data:e.eventData};i._request("conversion",r,t)}},i.setUserID=function(e){i.userID=e},i.setGlobalEventData=function(e){i.globalEventData=e},i.setHeaders=function(e){i.headers=e},i}}})); | ||
//# sourceMappingURL=analytics.umd.min.js.map |
{ | ||
"name": "@appbaseio/analytics", | ||
"version": "2.1.0-beta", | ||
"version": "2.1.1-beta", | ||
"description": "Universal analytics library for appbase.io apps", | ||
@@ -5,0 +5,0 @@ "main": "dist/@appbaseio/analytics.cjs.js", |
108
README.md
@@ -242,3 +242,3 @@ [![NPM Version](https://img.shields.io/npm/v/@appbaseio/analytics.svg?style=flat)](https://www.npmjs.com/package/@appbaseio/analytics) | ||
It sets the unique identification for each user to distinguish analytics events for users. | ||
It allows you to set the `userID`. | ||
@@ -262,3 +262,3 @@ ```ts | ||
Sets the custom events which will be attached for each event. | ||
To set the custom events which will be attached for each event recorded by the instance. | ||
@@ -303,13 +303,32 @@ For example: | ||
| Option | Type | Default | Description | | ||
| ----------------- | -------- | --------------- | ------------------------------------------ | | ||
| **`index`** | `string` | None (required) | Elasticsearch index name. | | ||
| **`credentials`** | `string` | None (required) | API key for appbase.io hosted application. | | ||
| **`url`** | `string` | None (required) | Appbaseio cluster url. | | ||
| `userID` | `string` | null | Sets the userID to be recorded. | | ||
| `globalEventData` | `object` | null | To set the custom events | | ||
| `headers` | `object` | null | To set the custom headers | | ||
| Option | Type | Description | | ||
| ----------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ||
| **`index`** | `string` (required) | Elasticsearch index name. | | ||
| **`credentials`** | `string` (required) | credentials as they appear on the Appbaseio dashboard. It should be a string of the format <b>username:password</b> and is used for authenticating the app. | | ||
| **`url`** | `string` (required) | Appbaseio cluster URL. | | ||
| `userID` | `string` | UserID allows you to record events for a particular user. For example, you may want to know that how many different users are using the search. | | ||
| `globalEventData` | `Object` | It allows you to set the <b>global</b> custom events which can be used to build your own analytics on top of the appbase.io analytics. [Read More](https://docs.appbase.io/docs/analytics/Implement/#how-to-implement-custom-events) | | ||
| `headers` | `Object` | Sometimes it may require to set extra headers to the analytics API. For example, you're using proxy middleware which adds an additional security layer. | | ||
### Methods | ||
An example with all possible options: | ||
```ts | ||
const aa = require('@appbaseio/analytics'); | ||
const aaInstance = aa.init({ | ||
index: 'books', | ||
credentials: 'foo:bar', | ||
url: 'http://localhost:8000', | ||
userID: 'jon@abc.com', | ||
globalEventData: { | ||
platform: 'mac' | ||
}, | ||
headers: { | ||
'X-auth-token': 'XYZ' | ||
} | ||
}); | ||
``` | ||
### Instance Methods | ||
#### Record Search | ||
@@ -319,3 +338,3 @@ | ||
search(searchConfig: Object, callback: CallBack) => void | ||
search(searchConfig: Object, callback: Function) | ||
@@ -326,10 +345,15 @@ ``` | ||
| Option | Type | Default | Description | | ||
| ------------- | -------- | ------- | -------------------------------------------------------------------------------------- | | ||
| **`query`** | `string` | None | Search query, set to empty string to register as an empty query search. | | ||
| **`queryID`** | `string` | None | Search query ID returned from Appbase. | | ||
| `eventData` | `object` | null | To set the search filters, for e.g `{ "year": 2018 }` | | ||
| `filters` | `object` | null | To set the custom events, for e.g `{ "platform": mac }` | | ||
| `hits` | `array` | null | To set the search hits, a hit object can have the `id`, `type` & `source` properties . | | ||
| Option | Type | Description | | ||
| --------------- | -------- | ------------------------------------------------------------------------------------------------ | | ||
| **`query`** | `string` | Search query, set to empty string to register as an empty query search. | | ||
| **`queryID`** | `string` | Search query ID returned from Appbase. | | ||
| **`totalHits`** | `number` | Represents the total number of hits returned by a particular query. | | ||
| `eventData` | `Object` | To set the custom events, for e.g `{ "platform": mac }` | | ||
| `filters` | `Object` | It allows to record the applied facets on the search query, for e.g `{ "year": 2018 }` | | ||
| `impressions` | `Array` | To set the results impressions, an impression object must have the `id` and `index` properties . | | ||
<b>Note: </b> | ||
`query` or `queryID` must be present. | ||
An example with all possible options: | ||
@@ -343,2 +367,3 @@ | ||
queryID: 'cf827a07-60a6-43ef-ab93-e1f8e1e3e1a8', | ||
totalHits: 200, | ||
eventData: { | ||
@@ -350,9 +375,6 @@ source: 'promoted_results' | ||
}, | ||
hits: [ | ||
impressions: [ | ||
{ | ||
id: '12345678', | ||
source: { | ||
title: 'iphoneX' | ||
}, | ||
type: '_doc' | ||
index: 'products' | ||
} | ||
@@ -384,3 +406,3 @@ ] | ||
```ts | ||
click(clickConfig: Object, callback: CallBack) => void | ||
click(clickConfig: Object, callback: Function) | ||
``` | ||
@@ -390,13 +412,13 @@ | ||
| Option | Type | Default | Description | | ||
| ------------------- | ------------------------- | --------------- | --------------------------------------------------------------------------------------------- | | ||
| **`query`** | `string` | None | Search query, set to empty string to register as an empty query search. | | ||
| **`queryID`** | `string` | None | Search query ID returned from Appbase. | | ||
| **`objects`** | `{[key: string]: number}` | None (required) | To set the click object ids followed by click positions, for example `{ "iphoneX_1234": 2 }`. | | ||
| `isSuggestionClick` | `boolean` | `false` | Set as `true` to register as a suggestion click. | | ||
| `eventData` | `object` | null | To set the custom events, for e.g `{ "platform": mac }` | | ||
| Option | Type | Description | | ||
| ------------------- | ------------------------------------ | --------------------------------------------------------------------------------------------- | | ||
| **`query`** | `string` | Search query, set to empty string to register as an empty query search. | | ||
| **`queryID`** | `string` | Search query ID returned from Appbase. | | ||
| **`objects`** | `{[key: string]: number}` (required) | To set the click object ids followed by click positions, for example `{ "iphoneX_1234": 2 }`. | | ||
| `isSuggestionClick` | `boolean` | Set as `true` to register as a suggestion click. | | ||
| `eventData` | `Object` | To set the custom events, for e.g `{ "platform": mac }` | | ||
<b>Note: </b> | ||
`query` or `query_id` must be present. | ||
`query` or `queryID` must be present. | ||
@@ -434,3 +456,3 @@ An example with all possible options: | ||
```ts | ||
conversion(conversionConfig: Object, callback: CallBack) => void | ||
conversion(conversionConfig: Object, callback: Function) | ||
``` | ||
@@ -440,12 +462,12 @@ | ||
| Option | Type | Default | Description | | ||
| ------------- | --------------- | --------------- | ----------------------------------------------------------------------- | | ||
| **`query`** | `string` | None | Search query, set to empty string to register as an empty query search. | | ||
| **`queryID`** | `string` | None | Search query ID returned from Appbase. | | ||
| **`objects`** | `Array<string>` | None (required) | To set the converted object ids, for example: `["iphoneX_1234"]`. | | ||
| `eventData` | `object` | null | To set the custom events, for e.g `{ "platform": mac }` | | ||
| Option | Type | Description | | ||
| ------------- | -------------------------- | ----------------------------------------------------------------------- | | ||
| **`query`** | `string` | Search query, set to empty string to register as an empty query search. | | ||
| **`queryID`** | `string` | Search query ID returned from Appbase. | | ||
| **`objects`** | `Array<string>` (required) | To set the converted object ids, for example: `["iphoneX_1234"]`. | | ||
| `eventData` | `Object` | To set the custom events, for e.g `{ "platform": mac }` | | ||
<b>Note: </b> | ||
`query` or `query_id` must be present. | ||
`query` or `queryID` must be present. | ||
@@ -486,3 +508,3 @@ An example with all possible options: | ||
Sets the user ID which will be used to retrieve the search headers. | ||
Sets the user ID. User ID helps to record an event for that particular user. | ||
@@ -495,3 +517,3 @@ ```ts | ||
Sets the global events which will be added to all analytics requests. | ||
Sets the global event data. This will be added to all the analytics requests made by the instance. | ||
@@ -498,0 +520,0 @@ ```ts |
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
162111
1049
548