mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2024-12-27 18:42:33 +01:00
2 lines
7.2 KiB
JavaScript
2 lines
7.2 KiB
JavaScript
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).AlgoliaAnalytics={})}(this,function(e){"use strict";var n=function(){try{return Boolean(navigator.cookieEnabled)}catch(e){return!1}},t=function(){try{return Boolean(navigator.sendBeacon)}catch(e){return!1}},i=function(){try{return Boolean(XMLHttpRequest)}catch(e){return!1}},o=function(e){return void 0===e},r=function(e){return"string"==typeof e},s=function(e){return"number"==typeof e},a=function(e){return"function"==typeof e};function u(e){return function(n){var t=this;if(!this._userHasOptedOut){if(!this._hasCredentials)throw new Error("Before calling any methods on the analytics, you first need to call the 'init' function with appId and apiKey parameters");var i=n.map(function(e){var n,i,r=e.filters,s=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)n.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(t[i[o]]=e[i[o]])}return t}(e,["filters"]),a=Object.assign(Object.assign({},s),{userToken:(i=null===(n=e)||void 0===n?void 0:n.userToken,null!==i&&void 0!==i?i:t._userToken)});return o(r)||(a.filters=r.map(encodeURIComponent)),a});return function(e,n,t,i,o,r){var s=encodeURIComponent(i.join("; "));return e(o+"/1/events?X-Algolia-Application-Id="+n+"&X-Algolia-API-Key="+t+"&X-Algolia-Agent="+s,{events:r})}(e,this._appId,this._apiKey,this._ua,this._endpointOrigin,i)}}}var c=["insights-js (2.2.1)","insights-js-browser-umd (2.2.1)"];var h=["de","us"],l=2592e6;function f(e,n){return n.map(function(n){return Object.assign({eventType:e},n)})}var p,d,v,g,y=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var n=16*Math.random()|0;return("x"===e?n:3&n|8).toString(16)})},b="_ALGOLIA",k=function(e,n,t){var i=new Date;i.setTime(i.getTime()+t);var o="expires="+i.toUTCString();document.cookie=e+"="+n+";"+o+";path=/"},O=function(e){for(var n=e+"=",t=document.cookie.split(";"),i=0;i<t.length;i++){for(var o=t[i];" "===o.charAt(0);)o=o.substring(1);if(0===o.indexOf(n))return o.substring(n.length,o.length)}return""};Object.keys||(Object.keys=(p=Object.prototype.hasOwnProperty,d=!{toString:null}.propertyIsEnumerable("toString"),g=(v=["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 n,t,i=[];for(n in e)p.call(e,n)&&i.push(n);if(d)for(t=0;t<g;t++)p.call(e,v[t])&&i.push(v[t]);return i})),"function"!=typeof Object.assign&&(Object.assign=function(e,n){var t=arguments;if(null==e)throw new TypeError("Cannot convert undefined or null to object");for(var i=Object(e),o=1;o<arguments.length;o++){var r=t[o];if(null!=r)for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[s]=r[s])}return i});var x=function(e){var t=e.requestFn;this._ua=[],this.version="2.2.1",this._hasCredentials=!1,this.sendEvents=u(t).bind(this),this.init=function(e){var n;if(!e)throw new Error("Init function should be called with an object argument containing your apiKey and appId");if(o(e.apiKey)||!r(e.apiKey))throw new Error("apiKey is missing, please provide it so we can authenticate the application");if(o(e.appId)||!r(e.appId))throw new Error("appId is missing, please provide it, so we can properly attribute data to your application");if(!o(e.region)&&-1===h.indexOf(e.region))throw new Error("optional region is incorrect, please provide either one of: "+h.join(", ")+".");if(!(o(e.cookieDuration)||s(e.cookieDuration)&&isFinite(e.cookieDuration)&&Math.floor(e.cookieDuration)===e.cookieDuration))throw new Error("optional cookieDuration is incorrect, expected an integer.");this._apiKey=e.apiKey,this._appId=e.appId,this._userHasOptedOut=!!e.userHasOptedOut,this._region=e.region,this._endpointOrigin=e.region?"https://insights."+e.region+".algolia.io":"https://insights.algolia.io",this._useCookie=null!==(n=e.useCookie)&&void 0!==n&&n,this._cookieDuration=e.cookieDuration?e.cookieDuration:6*l,this._hasCredentials=!0,this._ua=[].concat(c),e.userToken?this.setUserToken(e.userToken):this._userToken||this._userHasOptedOut||!this._useCookie||this.setAnonymousUserToken()}.bind(this),this.addAlgoliaAgent=function(e){-1===this._ua.indexOf(e)&&this._ua.push(e)}.bind(this),this.setUserToken=function(e){this._userToken=e,a(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken)}.bind(this),this.setAnonymousUserToken=function(){if(n()){var e=O(b);e&&""!==e&&0===e.indexOf("anonymous-")?this.setUserToken(e):(this.setUserToken("anonymous-"+y()),k(b,this._userToken,this._cookieDuration))}}.bind(this),this.getUserToken=function(e,n){return a(n)&&n(null,this._userToken),this._userToken}.bind(this),this.onUserTokenChange=function(e,n){this._onUserTokenChangeCallback=e,n&&n.immediate&&a(this._onUserTokenChangeCallback)&&this._onUserTokenChangeCallback(this._userToken)}.bind(this),this.clickedObjectIDsAfterSearch=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("click",e))}.bind(this),this.clickedObjectIDs=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("click",e))}.bind(this),this.clickedFilters=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("click",e))}.bind(this),this.convertedObjectIDsAfterSearch=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("conversion",e))}.bind(this),this.convertedObjectIDs=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("conversion",e))}.bind(this),this.convertedFilters=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("conversion",e))}.bind(this),this.viewedObjectIDs=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("view",e))}.bind(this),this.viewedFilters=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];return this.sendEvents(f("view",e))}.bind(this),this.getVersion=function(e){a(e)&&e(this.version)}.bind(this)},w=function(e,n){var t=JSON.stringify(n);if(!navigator.sendBeacon(e,t))return _(e,n)},_=function(e,n){var t=JSON.stringify(n),i=new XMLHttpRequest;i.open("POST",e),i.send(t)};function T(e){var n,t=e.AlgoliaAnalyticsObject;if(t){var i=(n=this,function(e){for(var t=[],i=arguments.length-1;i-- >0;)t[i]=arguments[i+1];e&&a(n[e])?n[e].apply(n,t):console.warn("The method `"+e+"` doesn't exist.")}),o=e[t];o.queue=o.queue||[];var r=o.queue;r.forEach(function(e){var n=[].slice.call(e),t=n[0],o=n.slice(1);i.apply(void 0,[t].concat(o))}),r.push=function(e){var n=[].slice.call(e),t=n[0],o=n.slice(1);i.apply(void 0,[t].concat(o))}}}function m(e){var n=new x({requestFn:e});return"undefined"!=typeof window&&T.call(n,window),n}var j=m(function(){if(t())return w;if(i())return _;throw new Error("Could not find a supported HTTP request client in this environment.")}());e.createInsightsClient=m,e.default=j,Object.defineProperty(e,"__esModule",{value:!0})});
|