2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).AlgoliaAnalytics={})}(this,function(e){"use strict";function t(){"function"!=typeof Object.assign&&(Object.assign=function(e,t){var r=arguments;if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(e),o=1;o<arguments.length;o++){var i=r[o];if(null!=i)for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(n[s]=i[s])}return n})}var r=function(){try{return Boolean(navigator.cookieEnabled)}catch(e){return!1}},n=function(){try{return Boolean(navigator.sendBeacon)}catch(e){return!1}},o=function(){try{return Boolean(XMLHttpRequest)}catch(e){return!1}},i=function(e){return void 0===e},s=function(e){return"string"==typeof e},a=function(e){return"number"==typeof e},c=function(e){return"function"==typeof e};function u(e){return function(t,r,n){var o,c,u;if(!this._userHasOptedOut){if(!(!i(this._apiKey)&&!i(this._appId)||(null===(o=n)||void 0===o?void 0:o.headers["X-Algolia-Application-Id"])&&(null===(c=n)||void 0===c?void 0:c.headers["X-Algolia-API-Key"])))throw new Error("Before calling any methods on the analytics, you first need to call the 'init' function with appId and apiKey parameters or provide custom credentials in additional parameters.");if(""===r.userToken||""===this._userToken)throw new Error("`userToken` cannot be an empty string.");var h=r.userToken||this._userToken;if(i(h))throw new Error("Before calling any methods on the analytics, you first need to call 'setUserToken' function or include 'userToken' in the event payload.");if(!s(r.index))throw new TypeError("expected required parameter `index` to be a string");if(!s(r.eventName))throw new TypeError("expected required parameter `eventName` to be a string");if(!i(r.userToken)&&!s(r.userToken))throw new TypeError("expected optional parameter `userToken` to be a string");var p={eventType:t,eventName:r.eventName,userToken:h,index:r.index};if(!i(r.timestamp)){if(!a(r.timestamp))throw new TypeError("expected optional parameter `timestamp` to be a number");p.timestamp=r.timestamp}if(!i(r.queryID)){if(!s(r.queryID))throw new TypeError("expected optional parameter `queryID` to be a string");p.queryID=r.queryID}if(!i(r.objectIDs)){if(!Array.isArray(r.objectIDs))throw new TypeError("expected optional parameter `objectIDs` to be an array");p.objectIDs=r.objectIDs}if(!i(r.positions)){if(!Array.isArray(r.positions))throw new TypeError("expected optional parameter `positions` to be an array");if(i(r.objectIDs))throw new Error("cannot use `positions` without providing `objectIDs`");if(r.objectIDs.length!==r.positions.length)throw new Error("objectIDs and positions need to be of the same size");p.positions=r.positions}if(!i(r.filters)){if(!i(r.objectIDs))throw new Error("cannot use `objectIDs` and `filters` for the same event");if(!Array.isArray(r.filters))throw new TypeError("expected optional parameter `filters` to be an array");p.filters=r.filters}if(i(r.objectIDs)&&i(r.filters))throw new Error("expected either `objectIDs` or `filters` to be provided");return function(e,t,r,n,o,i,s){void 0===s&&(s={});var a=Object.assign({"X-Algolia-Application-Id":t,"X-Algolia-API-Key":r,"X-Algolia-Agent":n},s),c=Object.keys(a).map(function(e){return e+"="+a[e]}).join("&");return e(o+"/1/events?"+c,{events:i})}(e,this._appId,this._apiKey,this._uaURIEncoded,this._endpointOrigin,[p],null===(u=n)||void 0===u?void 0:u.headers)}}}var h="1.10.0",p="insights-js ("+h+")";var l=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},f="_ALGOLIA",d=2592e6,w=function(e,t,r){var n=new Date;n.setTime(n.getTime()+r);var o="expires="+n.toUTCString();document.cookie=e+"="+t+";"+o+";path=/"},b=function(e){for(var t=e+"=",r=document.cookie.split(";"),n=0;n<r.length;n++){for(var o=r[n];" "===o.charAt(0);)o=o.substring(1);if(0===o.indexOf(t))return o.substring(t.length,o.length)}return""};t();var v,y,g,m,I=["de","us"];function k(e){var t;if(void 0===e&&(e={}),!i(e.region)&&-1===I.indexOf(e.region))throw new Error("optional region is incorrect, please provide either one of: "+I.join(", ")+".");if(!(i(e.cookieDuration)||a(e.cookieDuration)&&isFinite(e.cookieDuration)&&Math.floor(e.cookieDuration)===e.cookieDuration))throw new Error("optional cookieDuration is incorrect, expected an integer.");!function(e,t,r){var n=t.partial,o=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}(t,["partial"]);n||Object.assign(e,r);Object.assign(e,Object.keys(o).reduce(function(e,t){var r;return Object.assign(Object.assign({},e),((r={})["_"+t]=o[t],r))},{}))}(this,e,{_userHasOptedOut:!!e.userHasOptedOut,_region:e.region,_useCookie:(t=e.useCookie,null===t||void 0===t||t),_cookieDuration:e.cookieDuration||6*d}),this._endpointOrigin=e.region?"https://insights."+e.region+".algolia.io":"https://insights.algolia.io",this._ua=p,this._uaURIEncoded=encodeURIComponent(p),e.userToken?this.setUserToken(e.userToken):this._userToken||this._userHasOptedOut||!this._useCookie||this.setAnonymousUserToken()}Object.keys||(Object.keys=(v=Object.prototype.hasOwnProperty,y=!{toString:null}.propertyIsEnumerable("toString"),m=(g=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"]).length,function(e){if("function"!=typeof e&&("object"!=typeof e||null===e))throw new TypeError("Object.keys called on non-object");var t,r,n=[];for(t in e)v.call(e,t)&&n.push(t);if(y)for(r=0;r<m;r++)v.call(e,g[r])&&n.push(g[r]);return n})),t();var j=function(e){var t=e.requestFn;this._endpointOrigin="https://insights.algolia.io",this._userHasOptedOut=!1,this._useCookie=!1,this._cookieDuration=6*d,this._ua="",this._uaURIEncoded="",this.version=h,this.sendEvent=u(t).bind(this),this.init=k.bind(this),this.initSearch=function(e){if(i(this._apiKey)||i(this._appId))throw new Error("Before calling any methods on the analytics, you first need to call the 'init' function with appId and apiKey parameters");if(!e)throw new Error("initSearch function requires an argument with getQueryID and hitsContainer arguments");if(!e.getQueryID||"function"!=typeof e.getQueryID)throw new Error("getQueryID must be a function that returns the queryID of the last search operation");this.getQueryID=e.getQueryID}.bind(this),this.addAlgoliaAgent=function(e){-1===this._ua.indexOf("; "+e)&&(this._ua+="; "+e,this._uaURIEncoded=encodeURIComponent(this._ua))}.bind(this),this.setUserToken=function(e){this._userToken=e,c(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken)}.bind(this),this.setAnonymousUserToken=function(){if(r()){var e=b(f);e&&""!==e&&0===e.indexOf("anonymous-")?this.setUserToken(e):(this.setUserToken("anonymous-"+l()),w(f,this._userToken,this._cookieDuration))}}.bind(this),this.getUserToken=function(e,t){return c(t)&&t(null,this._userToken),this._userToken}.bind(this),this.onUserTokenChange=function(e,t){this._onUserTokenChangeCallback=e,t&&t.immediate&&c(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken)}.bind(this),this.clickedObjectIDsAfterSearch=function(e,t){if(!e)throw new Error("No params were sent to clickedObjectIDsAfterSearch function, please provide `queryID`, `objectIDs` and `positions` to be reported");if(!e.queryID)throw new Error("required queryID parameter was not sent, click event can not be properly sent without");if(!e.objectIDs)throw new Error("required objectIDs parameter was not sent, click event can not be properly sent without");if(!e.positions)throw new Error("required positions parameter was not sent, click event can not be properly sent without");this.sendEvent("click",e,t)}.bind(this),this.clickedObjectIDs=function(e,t){if(!e)throw new Error("No params were sent to clickedObjectIDs function, please provide `objectIDs` to be reported");if(!e.objectIDs)throw new Error("required `objectIDs` parameter was not sent, click event can not be properly sent without");this.sendEvent("click",e,t)}.bind(this),this.clickedFilters=function(e,t){if(!e)throw new Error("No params were sent to clickedFilters function, please provide `filters` to be reported");if(!e.filters)throw new Error("required `filters` parameter was not sent, click event can not be properly sent without");this.sendEvent("click",e,t)}.bind(this),this.convertedObjectIDsAfterSearch=function(e,t){if(!e)throw new Error("No params were sent to convertedObjectIDsAfterSearch function, please provide `queryID` and `objectIDs` to be reported");if(!e.queryID)throw new Error("required queryID parameter was not sent, conversion event can not be properly sent without");if(!e.objectIDs)throw new Error("required objectIDs parameter was not sent, conversion event can not be properly sent without");this.sendEvent("conversion",e,t)}.bind(this),this.convertedObjectIDs=function(e,t){if(!e)throw new Error("No params were sent to convertedObjectIDs function, please provide `objectIDs` to be reported");if(!e.objectIDs)throw new Error("required objectIDs parameter was not sent, conversion event can not be properly sent without");this.sendEvent("conversion",e,t)}.bind(this),this.convertedFilters=function(e,t){if(!e)throw new Error("No params were sent to convertedFilters function, please provide `filters` to be reported");if(!e.filters)throw new Error("required filters parameter was not sent, conversion event can not be properly sent without");this.sendEvent("conversion",e,t)}.bind(this),this.viewedObjectIDs=function(e,t){if(!e)throw new Error("No params were sent to viewedObjectIDs function, please provide `objectIDs` to be reported");if(!e.objectIDs)throw new Error("required objectIDs parameter was not sent, view event can not be properly sent without");this.sendEvent("view",e,t)}.bind(this),this.viewedFilters=function(e,t){if(!e)throw new Error("No params were sent to viewedFilters function, please provide `filters` to be reported");if(!e.filters)throw new Error("required filters parameter was not sent, view event can not be properly sent without");this.sendEvent("view",e,t)}.bind(this),this._get=function(e,t){t(this[e])}.bind(this),this.getVersion=function(e){c(e)&&e(this.version)}.bind(this)},D=function(e,t){var r=JSON.stringify(t);navigator.sendBeacon(e,r)},O=function(e,t){var r=JSON.stringify(t),n=new XMLHttpRequest;n.open("POST",e),n.send(r)};function E(e){var t,r=e.AlgoliaAnalyticsObject;if(r){var n=(t=this,function(e){for(var r=[],n=arguments.length-1;n-- >0;)r[n]=arguments[n+1];e&&c(t[e])?t[e].apply(t,r):console.warn("The method `"+e+"` doesn't exist.")}),o=e[r];o.queue=o.queue||[];var i=o.queue;i.forEach(function(e){var t=[].slice.call(e),r=t[0],o=t.slice(1);n.apply(void 0,[r].concat(o))}),i.push=function(e){var t=[].slice.call(e),r=t[0],o=t.slice(1);n.apply(void 0,[r].concat(o))}}}function x(e){var t=new j({requestFn:e});return"object"==typeof window&&E.call(t,window),t.version=h,t}var T=x(function(){if(n())return D;if(o())return O;throw new Error("Could not find a supported HTTP request client in this environment.")}());e.createInsightsClient=x,e.default=T,Object.defineProperty(e,"__esModule",{value:!0})});
|