@appbaseio/analytics
Advanced tools
Comparing version 2.1.1-beta to 2.1.2-beta
@@ -135,8 +135,14 @@ 'use strict'; | ||
} | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
})["catch"](function (error) { | ||
console.error(error); | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
}); | ||
} | ||
if (callback) { | ||
} else if (callback) { | ||
callback(err, res); | ||
@@ -153,4 +159,3 @@ } | ||
filters: searchConfig.filters, | ||
total_hits: searchConfig.totalHits, | ||
impressions: searchConfig.impressions | ||
hits: searchConfig.hits | ||
}; | ||
@@ -182,3 +187,3 @@ | ||
metrics.conversion = function (conversionConfig, callback) { | ||
validateQuery(conversionConfig.query, conversionConfig.queryID); | ||
validateQuery(null, conversionConfig.queryID); | ||
validateConversionObjects(conversionConfig.objects); // just to avoid the flow type error | ||
@@ -189,5 +194,3 @@ | ||
conversion_on: conversionConfig.objects, | ||
query: conversionConfig.query, | ||
query_id: conversionConfig.queryID, | ||
event_data: conversionConfig.eventData | ||
query_id: conversionConfig.queryID | ||
}; | ||
@@ -212,2 +215,7 @@ | ||
metrics.headers = headers; | ||
}; // get queryID | ||
metrics.getQueryID = function () { | ||
return metrics.queryID; | ||
}; | ||
@@ -214,0 +222,0 @@ |
@@ -131,8 +131,14 @@ import fetch from 'cross-fetch'; | ||
} | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
})["catch"](function (error) { | ||
console.error(error); | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
}); | ||
} | ||
if (callback) { | ||
} else if (callback) { | ||
callback(err, res); | ||
@@ -149,4 +155,3 @@ } | ||
filters: searchConfig.filters, | ||
total_hits: searchConfig.totalHits, | ||
impressions: searchConfig.impressions | ||
hits: searchConfig.hits | ||
}; | ||
@@ -178,3 +183,3 @@ | ||
metrics.conversion = function (conversionConfig, callback) { | ||
validateQuery(conversionConfig.query, conversionConfig.queryID); | ||
validateQuery(null, conversionConfig.queryID); | ||
validateConversionObjects(conversionConfig.objects); // just to avoid the flow type error | ||
@@ -185,5 +190,3 @@ | ||
conversion_on: conversionConfig.objects, | ||
query: conversionConfig.query, | ||
query_id: conversionConfig.queryID, | ||
event_data: conversionConfig.eventData | ||
query_id: conversionConfig.queryID | ||
}; | ||
@@ -208,2 +211,7 @@ | ||
metrics.headers = headers; | ||
}; // get queryID | ||
metrics.getQueryID = function () { | ||
return metrics.queryID; | ||
}; | ||
@@ -210,0 +218,0 @@ |
@@ -693,8 +693,14 @@ (function (global, factory) { | ||
} | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
})["catch"](function (error) { | ||
console.error(error); | ||
if (callback) { | ||
callback(err, res); | ||
} | ||
}); | ||
} | ||
if (callback) { | ||
} else if (callback) { | ||
callback(err, res); | ||
@@ -711,4 +717,3 @@ } | ||
filters: searchConfig.filters, | ||
total_hits: searchConfig.totalHits, | ||
impressions: searchConfig.impressions | ||
hits: searchConfig.hits | ||
}; | ||
@@ -740,3 +745,3 @@ | ||
metrics.conversion = function (conversionConfig, callback) { | ||
validateQuery(conversionConfig.query, conversionConfig.queryID); | ||
validateQuery(null, conversionConfig.queryID); | ||
validateConversionObjects(conversionConfig.objects); // just to avoid the flow type error | ||
@@ -747,5 +752,3 @@ | ||
conversion_on: conversionConfig.objects, | ||
query: conversionConfig.query, | ||
query_id: conversionConfig.queryID, | ||
event_data: conversionConfig.eventData | ||
query_id: conversionConfig.queryID | ||
}; | ||
@@ -770,2 +773,7 @@ | ||
metrics.headers = headers; | ||
}; // get queryID | ||
metrics.getQueryID = function () { | ||
return metrics.queryID; | ||
}; | ||
@@ -772,0 +780,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,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}}})); | ||
!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(n){n&&n.query_id&&(i.queryID=n.query_id),t&&t(e,r)})).catch((function(n){console.error(n),t&&t(e,r)})):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(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),i._request){var r={conversion_on:e.objects,query_id:e.queryID};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.getQueryID=function(){return i.queryID},i}}})); | ||
//# sourceMappingURL=analytics.umd.min.js.map |
{ | ||
"name": "@appbaseio/analytics", | ||
"version": "2.1.1-beta", | ||
"version": "2.1.2-beta", | ||
"description": "Universal analytics library for appbase.io apps", | ||
@@ -44,3 +44,6 @@ "main": "dist/@appbaseio/analytics.cjs.js", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-eslint": "^10.0.3", | ||
"babel-jest": "^23.4.2", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0", | ||
"eslint": "^6.2.1", | ||
"eslint-config-airbnb-base": "^14.0.0", | ||
@@ -56,7 +59,5 @@ "eslint-config-prettier": "^6.1.0", | ||
"lint-staged": "^9.2.4", | ||
"prettier": "^1.18.2", | ||
"eslint": "^6.2.1", | ||
"babel-eslint": "^10.0.3", | ||
"nps": "^5.9.8", | ||
"nps-utils": "^1.7.0", | ||
"prettier": "^1.18.2", | ||
"rollup": "^1.20.3", | ||
@@ -68,4 +69,3 @@ "rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.1.1", | ||
"babel-plugin-transform-flow-strip-types": "^6.22.0" | ||
"rollup-plugin-terser": "^5.1.1" | ||
}, | ||
@@ -72,0 +72,0 @@ "keywords": [ |
@@ -20,4 +20,2 @@ [![NPM Version](https://img.shields.io/npm/v/@appbaseio/analytics.svg?style=flat)](https://www.npmjs.com/package/@appbaseio/analytics) | ||
- [Record conversions](#record-conversions) | ||
- [Record conversions for a particular search event](#record-conversions-for-a-particular-search-event) | ||
- [Record conversions with particular events](#record-conversions-with-particular-events) | ||
- [Set user](#set-user) | ||
@@ -193,24 +191,5 @@ - [Set global events](#set-global-events) | ||
To record a search conversion. | ||
Conversions must be recorded for a particular search event so it is required to define a `queryID` to record conversion. | ||
```ts | ||
const aa = require('@appbaseio/analytics'); | ||
const aaInstance = aa.init({ | ||
index: 'INDEX_NAME', | ||
credentials: 'AUTH_CREDENTIALS', | ||
url: 'CLUSTER_URL' | ||
}); | ||
aaInstance.conversion({ | ||
query: 'iphone', | ||
objects: ['iphoneX_19348', 'iphone7_19348'] | ||
}); | ||
``` | ||
#### Record conversions for a particular search event | ||
Use `queryID` instead of `query` to record conversions for a particular search event. | ||
```ts | ||
// Record a search | ||
@@ -228,16 +207,2 @@ aaInstance.search({ | ||
#### Record conversions with particular events | ||
Attach the custom events to distinguish the conversion events. | ||
```ts | ||
aaInstance.conversion({ | ||
query: 'iphone', | ||
objects: ['iphoneX_19348', 'iphone7_19348'], | ||
eventData: { | ||
conversion_source: 'promoted_collections' | ||
} | ||
}); | ||
``` | ||
### Set user | ||
@@ -344,10 +309,9 @@ | ||
| 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 . | | ||
| 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. | | ||
| `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 }` | | ||
| `hits` | `Array` | To set the search hits, a hit object can have the `id`, `type` & `source` properties . | | ||
@@ -366,3 +330,2 @@ <b>Note: </b> | ||
queryID: 'cf827a07-60a6-43ef-ab93-e1f8e1e3e1a8', | ||
totalHits: 200, | ||
eventData: { | ||
@@ -374,6 +337,9 @@ source: 'promoted_results' | ||
}, | ||
impressions: [ | ||
hits: [ | ||
{ | ||
id: '12345678', | ||
index: 'products' | ||
source: { | ||
title: 'iphoneX' | ||
}, | ||
type: '_doc' | ||
} | ||
@@ -458,12 +424,10 @@ ] | ||
| 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 }` | | ||
| Option | Type | Description | | ||
| ------------- | -------------------------- | ----------------------------------------------------------------- | | ||
| **`queryID`** | `string` (required) | Search query ID returned from Appbase. | | ||
| **`objects`** | `Array<string>` (required) | To set the converted object ids, for example: `["iphoneX_1234"]`. | | ||
<b>Note: </b> | ||
`query` or `queryID` must be present. | ||
`queryID` must be present. | ||
@@ -475,10 +439,4 @@ An example with all possible options: | ||
{ | ||
query: 'iphone', | ||
// or | ||
queryID: 'cf827a07-60a6-43ef-ab93-e1f8e1e3e1a8', | ||
eventData: { | ||
source: 'promoted_results' | ||
}, | ||
objects: ['iphone_1234'], | ||
isSuggestionClick: true | ||
objects: ['iphone_1234'] | ||
}, | ||
@@ -485,0 +443,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
1064
160677
506
6