@appbaseio/analytics
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -184,3 +184,4 @@ 'use strict'; | ||
query_id: clickConfig.queryID, | ||
custom_events: clickConfig.customEvents | ||
custom_events: clickConfig.customEvents, | ||
meta: clickConfig.meta | ||
}; | ||
@@ -200,3 +201,4 @@ | ||
conversion_on: conversionConfig.objects, | ||
query_id: conversionConfig.queryID | ||
query_id: conversionConfig.queryID, | ||
meta: conversionConfig.meta | ||
}; | ||
@@ -203,0 +205,0 @@ |
@@ -180,3 +180,4 @@ import fetch from 'cross-fetch'; | ||
query_id: clickConfig.queryID, | ||
custom_events: clickConfig.customEvents | ||
custom_events: clickConfig.customEvents, | ||
meta: clickConfig.meta | ||
}; | ||
@@ -196,3 +197,4 @@ | ||
conversion_on: conversionConfig.objects, | ||
query_id: conversionConfig.queryID | ||
query_id: conversionConfig.queryID, | ||
meta: conversionConfig.meta | ||
}; | ||
@@ -199,0 +201,0 @@ |
@@ -757,3 +757,4 @@ (function (global, factory) { | ||
query_id: clickConfig.queryID, | ||
custom_events: clickConfig.customEvents | ||
custom_events: clickConfig.customEvents, | ||
meta: clickConfig.meta | ||
}; | ||
@@ -773,3 +774,4 @@ | ||
conversion_on: conversionConfig.objects, | ||
query_id: conversionConfig.queryID | ||
query_id: conversionConfig.queryID, | ||
meta: conversionConfig.meta | ||
}; | ||
@@ -776,0 +778,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,s=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|s)||(i="=",s%1);n+=i.charAt(63&o>>8-s%1*8)){if((t=r.charCodeAt(s+=3/4))>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,o=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){var n="undefined"!=typeof self?self:r,o=function(){function e(){this.fetch=!1,this.DOMException=n.DOMException}return e.prototype=n,new e}();!function(e){!function(t){var r="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,i="ArrayBuffer"in e;if(i)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&a.indexOf(Object.prototype.toString.call(e))>-1};function c(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 f(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?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 d(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function p(e){var t=new FileReader,r=y(t);return t.readAsArrayBuffer(e),r}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():i&&o&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=b(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&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var e=d(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?d(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(p)}),this.text=function(){var e,t,r,n=d(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=y(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)},s&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=c(e),t=f(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},h.prototype.delete=function(e){delete this.map[c(e)]},h.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},h.prototype.set=function(e,t){this.map[c(e)]=f(t)},h.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(h.prototype[Symbol.iterator]=h.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function _(e,t){var r,n,o=(t=t||{}).body;if(e instanceof _){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(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 h(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),m.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 w(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 E(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 h(t.headers),this.url=t.url||"",this._initBody(e)}_.prototype.clone=function(){return new _(this,{body:this._bodyInit})},v.call(_.prototype),v.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var e=new E(null,{status:0,statusText:""});return e.type="error",e};var g=[301,302,303,307,308];E.redirect=function(e,t){if(-1===g.indexOf(t))throw new RangeError("Invalid status code");return new E(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 q(e,r){return new Promise((function(n,s){var i=new _(e,r);if(i.signal&&i.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var e,t,r={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new h,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 o="response"in a?a.response:a.responseText;n(new E(o,r))},a.onerror=function(){s(new TypeError("Network request failed"))},a.ontimeout=function(){s(new TypeError("Network request failed"))},a.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},a.open(i.method,i.url,!0),"include"===i.credentials?a.withCredentials=!0:"omit"===i.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),i.headers.forEach((function(e,t){a.setRequestHeader(t,e)})),i.signal&&(i.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&i.signal.removeEventListener("abort",u)}),a.send(void 0===i._bodyInit?null:i._bodyInit)}))}q.polyfill=!0,e.fetch||(e.fetch=q,e.Headers=h,e.Request=_,e.Response=E),t.Headers=h,t.Request=_,t.Response=E,t.fetch=q,Object.defineProperty(t,"__esModule",{value:!0})}({})}(o),o.fetch.ponyfill=!0,delete o.fetch.polyfill;var s=o;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t})),s=(n=o)&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;o.fetch,o.Headers,o.Request,o.Response;function i(e,t){if(null==e&&!t)throw new Error("appbase-analytics: query or queryID must be present to register a click/conversion event")}function a(e){if(!e)throw new Error("appbase-analytics: queryID must be present to save search/favorite")}return{init:function(r){void 0===r&&(r={});var n={credentials:r.credentials,index:r.index,url:r.url,userID:r.userID,globalCustomEvents:r.globalCustomEvents,queryID:"",headers:null,_request:function(r,o,i,a,u){var c=e({user_id:n.userID},i,{custom_events:e({},i&&i.custom_events,{},n.globalCustomEvents)}),f="";return a&&(f=Object.keys(a).map((function(e){return e+"="+a[e]})).join("&")),s(n.url+"/"+o+"?"+f,{method:r,headers:e({},n.headers,{"Content-Type":"application/json",Authorization:"Basic "+t(n.credentials)}),body:"GET"===r?null:JSON.stringify(c)}).then((function(e){u&&u(null,e)})).catch((function(e){u&&u(e,null)}))}};return function(e){if(!e)throw new Error("appbase-analytics: A valid index must be present to record analytics events.")}(n.index),function(e){if(!e)throw new Error("appbase-analytics: Auth credentials is missing.")}(n.credentials),function(e){if(!e)throw new Error("appbase-analytics: URL is missing.")}(n.url),n.search=function(e,t){i(e.query,e.queryID);if(n._request){var r={query:e.query,query_id:e.queryID,custom_events:e.customEvents,filters:e.filters,hits:e.hits};n._request("PUT",n.index+"/_analytics/search",r,null,(function(e,r){r?r.json().then((function(o){o&&o.query_id&&(n.queryID=o.query_id),t&&t(e,r)})).catch((function(e){t&&t(e,r)})):t&&t(e,r)}))}},n.click=function(e,t){if(i(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),n._request){var r={click_on:e.objects,click_type:e.isSuggestionClick?"suggestion":"result",query:e.query,query_id:e.queryID,custom_events:e.customEvents};n._request("PUT",n.index+"/_analytics/click",r,null,t)}},n.conversion=function(e,t){if(i(null,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),n._request){var r={conversion_on:e.objects,query_id:e.queryID};n._request("PUT",n.index+"/_analytics/conversion",r,null,t)}},n.saveSearch=function(e,t){a(e.queryID);var r={query_id:e.queryID,save_search_id:e.saveSearchID,save_search_meta:e.saveSearchMeta,user_id:e.userID,custom_events:e.customEvents};n._request("PUT","_analytics/save-search",r,null,t)},n.getSavedSearches=function(e,t){n._request&&n._request("GET","_analytics/saved-searches",null,e,t)},n.favorite=function(e,t){if(a(e.queryID),!e.favoriteOn||""===e.favoriteOn)throw new Error("appbase-analytics: favoriteOn property is required");if(!e.source)throw new Error("appbase-analytics: source property is required");var r={query_id:e.queryID,favorite_on:e.favoriteOn,source:e.source,id:e.id,meta:e.meta,user_id:e.userID,custom_events:e.customEvents};n._request("PUT","_analytics/favorite",r,null,t)},n.getFavorites=function(e,t){n._request&&n._request("GET","_analytics/favorites",null,e,t)},n.setUserID=function(e){n.userID=e},n.setGlobalCustomEvents=function(e){n.globalCustomEvents=e},n.setHeaders=function(e){n.headers=e},n.getQueryID=function(){return n.queryID},n}}})); | ||
!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,s=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";r.charAt(0|s)||(i="=",s%1);n+=i.charAt(63&o>>8-s%1*8)){if((t=r.charCodeAt(s+=3/4))>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,o=function(e,t){return e(t={exports:{}},t.exports),t.exports}((function(e,t){var n="undefined"!=typeof self?self:r,o=function(){function e(){this.fetch=!1,this.DOMException=n.DOMException}return e.prototype=n,new e}();!function(e){!function(t){var r="URLSearchParams"in e,n="Symbol"in e&&"iterator"in Symbol,o="FileReader"in e&&"Blob"in e&&function(){try{return new Blob,!0}catch(e){return!1}}(),s="FormData"in e,i="ArrayBuffer"in e;if(i)var a=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],u=ArrayBuffer.isView||function(e){return e&&a.indexOf(Object.prototype.toString.call(e))>-1};function c(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 f(e){return"string"!=typeof e&&(e=String(e)),e}function l(e){var t={next:function(){var t=e.shift();return{done:void 0===t,value:t}}};return n&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?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 d(e){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}function y(e){return new Promise((function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}}))}function p(e){var t=new FileReader,r=y(t);return t.readAsArrayBuffer(e),r}function b(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(e){var t;this._bodyInit=e,e?"string"==typeof e?this._bodyText=e:o&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:s&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:r&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():i&&o&&((t=e)&&DataView.prototype.isPrototypeOf(t))?(this._bodyArrayBuffer=b(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):i&&(ArrayBuffer.prototype.isPrototypeOf(e)||u(e))?this._bodyArrayBuffer=b(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&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},o&&(this.blob=function(){var e=d(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?d(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(p)}),this.text=function(){var e,t,r,n=d(this);if(n)return n;if(this._bodyBlob)return e=this._bodyBlob,t=new FileReader,r=y(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)},s&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(e,t){e=c(e),t=f(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},h.prototype.delete=function(e){delete this.map[c(e)]},h.prototype.get=function(e){return e=c(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(c(e))},h.prototype.set=function(e,t){this.map[c(e)]=f(t)},h.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},h.prototype.keys=function(){var e=[];return this.forEach((function(t,r){e.push(r)})),l(e)},h.prototype.values=function(){var e=[];return this.forEach((function(t){e.push(t)})),l(e)},h.prototype.entries=function(){var e=[];return this.forEach((function(t,r){e.push([r,t])})),l(e)},n&&(h.prototype[Symbol.iterator]=h.prototype.entries);var m=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function _(e,t){var r,n,o=(t=t||{}).body;if(e instanceof _){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(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 h(t.headers)),this.method=(r=t.method||this.method||"GET",n=r.toUpperCase(),m.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 w(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 E(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 h(t.headers),this.url=t.url||"",this._initBody(e)}_.prototype.clone=function(){return new _(this,{body:this._bodyInit})},v.call(_.prototype),v.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var e=new E(null,{status:0,statusText:""});return e.type="error",e};var g=[301,302,303,307,308];E.redirect=function(e,t){if(-1===g.indexOf(t))throw new RangeError("Invalid status code");return new E(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 q(e,r){return new Promise((function(n,s){var i=new _(e,r);if(i.signal&&i.signal.aborted)return s(new t.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var e,t,r={status:a.status,statusText:a.statusText,headers:(e=a.getAllResponseHeaders()||"",t=new h,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 o="response"in a?a.response:a.responseText;n(new E(o,r))},a.onerror=function(){s(new TypeError("Network request failed"))},a.ontimeout=function(){s(new TypeError("Network request failed"))},a.onabort=function(){s(new t.DOMException("Aborted","AbortError"))},a.open(i.method,i.url,!0),"include"===i.credentials?a.withCredentials=!0:"omit"===i.credentials&&(a.withCredentials=!1),"responseType"in a&&o&&(a.responseType="blob"),i.headers.forEach((function(e,t){a.setRequestHeader(t,e)})),i.signal&&(i.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&i.signal.removeEventListener("abort",u)}),a.send(void 0===i._bodyInit?null:i._bodyInit)}))}q.polyfill=!0,e.fetch||(e.fetch=q,e.Headers=h,e.Request=_,e.Response=E),t.Headers=h,t.Request=_,t.Response=E,t.fetch=q,Object.defineProperty(t,"__esModule",{value:!0})}({})}(o),o.fetch.ponyfill=!0,delete o.fetch.polyfill;var s=o;(t=s.fetch).default=s.fetch,t.fetch=s.fetch,t.Headers=s.Headers,t.Request=s.Request,t.Response=s.Response,e.exports=t})),s=(n=o)&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n;o.fetch,o.Headers,o.Request,o.Response;function i(e,t){if(null==e&&!t)throw new Error("appbase-analytics: query or queryID must be present to register a click/conversion event")}function a(e){if(!e)throw new Error("appbase-analytics: queryID must be present to save search/favorite")}return{init:function(r){void 0===r&&(r={});var n={credentials:r.credentials,index:r.index,url:r.url,userID:r.userID,globalCustomEvents:r.globalCustomEvents,queryID:"",headers:null,_request:function(r,o,i,a,u){var c=e({user_id:n.userID},i,{custom_events:e({},i&&i.custom_events,{},n.globalCustomEvents)}),f="";return a&&(f=Object.keys(a).map((function(e){return e+"="+a[e]})).join("&")),s(n.url+"/"+o+"?"+f,{method:r,headers:e({},n.headers,{"Content-Type":"application/json",Authorization:"Basic "+t(n.credentials)}),body:"GET"===r?null:JSON.stringify(c)}).then((function(e){u&&u(null,e)})).catch((function(e){u&&u(e,null)}))}};return function(e){if(!e)throw new Error("appbase-analytics: A valid index must be present to record analytics events.")}(n.index),function(e){if(!e)throw new Error("appbase-analytics: Auth credentials is missing.")}(n.credentials),function(e){if(!e)throw new Error("appbase-analytics: URL is missing.")}(n.url),n.search=function(e,t){i(e.query,e.queryID);if(n._request){var r={query:e.query,query_id:e.queryID,custom_events:e.customEvents,filters:e.filters,hits:e.hits};n._request("PUT",n.index+"/_analytics/search",r,null,(function(e,r){r?r.json().then((function(o){o&&o.query_id&&(n.queryID=o.query_id),t&&t(e,r)})).catch((function(e){t&&t(e,r)})):t&&t(e,r)}))}},n.click=function(e,t){if(i(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),n._request){var r={click_on:e.objects,click_type:e.isSuggestionClick?"suggestion":"result",query:e.query,query_id:e.queryID,custom_events:e.customEvents,meta:e.meta};n._request("PUT",n.index+"/_analytics/click",r,null,t)}},n.conversion=function(e,t){if(i(null,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),n._request){var r={conversion_on:e.objects,query_id:e.queryID,meta:e.meta};n._request("PUT",n.index+"/_analytics/conversion",r,null,t)}},n.saveSearch=function(e,t){a(e.queryID);var r={query_id:e.queryID,save_search_id:e.saveSearchID,save_search_meta:e.saveSearchMeta,user_id:e.userID,custom_events:e.customEvents};n._request("PUT","_analytics/save-search",r,null,t)},n.getSavedSearches=function(e,t){n._request&&n._request("GET","_analytics/saved-searches",null,e,t)},n.favorite=function(e,t){if(a(e.queryID),!e.favoriteOn||""===e.favoriteOn)throw new Error("appbase-analytics: favoriteOn property is required");if(!e.source)throw new Error("appbase-analytics: source property is required");var r={query_id:e.queryID,favorite_on:e.favoriteOn,source:e.source,id:e.id,meta:e.meta,user_id:e.userID,custom_events:e.customEvents};n._request("PUT","_analytics/favorite",r,null,t)},n.getFavorites=function(e,t){n._request&&n._request("GET","_analytics/favorites",null,e,t)},n.setUserID=function(e){n.userID=e},n.setGlobalCustomEvents=function(e){n.globalCustomEvents=e},n.setHeaders=function(e){n.headers=e},n.getQueryID=function(){return n.queryID},n}}})); | ||
//# sourceMappingURL=analytics.umd.min.js.map |
{ | ||
"name": "@appbaseio/analytics", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Universal analytics library for appbase.io apps", | ||
@@ -5,0 +5,0 @@ "main": "dist/@appbaseio/analytics.cjs.js", |
@@ -136,2 +136,5 @@ [![NPM Version](https://img.shields.io/npm/v/@appbaseio/analytics.svg?style=flat)](https://www.npmjs.com/package/@appbaseio/analytics) | ||
iphone7_19348: 3 | ||
}, | ||
meta: { | ||
key1: 'value1' | ||
} | ||
@@ -206,3 +209,6 @@ }); | ||
queryID: aaInstance.getQueryID(), | ||
objects: ['iphoneX_19348', 'iphone7_19348'] | ||
objects: ['iphoneX_19348', 'iphone7_19348'], | ||
meta: { | ||
key1: value1 | ||
} | ||
}); | ||
@@ -485,2 +491,3 @@ ``` | ||
| `customEvents` | `Object` | To set the custom events, for e.g `{ "platform": mac }` | | ||
| **`meta`** | `Object` | Meta data | | ||
@@ -505,3 +512,6 @@ <b>Note: </b> | ||
}, | ||
isSuggestionClick: true | ||
isSuggestionClick: true, | ||
meta: { | ||
key1: value1 | ||
} | ||
}, | ||
@@ -532,2 +542,3 @@ (err, res) => { | ||
| **`objects`** | `Array<string>` (required) | To set the converted object ids, for example: `["iphoneX_1234"]`. | | ||
| **`meta`** | `Object` | Meta data | | ||
@@ -544,3 +555,6 @@ <b>Note: </b> | ||
queryID: 'cf827a07-60a6-43ef-ab93-e1f8e1e3e1a8', | ||
objects: ['iphone_1234'] | ||
objects: ['iphone_1234'], | ||
meta: { | ||
key1: value1 | ||
} | ||
}, | ||
@@ -547,0 +561,0 @@ (err, res) => { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
189948
1241
797
6