LocalCDN-Firefox-Chrome-Brave/resources/search-insights/2.13.0/search-insights.min.jsm

2 lines
9.8 KiB
JavaScript

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).AlgoliaAnalytics={})}(this,function(e){"use strict";var t="2.13.0";function o(e){return e.reduce(function(e,t){var n=e.events,e=e.additionalParams;return"index"in t?{additionalParams:e,events:n.concat([t])}:{events:n,additionalParams:t}},{events:[],additionalParams:void 0})}function n(){try{return Boolean(navigator.cookieEnabled)}catch(e){return}}function l(e){return void 0===e}function r(e){return"number"==typeof e}function s(e){return"function"==typeof e}function i(e){var n,i,t=e.AlgoliaAnalyticsObject;t&&(i=this,n=function(e){for(var t=[],n=arguments.length-1;0<n--;)t[n]=arguments[n+1];e&&s(i[e])?i[e].apply(i,t):console.warn("The method `"+e+"` doesn't exist.")},(e=e[t]).queue=e.queue||[],(t=e.queue).forEach(function(e){var e=[].slice.call(e),t=e[0],e=e.slice(1);n.apply(void 0,[t].concat(e))}),t.push=function(e){var e=[].slice.call(e),t=e[0],e=e.slice(1);n.apply(void 0,[t].concat(e))})}var a=["insights-js ("+t+")","insights-js-browser-umd ("+t+")"];function f(e,t){var n={};for(o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]]);return n}function u(d){return function(e,t){var i=this;if(!this._userHasOptedOut){if(!(!l(this._apiKey)&&!l(this._appId)||(null==(h=null==t?void 0:t.headers)?void 0:h["X-Algolia-Application-Id"])&&(null==(h=null==t?void 0:t.headers)?void 0:h["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.");!this._userToken&&this._anonymousUserToken&&this.setAnonymousUserToken(!0);var n,o,s,r,a,u,c,h=e.map(function(e){var t=e.filters,n=f(e,["filters"]),e=Object.assign(Object.assign({},n),{userToken:null!=(n=null==e?void 0:e.userToken)?n:i._userToken,authenticatedUserToken:null!=(n=null==e?void 0:e.authenticatedUserToken)?n:i._authenticatedUserToken});return l(t)||(e.filters=t.map(encodeURIComponent)),e});return e=d,n=this._ua,o=this._endpointOrigin,h=h,s=this._appId,r=this._apiKey,t=null==t?void 0:t.headers,a=(t=void 0===t?{}:t)["X-Algolia-Application-Id"],u=t["X-Algolia-API-Key"],t=f(t,["X-Algolia-Application-Id","X-Algolia-API-Key"]),c=Object.assign({"X-Algolia-Application-Id":null!=a?a:s,"X-Algolia-API-Key":null!=u?u:r,"X-Algolia-Agent":encodeURIComponent(n.join("; "))},t),a=Object.keys(c).map(function(e){return e+"="+c[e]}).join("&"),e(o+"/1/events?"+a,{events:h})}}}function c(){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)})}function h(e,t,n){var i=new Date,n=(i.setTime(i.getTime()+n),"expires="+i.toUTCString());document.cookie=e+"="+t+";"+n+";path=/"}function d(e){for(var t=e+"=",n=document.cookie.split(";"),i=0;i<n.length;i++){for(var o=n[i];" "===o.charAt(0);)o=o.substring(1);if(0===o.indexOf(t))return o.substring(t.length,o.length)}return""}var v="_ALGOLIA",p=2592e6;function g(t,e){return e.map(function(e){return Object.assign({eventType:t},e)})}function k(t,n,e){return e.map(function(e){return Object.assign({eventType:t,eventSubtype:n},e)})}var b=["de","us"];function T(e){if(!l((e=void 0===e?{}:e).region)&&-1===b.indexOf(e.region))throw new Error("optional region is incorrect, please provide either one of: "+b.join(", ")+".");if(!(l(e.cookieDuration)||r(e.cookieDuration)&&isFinite(e.cookieDuration)&&Math.floor(e.cookieDuration)===e.cookieDuration))throw new Error("optional cookieDuration is incorrect, expected an integer.");var t=this,n=e,i={_userHasOptedOut:Boolean(e.userHasOptedOut),_region:e.region,_host:e.host,_anonymousUserToken:null==(i=e.anonymousUserToken)||i,_useCookie:null!=(i=e.useCookie)&&i,_cookieDuration:e.cookieDuration||6*p},o=n.partial,s=f(n,["partial"]);o||Object.assign(t,i),Object.assign(t,Object.keys(s).reduce(function(e,t){return Object.assign(Object.assign({},e),((e={})["_"+t]=s[t],e))},{})),this._endpointOrigin=this._host||(this._region?"https://insights."+this._region+".algolia.io":"https://insights.algolia.io"),this._ua=[].concat(a),e.authenticatedUserToken&&this.setAuthenticatedUserToken(e.authenticatedUserToken),e.userToken?this.setUserToken(e.userToken):this._userToken||this._userHasOptedOut||!this._useCookie||this.setAnonymousUserToken()}function y(e){e=e.requestFn,this._endpointOrigin="https://insights.algolia.io",this._anonymousUserToken=!0,this._userHasOptedOut=!1,this._useCookie=!1,this._cookieDuration=6*p,this._ua=[],this.version=t,this.sendEvents=u(e).bind(this),this.init=T.bind(this),this.addAlgoliaAgent=function(e){-1===this._ua.indexOf(e)&&this._ua.push(e)}.bind(this),this.setUserToken=function(e){return this._userToken=e,s(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken),this._userToken}.bind(this),this.setAnonymousUserToken=function(e){(e=void 0!==e&&e)?this.setUserToken("anonymous-"+c()):n()&&((e=d(v))&&""!==e&&0===e.indexOf("anonymous-")?this.setUserToken(e):(e=this.setUserToken("anonymous-"+c()),h(v,e,this._cookieDuration)))}.bind(this),this.getUserToken=function(e,t){return s(t)&&t(null,this._userToken),this._userToken}.bind(this),this.onUserTokenChange=function(e,t){this._onUserTokenChangeCallback=e,t&&t.immediate&&s(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken)}.bind(this),this.setAuthenticatedUserToken=function(e){return this._authenticatedUserToken=e,s(this._onAuthenticatedUserTokenChangeCallback)&&this._onAuthenticatedUserTokenChangeCallback(this._authenticatedUserToken),this._authenticatedUserToken}.bind(this),this.getAuthenticatedUserToken=function(e,t){return s(t)&&t(null,this._authenticatedUserToken),this._authenticatedUserToken}.bind(this),this.onAuthenticatedUserTokenChange=function(e,t){this._onAuthenticatedUserTokenChangeCallback=e,t&&t.immediate&&s(this._onAuthenticatedUserTokenChangeCallback)&&this._onAuthenticatedUserTokenChangeCallback(this._authenticatedUserToken)}.bind(this),this.clickedObjectIDsAfterSearch=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("click",n),i)}.bind(this),this.clickedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("click",n),i)}.bind(this),this.clickedFilters=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("click",n),i)}.bind(this),this.convertedObjectIDsAfterSearch=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("conversion",n),i)}.bind(this),this.purchasedObjectIDsAfterSearch=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(k("conversion","purchase",n),i)}.bind(this),this.addedToCartObjectIDsAfterSearch=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(k("conversion","addToCart",n),i)}.bind(this),this.convertedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("conversion",n),i)}.bind(this),this.addedToCartObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(k("conversion","addToCart",n),i)}.bind(this),this.purchasedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(k("conversion","purchase",n),i)}.bind(this),this.convertedFilters=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("conversion",n),i)}.bind(this),this.viewedObjectIDs=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("view",n),i)}.bind(this),this.viewedFilters=function(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];var n=(i=o(e)).events,i=i.additionalParams;return this.sendEvents(g("view",n),i)}.bind(this),this.getVersion=function(e){s(e)&&e(this.version)}.bind(this)}function m(e,t){var n=JSON.stringify(t),n=navigator.sendBeacon(e,n);return Promise.resolve(!!n||O(e,t))}function _(e,i){return new Promise(function(t,n){fetch(e,{method:"POST",body:JSON.stringify(i),headers:{"Content-Type":"application/json"}}).then(function(e){t(200===e.status)}).catch(function(e){n(e)})})}var O=function(o,s){return new Promise(function(e,t){var n=JSON.stringify(s),i=new XMLHttpRequest;i.addEventListener("readystatechange",function(){4===i.readyState&&200===i.status?e(!0):4===i.readyState&&e(!1)}),i.addEventListener("error",function(){return t()}),i.addEventListener("timeout",function(){return e(!1)}),i.open("POST",o),i.setRequestHeader("Content-Type","application/json"),i.setRequestHeader("Content-Length",""+n.length),i.send(n)})};function x(e){e=new y({requestFn:e});return"object"==typeof window&&i.call(e,window),e.version=t,e}var A=x(function(){if(function(){try{return Boolean(navigator.sendBeacon)}catch(e){return!1}}())return m;if(function(){try{return Boolean(XMLHttpRequest)}catch(e){return!1}}())return O;if(function(){try{return void 0!==fetch}catch(e){return!1}}())return _;throw new Error("Could not find a supported HTTP request client in this environment.")}());e.createInsightsClient=x,e.default=A,Object.defineProperty(e,"__esModule",{value:!0})});