@algolia/client-analytics 5.19.0 → 5.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/browser.d.ts +56 -56
- package/dist/builds/browser.js +22 -22
- package/dist/builds/browser.js.map +1 -1
- package/dist/builds/browser.min.js +1 -1
- package/dist/builds/browser.min.js.map +1 -1
- package/dist/builds/browser.umd.js +1 -1
- package/dist/builds/fetch.js +22 -22
- package/dist/builds/fetch.js.map +1 -1
- package/dist/builds/node.cjs +22 -22
- package/dist/builds/node.cjs.map +1 -1
- package/dist/builds/node.js +22 -22
- package/dist/builds/node.js.map +1 -1
- package/dist/builds/worker.js +22 -22
- package/dist/builds/worker.js.map +1 -1
- package/dist/fetch.d.ts +56 -56
- package/dist/node.d.cts +56 -56
- package/dist/node.d.ts +56 -56
- package/dist/src/analyticsClient.cjs +22 -22
- package/dist/src/analyticsClient.cjs.map +1 -1
- package/dist/src/analyticsClient.js +22 -22
- package/dist/src/analyticsClient.js.map +1 -1
- package/dist/worker.d.ts +56 -56
- package/package.json +10 -10
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@algolia/client-analytics"] = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function _(){function o(t){return new Promise(d=>{let u=new XMLHttpRequest;u.open(t.method,t.url,!0),Object.keys(t.headers).forEach(f=>u.setRequestHeader(f,t.headers[f]));let h=(f,e)=>setTimeout(()=>{u.abort(),d({status:0,content:e,isTimedOut:!0});},f),R=h(t.connectTimeout,"Connection timeout"),y;u.onreadystatechange=()=>{u.readyState>u.OPENED&&y===void 0&&(clearTimeout(R),y=h(t.responseTimeout,"Socket timeout"));},u.onerror=()=>{u.status===0&&(clearTimeout(R),clearTimeout(y),d({content:u.responseText||"Network request failed",status:u.status,isTimedOut:!1}));},u.onload=()=>{clearTimeout(R),clearTimeout(y),d({content:u.responseText,status:u.status,isTimedOut:!1});},u.send(t.data);})}return {send:o}}function L(o){let t,d=`algolia-client-js-${o.key}`;function u(){return t===void 0&&(t=o.localStorage||window.localStorage),t}function h(){return JSON.parse(u().getItem(d)||"{}")}function R(f){u().setItem(d,JSON.stringify(f));}function y(){let f=o.timeToLive?o.timeToLive*1e3:null,e=h(),s=Object.fromEntries(Object.entries(e).filter(([,i])=>i.timestamp!==void 0));if(R(s),!f)return;let n=Object.fromEntries(Object.entries(s).filter(([,i])=>{let l=new Date().getTime();return !(i.timestamp+f<l)}));R(n);}return {get(f,e,s={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(y(),h()[JSON.stringify(f)])).then(n=>Promise.all([n?n.value:e(),n!==void 0])).then(([n,i])=>Promise.all([n,i||s.miss(n)])).then(([n])=>n)},set(f,e){return Promise.resolve().then(()=>{let s=h();return s[JSON.stringify(f)]={timestamp:new Date().getTime(),value:e},u().setItem(d,JSON.stringify(s)),e})},delete(f){return Promise.resolve().then(()=>{let e=h();delete e[JSON.stringify(f)],u().setItem(d,JSON.stringify(e));})},clear(){return Promise.resolve().then(()=>{u().removeItem(d);})}}}function V(){return {get(o,t,d={miss:()=>Promise.resolve()}){return t().then(h=>Promise.all([h,d.miss(h)])).then(([h])=>h)},set(o,t){return Promise.resolve(t)},delete(o){return Promise.resolve()},clear(){return Promise.resolve()}}}function C(o){let t=[...o.caches],d=t.shift();return d===void 0?V():{get(u,h,R={miss:()=>Promise.resolve()}){return d.get(u,h,R).catch(()=>C({caches:t}).get(u,h,R))},set(u,h){return d.set(u,h).catch(()=>C({caches:t}).set(u,h))},delete(u){return d.delete(u).catch(()=>C({caches:t}).delete(u))},clear(){return d.clear().catch(()=>C({caches:t}).clear())}}}function v(o={serializable:!0}){let t={};return {get(d,u,h={miss:()=>Promise.resolve()}){let R=JSON.stringify(d);if(R in t)return Promise.resolve(o.serializable?JSON.parse(t[R]):t[R]);let y=u();return y.then(f=>h.miss(f)).then(()=>y)},set(d,u){return t[JSON.stringify(d)]=o.serializable?JSON.stringify(u):u,Promise.resolve(u)},delete(d){return delete t[JSON.stringify(d)],Promise.resolve()},clear(){return t={},Promise.resolve()}}}function Y(o){let t={value:`Algolia for JavaScript (${o})`,add(d){let u=`; ${d.segment}${d.version!==void 0?` (${d.version})`:""}`;return t.value.indexOf(u)===-1&&(t.value=`${t.value}${u}`),t}};return t}function $(o,t,d="WithinHeaders"){let u={"x-algolia-api-key":t,"x-algolia-application-id":o};return {headers(){return d==="WithinHeaders"?u:{}},queryParameters(){return d==="WithinQueryParameters"?u:{}}}}function j({algoliaAgents:o,client:t,version:d}){let u=Y(d).add({segment:t,version:d});return o.forEach(h=>u.add(h)),u}function W(){return {debug(o,t){return Promise.resolve()},info(o,t){return Promise.resolve()},error(o,t){return Promise.resolve()}}}var U=2*60*1e3;function I(o,t="up"){let d=Date.now();function u(){return t==="up"||Date.now()-d>U}function h(){return t==="timed out"&&Date.now()-d<=U}return {...o,status:t,lastUpdate:d,isUp:u,isTimedOut:h}}var J=class extends Error{name="AlgoliaError";constructor(o,t){super(o),t&&(this.name=t);}},z=class extends J{stackTrace;constructor(o,t,d){super(o,d),this.stackTrace=t;}},Z=class extends z{constructor(o){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",o,"RetryError");}},k=class extends z{status;constructor(o,t,d,u="ApiError"){super(o,d,u),this.status=t;}},ee=class extends J{response;constructor(o,t){super(o,"DeserializationError"),this.response=t;}},te=class extends k{error;constructor(o,t,d,u){super(o,t,u,"DetailedApiError"),this.error=d;}};function re(o,t,d){let u=oe(d),h=`${o.protocol}://${o.url}${o.port?`:${o.port}`:""}/${t.charAt(0)==="/"?t.substring(1):t}`;return u.length&&(h+=`?${u}`),h}function oe(o){return Object.keys(o).filter(t=>o[t]!==void 0).sort().map(t=>`${t}=${encodeURIComponent(Object.prototype.toString.call(o[t])==="[object Array]"?o[t].join(","):o[t]).replace(/\+/g,"%20")}`).join("&")}function se(o,t){if(o.method==="GET"||o.data===void 0&&t.data===void 0)return;let d=Array.isArray(o.data)?o.data:{...o.data,...t.data};return JSON.stringify(d)}function ne(o,t,d){let u={Accept:"application/json",...o,...t,...d},h={};return Object.keys(u).forEach(R=>{let y=u[R];h[R.toLowerCase()]=y;}),h}function ie(o){try{return JSON.parse(o.content)}catch(t){throw new ee(t.message,o)}}function ae({content:o,status:t},d){try{let u=JSON.parse(o);return "error"in u?new te(u.message,t,u.error,d):new k(u.message,t,d)}catch{}return new k(o,t,d)}function ue({isTimedOut:o,status:t}){return !o&&~~t===0}function ce({isTimedOut:o,status:t}){return o||ue({isTimedOut:o,status:t})||~~(t/100)!==2&&~~(t/100)!==4}function de({status:o}){return ~~(o/100)===2}function le(o){return o.map(t=>M(t))}function M(o){let t=o.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...o,request:{...o.request,headers:{...o.request.headers,...t}}}}function B({hosts:o,hostsCache:t,baseHeaders:d,logger:u,baseQueryParameters:h,algoliaAgent:R,timeouts:y,requester:f,requestsCache:e,responsesCache:s}){async function n(a){let c=await Promise.all(a.map(P=>t.get(P,()=>Promise.resolve(I(P))))),r=c.filter(P=>P.isUp()),m=c.filter(P=>P.isTimedOut()),p=[...r,...m];return {hosts:p.length>0?p:a,getTimeout(P,S){return (m.length===0&&P===0?1:m.length+3+P)*S}}}async function i(a,c,r=!0){let m=[],p=se(a,c),g=ne(d,a.headers,c.headers),P=a.method==="GET"?{...a.data,...c.data}:{},S={...h,...a.queryParameters,...P};if(R.value&&(S["x-algolia-agent"]=R.value),c&&c.queryParameters)for(let T of Object.keys(c.queryParameters))!c.queryParameters[T]||Object.prototype.toString.call(c.queryParameters[T])==="[object Object]"?S[T]=c.queryParameters[T]:S[T]=c.queryParameters[T].toString();let q=0,E=async(T,A)=>{let G=T.pop();if(G===void 0)throw new Z(le(m));let O={...y,...c.timeouts},F={data:p,headers:g,method:a.method,url:re(G,a.path,S),connectTimeout:A(q,O.connect),responseTimeout:A(q,r?O.read:O.write)},D=N=>{let Q={request:F,response:N,host:G,triesLeft:T.length};return m.push(Q),Q},w=await f.send(F);if(ce(w)){let N=D(w);return w.isTimedOut&&q++,u.info("Retryable failure",M(N)),await t.set(G,I(G,w.isTimedOut?"timed out":"down")),E(T,A)}if(de(w))return ie(w);throw D(w),ae(w,m)},K=o.filter(T=>T.accept==="readWrite"||(r?T.accept==="read":T.accept==="write")),H=await n(K);return E([...H.hosts].reverse(),H.getTimeout)}function l(a,c={}){let r=a.useReadTransporter||a.method==="GET";if(!r)return i(a,c,r);let m=()=>i(a,c);if((c.cacheable||a.cacheable)!==!0)return m();let g={request:a,requestOptions:c,transporter:{queryParameters:h,headers:d}};return s.get(g,()=>e.get(g,()=>e.set(g,m()).then(P=>Promise.all([e.delete(g),P]),P=>Promise.all([e.delete(g),Promise.reject(P)])).then(([P,S])=>S)),{miss:P=>s.set(g,P)})}return {hostsCache:t,requester:f,timeouts:y,logger:u,algoliaAgent:R,baseHeaders:d,baseQueryParameters:h,hosts:o,request:l,requestsCache:e,responsesCache:s}}var x="5.19.0",b=["de","us"];function fe(o){return [{url:o?"analytics.{region}.algolia.com".replace("{region}",o):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function X({appId:o,apiKey:t,authMode:d,algoliaAgents:u,region:h,...R}){let y=$(o,t,d),f=B({hosts:fe(h),...R,algoliaAgent:j({algoliaAgents:u,client:"Analytics",version:x}),baseHeaders:{"content-type":"text/plain",...y.headers(),...R.baseHeaders},baseQueryParameters:{...y.queryParameters(),...R.baseQueryParameters}});return {transporter:f,appId:o,apiKey:t,clearCache(){return Promise.all([f.requestsCache.clear(),f.responsesCache.clear()]).then(()=>{})},get _ua(){return f.algoliaAgent.value},addAlgoliaAgent(e,s){f.algoliaAgent.add({segment:e,version:s});},setClientApiKey({apiKey:e}){!d||d==="WithinHeaders"?f.baseHeaders["x-algolia-api-key"]=e:f.baseQueryParameters["x-algolia-api-key"]=e;},customDelete({path:e,parameters:s},n){if(!e)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{}};return f.request(c,n)},customGet({path:e,parameters:s},n){if(!e)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{}};return f.request(c,n)},customPost({path:e,parameters:s,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPost`.");let r={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{},data:n||{}};return f.request(r,i)},customPut({path:e,parameters:s,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPut`.");let r={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{},data:n||{}};return f.request(r,i)},getAddToCartRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getAddToCartRate`.");let a="/2/conversions/addToCartRate",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getAverageClickPosition({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getAverageClickPosition`.");let a="/2/clicks/averageClickPosition",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getClickPositions({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getClickPositions`.");let a="/2/clicks/positions",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getClickThroughRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getClickThroughRate`.");let a="/2/clicks/clickThroughRate",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getConversionRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getConversionRate`.");let a="/2/conversions/conversionRate",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getNoClickRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getNoClickRate`.");let a="/2/searches/noClickRate",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getNoResultsRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getNoResultsRate`.");let a="/2/searches/noResultRate",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getPurchaseRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getPurchaseRate`.");let a="/2/conversions/purchaseRate",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getRevenue({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getRevenue`.");let a="/2/conversions/revenue",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getSearchesCount({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesCount`.");let a="/2/searches/count",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getSearchesNoClicks({index:e,startDate:s,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoClicks`.");let r="/2/searches/noClicks",m={},p={};e!==void 0&&(p.index=e.toString()),s!==void 0&&(p.startDate=s.toString()),n!==void 0&&(p.endDate=n.toString()),i!==void 0&&(p.limit=i.toString()),l!==void 0&&(p.offset=l.toString()),a!==void 0&&(p.tags=a.toString());let g={method:"GET",path:r,queryParameters:p,headers:m};return f.request(g,c)},getSearchesNoResults({index:e,startDate:s,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoResults`.");let r="/2/searches/noResults",m={},p={};e!==void 0&&(p.index=e.toString()),s!==void 0&&(p.startDate=s.toString()),n!==void 0&&(p.endDate=n.toString()),i!==void 0&&(p.limit=i.toString()),l!==void 0&&(p.offset=l.toString()),a!==void 0&&(p.tags=a.toString());let g={method:"GET",path:r,queryParameters:p,headers:m};return f.request(g,c)},getStatus({index:e},s){if(!e)throw new Error("Parameter `index` is required when calling `getStatus`.");let n="/2/status",i={},l={};e!==void 0&&(l.index=e.toString());let a={method:"GET",path:n,queryParameters:l,headers:i};return f.request(a,s)},getTopCountries({index:e,startDate:s,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getTopCountries`.");let r="/2/countries",m={},p={};e!==void 0&&(p.index=e.toString()),s!==void 0&&(p.startDate=s.toString()),n!==void 0&&(p.endDate=n.toString()),i!==void 0&&(p.limit=i.toString()),l!==void 0&&(p.offset=l.toString()),a!==void 0&&(p.tags=a.toString());let g={method:"GET",path:r,queryParameters:p,headers:m};return f.request(g,c)},getTopFilterAttributes({index:e,search:s,startDate:n,endDate:i,limit:l,offset:a,tags:c},r){if(!e)throw new Error("Parameter `index` is required when calling `getTopFilterAttributes`.");let m="/2/filters",p={},g={};e!==void 0&&(g.index=e.toString()),s!==void 0&&(g.search=s.toString()),n!==void 0&&(g.startDate=n.toString()),i!==void 0&&(g.endDate=i.toString()),l!==void 0&&(g.limit=l.toString()),a!==void 0&&(g.offset=a.toString()),c!==void 0&&(g.tags=c.toString());let P={method:"GET",path:m,queryParameters:g,headers:p};return f.request(P,r)},getTopFilterForAttribute({attribute:e,index:s,search:n,startDate:i,endDate:l,limit:a,offset:c,tags:r},m){if(!e)throw new Error("Parameter `attribute` is required when calling `getTopFilterForAttribute`.");if(!s)throw new Error("Parameter `index` is required when calling `getTopFilterForAttribute`.");let p="/2/filters/{attribute}".replace("{attribute}",encodeURIComponent(e)),g={},P={};s!==void 0&&(P.index=s.toString()),n!==void 0&&(P.search=n.toString()),i!==void 0&&(P.startDate=i.toString()),l!==void 0&&(P.endDate=l.toString()),a!==void 0&&(P.limit=a.toString()),c!==void 0&&(P.offset=c.toString()),r!==void 0&&(P.tags=r.toString());let S={method:"GET",path:p,queryParameters:P,headers:g};return f.request(S,m)},getTopFiltersNoResults({index:e,search:s,startDate:n,endDate:i,limit:l,offset:a,tags:c},r){if(!e)throw new Error("Parameter `index` is required when calling `getTopFiltersNoResults`.");let m="/2/filters/noResults",p={},g={};e!==void 0&&(g.index=e.toString()),s!==void 0&&(g.search=s.toString()),n!==void 0&&(g.startDate=n.toString()),i!==void 0&&(g.endDate=i.toString()),l!==void 0&&(g.limit=l.toString()),a!==void 0&&(g.offset=a.toString()),c!==void 0&&(g.tags=c.toString());let P={method:"GET",path:m,queryParameters:g,headers:p};return f.request(P,r)},getTopHits({index:e,search:s,clickAnalytics:n,revenueAnalytics:i,startDate:l,endDate:a,limit:c,offset:r,tags:m},p){if(!e)throw new Error("Parameter `index` is required when calling `getTopHits`.");let g="/2/hits",P={},S={};e!==void 0&&(S.index=e.toString()),s!==void 0&&(S.search=s.toString()),n!==void 0&&(S.clickAnalytics=n.toString()),i!==void 0&&(S.revenueAnalytics=i.toString()),l!==void 0&&(S.startDate=l.toString()),a!==void 0&&(S.endDate=a.toString()),c!==void 0&&(S.limit=c.toString()),r!==void 0&&(S.offset=r.toString()),m!==void 0&&(S.tags=m.toString());let q={method:"GET",path:g,queryParameters:S,headers:P};return f.request(q,p)},getTopSearches({index:e,clickAnalytics:s,revenueAnalytics:n,startDate:i,endDate:l,orderBy:a,direction:c,limit:r,offset:m,tags:p},g){if(!e)throw new Error("Parameter `index` is required when calling `getTopSearches`.");let P="/2/searches",S={},q={};e!==void 0&&(q.index=e.toString()),s!==void 0&&(q.clickAnalytics=s.toString()),n!==void 0&&(q.revenueAnalytics=n.toString()),i!==void 0&&(q.startDate=i.toString()),l!==void 0&&(q.endDate=l.toString()),a!==void 0&&(q.orderBy=a.toString()),c!==void 0&&(q.direction=c.toString()),r!==void 0&&(q.limit=r.toString()),m!==void 0&&(q.offset=m.toString()),p!==void 0&&(q.tags=p.toString());let E={method:"GET",path:P,queryParameters:q,headers:S};return f.request(E,g)},getUsersCount({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getUsersCount`.");let a="/2/users/count",c={},r={};e!==void 0&&(r.index=e.toString()),s!==void 0&&(r.startDate=s.toString()),n!==void 0&&(r.endDate=n.toString()),i!==void 0&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)}}}function At(o,t,d,u){if(!o||typeof o!="string")throw new Error("`appId` is missing.");if(!t||typeof t!="string")throw new Error("`apiKey` is missing.");if(d&&(typeof d!="string"||!b.includes(d)))throw new Error(`\`region\` must be one of the following: ${b.join(", ")}`);return X({appId:o,apiKey:t,region:d,timeouts:{connect:1e3,read:2e3,write:3e4},logger:W(),requester:_(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:v(),requestsCache:v({serializable:!1}),hostsCache:C({caches:[L({key:`${x}-${o}`}),v()]}),...u})}
|
|
7
|
+
function _(){function o(t){return new Promise(d=>{let u=new XMLHttpRequest;u.open(t.method,t.url,true),Object.keys(t.headers).forEach(f=>u.setRequestHeader(f,t.headers[f]));let h=(f,e)=>setTimeout(()=>{u.abort(),d({status:0,content:e,isTimedOut:true});},f),R=h(t.connectTimeout,"Connection timeout"),y;u.onreadystatechange=()=>{u.readyState>u.OPENED&&y===undefined&&(clearTimeout(R),y=h(t.responseTimeout,"Socket timeout"));},u.onerror=()=>{u.status===0&&(clearTimeout(R),clearTimeout(y),d({content:u.responseText||"Network request failed",status:u.status,isTimedOut:false}));},u.onload=()=>{clearTimeout(R),clearTimeout(y),d({content:u.responseText,status:u.status,isTimedOut:false});},u.send(t.data);})}return {send:o}}function L(o){let t,d=`algolia-client-js-${o.key}`;function u(){return t===undefined&&(t=o.localStorage||window.localStorage),t}function h(){return JSON.parse(u().getItem(d)||"{}")}function R(f){u().setItem(d,JSON.stringify(f));}function y(){let f=o.timeToLive?o.timeToLive*1e3:null,e=h(),s=Object.fromEntries(Object.entries(e).filter(([,i])=>i.timestamp!==undefined));if(R(s),!f)return;let n=Object.fromEntries(Object.entries(s).filter(([,i])=>{let l=new Date().getTime();return !(i.timestamp+f<l)}));R(n);}return {get(f,e,s={miss:()=>Promise.resolve()}){return Promise.resolve().then(()=>(y(),h()[JSON.stringify(f)])).then(n=>Promise.all([n?n.value:e(),n!==undefined])).then(([n,i])=>Promise.all([n,i||s.miss(n)])).then(([n])=>n)},set(f,e){return Promise.resolve().then(()=>{let s=h();return s[JSON.stringify(f)]={timestamp:new Date().getTime(),value:e},u().setItem(d,JSON.stringify(s)),e})},delete(f){return Promise.resolve().then(()=>{let e=h();delete e[JSON.stringify(f)],u().setItem(d,JSON.stringify(e));})},clear(){return Promise.resolve().then(()=>{u().removeItem(d);})}}}function V(){return {get(o,t,d={miss:()=>Promise.resolve()}){return t().then(h=>Promise.all([h,d.miss(h)])).then(([h])=>h)},set(o,t){return Promise.resolve(t)},delete(o){return Promise.resolve()},clear(){return Promise.resolve()}}}function C(o){let t=[...o.caches],d=t.shift();return d===undefined?V():{get(u,h,R={miss:()=>Promise.resolve()}){return d.get(u,h,R).catch(()=>C({caches:t}).get(u,h,R))},set(u,h){return d.set(u,h).catch(()=>C({caches:t}).set(u,h))},delete(u){return d.delete(u).catch(()=>C({caches:t}).delete(u))},clear(){return d.clear().catch(()=>C({caches:t}).clear())}}}function v(o={serializable:true}){let t={};return {get(d,u,h={miss:()=>Promise.resolve()}){let R=JSON.stringify(d);if(R in t)return Promise.resolve(o.serializable?JSON.parse(t[R]):t[R]);let y=u();return y.then(f=>h.miss(f)).then(()=>y)},set(d,u){return t[JSON.stringify(d)]=o.serializable?JSON.stringify(u):u,Promise.resolve(u)},delete(d){return delete t[JSON.stringify(d)],Promise.resolve()},clear(){return t={},Promise.resolve()}}}function Y(o){let t={value:`Algolia for JavaScript (${o})`,add(d){let u=`; ${d.segment}${d.version!==undefined?` (${d.version})`:""}`;return t.value.indexOf(u)===-1&&(t.value=`${t.value}${u}`),t}};return t}function $(o,t,d="WithinHeaders"){let u={"x-algolia-api-key":t,"x-algolia-application-id":o};return {headers(){return d==="WithinHeaders"?u:{}},queryParameters(){return d==="WithinQueryParameters"?u:{}}}}function j({algoliaAgents:o,client:t,version:d}){let u=Y(d).add({segment:t,version:d});return o.forEach(h=>u.add(h)),u}function W(){return {debug(o,t){return Promise.resolve()},info(o,t){return Promise.resolve()},error(o,t){return Promise.resolve()}}}var U=2*60*1e3;function I(o,t="up"){let d=Date.now();function u(){return t==="up"||Date.now()-d>U}function h(){return t==="timed out"&&Date.now()-d<=U}return {...o,status:t,lastUpdate:d,isUp:u,isTimedOut:h}}var J=class extends Error{name="AlgoliaError";constructor(o,t){super(o),t&&(this.name=t);}},z=class extends J{stackTrace;constructor(o,t,d){super(o,d),this.stackTrace=t;}},Z=class extends z{constructor(o){super("Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",o,"RetryError");}},k=class extends z{status;constructor(o,t,d,u="ApiError"){super(o,d,u),this.status=t;}},ee=class extends J{response;constructor(o,t){super(o,"DeserializationError"),this.response=t;}},te=class extends k{error;constructor(o,t,d,u){super(o,t,u,"DetailedApiError"),this.error=d;}};function re(o,t,d){let u=oe(d),h=`${o.protocol}://${o.url}${o.port?`:${o.port}`:""}/${t.charAt(0)==="/"?t.substring(1):t}`;return u.length&&(h+=`?${u}`),h}function oe(o){return Object.keys(o).filter(t=>o[t]!==undefined).sort().map(t=>`${t}=${encodeURIComponent(Object.prototype.toString.call(o[t])==="[object Array]"?o[t].join(","):o[t]).replace(/\+/g,"%20")}`).join("&")}function se(o,t){if(o.method==="GET"||o.data===undefined&&t.data===undefined)return;let d=Array.isArray(o.data)?o.data:{...o.data,...t.data};return JSON.stringify(d)}function ne(o,t,d){let u={Accept:"application/json",...o,...t,...d},h={};return Object.keys(u).forEach(R=>{let y=u[R];h[R.toLowerCase()]=y;}),h}function ie(o){try{return JSON.parse(o.content)}catch(t){throw new ee(t.message,o)}}function ae({content:o,status:t},d){try{let u=JSON.parse(o);return "error"in u?new te(u.message,t,u.error,d):new k(u.message,t,d)}catch{}return new k(o,t,d)}function ue({isTimedOut:o,status:t}){return !o&&~~t===0}function ce({isTimedOut:o,status:t}){return o||ue({isTimedOut:o,status:t})||~~(t/100)!==2&&~~(t/100)!==4}function de({status:o}){return ~~(o/100)===2}function le(o){return o.map(t=>M(t))}function M(o){let t=o.request.headers["x-algolia-api-key"]?{"x-algolia-api-key":"*****"}:{};return {...o,request:{...o.request,headers:{...o.request.headers,...t}}}}function B({hosts:o,hostsCache:t,baseHeaders:d,logger:u,baseQueryParameters:h,algoliaAgent:R,timeouts:y,requester:f,requestsCache:e,responsesCache:s}){async function n(a){let c=await Promise.all(a.map(P=>t.get(P,()=>Promise.resolve(I(P))))),r=c.filter(P=>P.isUp()),m=c.filter(P=>P.isTimedOut()),p=[...r,...m];return {hosts:p.length>0?p:a,getTimeout(P,S){return (m.length===0&&P===0?1:m.length+3+P)*S}}}async function i(a,c,r=true){let m=[],p=se(a,c),g=ne(d,a.headers,c.headers),P=a.method==="GET"?{...a.data,...c.data}:{},S={...h,...a.queryParameters,...P};if(R.value&&(S["x-algolia-agent"]=R.value),c&&c.queryParameters)for(let T of Object.keys(c.queryParameters))!c.queryParameters[T]||Object.prototype.toString.call(c.queryParameters[T])==="[object Object]"?S[T]=c.queryParameters[T]:S[T]=c.queryParameters[T].toString();let q=0,E=async(T,A)=>{let G=T.pop();if(G===undefined)throw new Z(le(m));let O={...y,...c.timeouts},F={data:p,headers:g,method:a.method,url:re(G,a.path,S),connectTimeout:A(q,O.connect),responseTimeout:A(q,r?O.read:O.write)},D=N=>{let Q={request:F,response:N,host:G,triesLeft:T.length};return m.push(Q),Q},w=await f.send(F);if(ce(w)){let N=D(w);return w.isTimedOut&&q++,u.info("Retryable failure",M(N)),await t.set(G,I(G,w.isTimedOut?"timed out":"down")),E(T,A)}if(de(w))return ie(w);throw D(w),ae(w,m)},K=o.filter(T=>T.accept==="readWrite"||(r?T.accept==="read":T.accept==="write")),H=await n(K);return E([...H.hosts].reverse(),H.getTimeout)}function l(a,c={}){let r=a.useReadTransporter||a.method==="GET";if(!r)return i(a,c,r);let m=()=>i(a,c);if((c.cacheable||a.cacheable)!==true)return m();let g={request:a,requestOptions:c,transporter:{queryParameters:h,headers:d}};return s.get(g,()=>e.get(g,()=>e.set(g,m()).then(P=>Promise.all([e.delete(g),P]),P=>Promise.all([e.delete(g),Promise.reject(P)])).then(([P,S])=>S)),{miss:P=>s.set(g,P)})}return {hostsCache:t,requester:f,timeouts:y,logger:u,algoliaAgent:R,baseHeaders:d,baseQueryParameters:h,hosts:o,request:l,requestsCache:e,responsesCache:s}}var x="5.20.0",b=["de","us"];function fe(o){return [{url:o?"analytics.{region}.algolia.com".replace("{region}",o):"analytics.algolia.com",accept:"readWrite",protocol:"https"}]}function X({appId:o,apiKey:t,authMode:d,algoliaAgents:u,region:h,...R}){let y=$(o,t,d),f=B({hosts:fe(h),...R,algoliaAgent:j({algoliaAgents:u,client:"Analytics",version:x}),baseHeaders:{"content-type":"text/plain",...y.headers(),...R.baseHeaders},baseQueryParameters:{...y.queryParameters(),...R.baseQueryParameters}});return {transporter:f,appId:o,apiKey:t,clearCache(){return Promise.all([f.requestsCache.clear(),f.responsesCache.clear()]).then(()=>{})},get _ua(){return f.algoliaAgent.value},addAlgoliaAgent(e,s){f.algoliaAgent.add({segment:e,version:s});},setClientApiKey({apiKey:e}){!d||d==="WithinHeaders"?f.baseHeaders["x-algolia-api-key"]=e:f.baseQueryParameters["x-algolia-api-key"]=e;},customDelete({path:e,parameters:s},n){if(!e)throw new Error("Parameter `path` is required when calling `customDelete`.");let c={method:"DELETE",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{}};return f.request(c,n)},customGet({path:e,parameters:s},n){if(!e)throw new Error("Parameter `path` is required when calling `customGet`.");let c={method:"GET",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{}};return f.request(c,n)},customPost({path:e,parameters:s,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPost`.");let r={method:"POST",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{},data:n||{}};return f.request(r,i)},customPut({path:e,parameters:s,body:n},i){if(!e)throw new Error("Parameter `path` is required when calling `customPut`.");let r={method:"PUT",path:"/{path}".replace("{path}",e),queryParameters:s||{},headers:{},data:n||{}};return f.request(r,i)},getAddToCartRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getAddToCartRate`.");let a="/2/conversions/addToCartRate",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getAverageClickPosition({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getAverageClickPosition`.");let a="/2/clicks/averageClickPosition",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getClickPositions({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getClickPositions`.");let a="/2/clicks/positions",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getClickThroughRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getClickThroughRate`.");let a="/2/clicks/clickThroughRate",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getConversionRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getConversionRate`.");let a="/2/conversions/conversionRate",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getNoClickRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getNoClickRate`.");let a="/2/searches/noClickRate",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getNoResultsRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getNoResultsRate`.");let a="/2/searches/noResultRate",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getPurchaseRate({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getPurchaseRate`.");let a="/2/conversions/purchaseRate",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getRevenue({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getRevenue`.");let a="/2/conversions/revenue",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getSearchesCount({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesCount`.");let a="/2/searches/count",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)},getSearchesNoClicks({index:e,startDate:s,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoClicks`.");let r="/2/searches/noClicks",m={},p={};e!==undefined&&(p.index=e.toString()),s!==undefined&&(p.startDate=s.toString()),n!==undefined&&(p.endDate=n.toString()),i!==undefined&&(p.limit=i.toString()),l!==undefined&&(p.offset=l.toString()),a!==undefined&&(p.tags=a.toString());let g={method:"GET",path:r,queryParameters:p,headers:m};return f.request(g,c)},getSearchesNoResults({index:e,startDate:s,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getSearchesNoResults`.");let r="/2/searches/noResults",m={},p={};e!==undefined&&(p.index=e.toString()),s!==undefined&&(p.startDate=s.toString()),n!==undefined&&(p.endDate=n.toString()),i!==undefined&&(p.limit=i.toString()),l!==undefined&&(p.offset=l.toString()),a!==undefined&&(p.tags=a.toString());let g={method:"GET",path:r,queryParameters:p,headers:m};return f.request(g,c)},getStatus({index:e},s){if(!e)throw new Error("Parameter `index` is required when calling `getStatus`.");let n="/2/status",i={},l={};e!==undefined&&(l.index=e.toString());let a={method:"GET",path:n,queryParameters:l,headers:i};return f.request(a,s)},getTopCountries({index:e,startDate:s,endDate:n,limit:i,offset:l,tags:a},c){if(!e)throw new Error("Parameter `index` is required when calling `getTopCountries`.");let r="/2/countries",m={},p={};e!==undefined&&(p.index=e.toString()),s!==undefined&&(p.startDate=s.toString()),n!==undefined&&(p.endDate=n.toString()),i!==undefined&&(p.limit=i.toString()),l!==undefined&&(p.offset=l.toString()),a!==undefined&&(p.tags=a.toString());let g={method:"GET",path:r,queryParameters:p,headers:m};return f.request(g,c)},getTopFilterAttributes({index:e,search:s,startDate:n,endDate:i,limit:l,offset:a,tags:c},r){if(!e)throw new Error("Parameter `index` is required when calling `getTopFilterAttributes`.");let m="/2/filters",p={},g={};e!==undefined&&(g.index=e.toString()),s!==undefined&&(g.search=s.toString()),n!==undefined&&(g.startDate=n.toString()),i!==undefined&&(g.endDate=i.toString()),l!==undefined&&(g.limit=l.toString()),a!==undefined&&(g.offset=a.toString()),c!==undefined&&(g.tags=c.toString());let P={method:"GET",path:m,queryParameters:g,headers:p};return f.request(P,r)},getTopFilterForAttribute({attribute:e,index:s,search:n,startDate:i,endDate:l,limit:a,offset:c,tags:r},m){if(!e)throw new Error("Parameter `attribute` is required when calling `getTopFilterForAttribute`.");if(!s)throw new Error("Parameter `index` is required when calling `getTopFilterForAttribute`.");let p="/2/filters/{attribute}".replace("{attribute}",encodeURIComponent(e)),g={},P={};s!==undefined&&(P.index=s.toString()),n!==undefined&&(P.search=n.toString()),i!==undefined&&(P.startDate=i.toString()),l!==undefined&&(P.endDate=l.toString()),a!==undefined&&(P.limit=a.toString()),c!==undefined&&(P.offset=c.toString()),r!==undefined&&(P.tags=r.toString());let S={method:"GET",path:p,queryParameters:P,headers:g};return f.request(S,m)},getTopFiltersNoResults({index:e,search:s,startDate:n,endDate:i,limit:l,offset:a,tags:c},r){if(!e)throw new Error("Parameter `index` is required when calling `getTopFiltersNoResults`.");let m="/2/filters/noResults",p={},g={};e!==undefined&&(g.index=e.toString()),s!==undefined&&(g.search=s.toString()),n!==undefined&&(g.startDate=n.toString()),i!==undefined&&(g.endDate=i.toString()),l!==undefined&&(g.limit=l.toString()),a!==undefined&&(g.offset=a.toString()),c!==undefined&&(g.tags=c.toString());let P={method:"GET",path:m,queryParameters:g,headers:p};return f.request(P,r)},getTopHits({index:e,search:s,clickAnalytics:n,revenueAnalytics:i,startDate:l,endDate:a,limit:c,offset:r,tags:m},p){if(!e)throw new Error("Parameter `index` is required when calling `getTopHits`.");let g="/2/hits",P={},S={};e!==undefined&&(S.index=e.toString()),s!==undefined&&(S.search=s.toString()),n!==undefined&&(S.clickAnalytics=n.toString()),i!==undefined&&(S.revenueAnalytics=i.toString()),l!==undefined&&(S.startDate=l.toString()),a!==undefined&&(S.endDate=a.toString()),c!==undefined&&(S.limit=c.toString()),r!==undefined&&(S.offset=r.toString()),m!==undefined&&(S.tags=m.toString());let q={method:"GET",path:g,queryParameters:S,headers:P};return f.request(q,p)},getTopSearches({index:e,clickAnalytics:s,revenueAnalytics:n,startDate:i,endDate:l,orderBy:a,direction:c,limit:r,offset:m,tags:p},g){if(!e)throw new Error("Parameter `index` is required when calling `getTopSearches`.");let P="/2/searches",S={},q={};e!==undefined&&(q.index=e.toString()),s!==undefined&&(q.clickAnalytics=s.toString()),n!==undefined&&(q.revenueAnalytics=n.toString()),i!==undefined&&(q.startDate=i.toString()),l!==undefined&&(q.endDate=l.toString()),a!==undefined&&(q.orderBy=a.toString()),c!==undefined&&(q.direction=c.toString()),r!==undefined&&(q.limit=r.toString()),m!==undefined&&(q.offset=m.toString()),p!==undefined&&(q.tags=p.toString());let E={method:"GET",path:P,queryParameters:q,headers:S};return f.request(E,g)},getUsersCount({index:e,startDate:s,endDate:n,tags:i},l){if(!e)throw new Error("Parameter `index` is required when calling `getUsersCount`.");let a="/2/users/count",c={},r={};e!==undefined&&(r.index=e.toString()),s!==undefined&&(r.startDate=s.toString()),n!==undefined&&(r.endDate=n.toString()),i!==undefined&&(r.tags=i.toString());let m={method:"GET",path:a,queryParameters:r,headers:c};return f.request(m,l)}}}function At(o,t,d,u){if(!o||typeof o!="string")throw new Error("`appId` is missing.");if(!t||typeof t!="string")throw new Error("`apiKey` is missing.");if(d&&(typeof d!="string"||!b.includes(d)))throw new Error(`\`region\` must be one of the following: ${b.join(", ")}`);return X({appId:o,apiKey:t,region:d,timeouts:{connect:1e3,read:2e3,write:3e4},logger:W(),requester:_(),algoliaAgents:[{segment:"Browser"}],authMode:"WithinQueryParameters",responsesCache:v(),requestsCache:v({serializable:false}),hostsCache:C({caches:[L({key:`${x}-${o}`}),v()]}),...u})}
|
|
8
8
|
|
|
9
9
|
exports.analyticsClient = At;
|
|
10
10
|
exports.apiClientVersion = x;
|
package/dist/builds/fetch.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createFetchRequester } from "@algolia/requester-fetch";
|
|
|
4
4
|
|
|
5
5
|
// src/analyticsClient.ts
|
|
6
6
|
import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
|
|
7
|
-
var apiClientVersion = "5.
|
|
7
|
+
var apiClientVersion = "5.20.0";
|
|
8
8
|
var REGIONS = ["de", "us"];
|
|
9
9
|
function getDefaultHosts(region) {
|
|
10
10
|
const url = !region ? "analytics.algolia.com" : "analytics.{region}.algolia.com".replace("{region}", region);
|
|
@@ -174,7 +174,7 @@ function createAnalyticsClient({
|
|
|
174
174
|
return transporter.request(request, requestOptions);
|
|
175
175
|
},
|
|
176
176
|
/**
|
|
177
|
-
* Retrieves the add-to-cart rate for all
|
|
177
|
+
* Retrieves the add-to-cart rate for all your searches with at least one add-to-cart event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day. The rate is the number of add-to-cart conversion events divided by the number of tracked searches. A search is tracked if it returns a queryID (`clickAnalytics` is `true`). This differs from the response\'s `count`, which shows the overall number of searches, including those where `clickAnalytics` is `false`. **There\'s a difference between a 0 and null add-to-cart rate when `clickAnalytics` is enabled:** - **Null** means there were no queries: since Algolia didn\'t receive any events, the add-to-cart rate is null. - **0** mean there _were_ queries but no [add-to-cart events](https://www.algolia.com/doc/guides/sending-events/getting-started/) were received.
|
|
178
178
|
*
|
|
179
179
|
* Required API Key ACLs:
|
|
180
180
|
* - analytics
|
|
@@ -213,7 +213,7 @@ function createAnalyticsClient({
|
|
|
213
213
|
return transporter.request(request, requestOptions);
|
|
214
214
|
},
|
|
215
215
|
/**
|
|
216
|
-
* Retrieves the average click position of your search results, including a daily breakdown. The average click position is the average of all clicked search
|
|
216
|
+
* Retrieves the average click position of your search results, including a daily breakdown. The average click position is the average of all clicked search result positions. For example, if users only ever click on the first result for any search, the average click position is 1. By default, the analyzed period includes the last eight days including the current day. An average of `null` when `clickAnalytics` is enabled means Algolia didn\'t receive any [click events](https://www.algolia.com/doc/guides/sending-events/getting-started/) for the queries. The average is `null` until Algolia receives at least one click event.
|
|
217
217
|
*
|
|
218
218
|
* Required API Key ACLs:
|
|
219
219
|
* - analytics
|
|
@@ -252,7 +252,7 @@ function createAnalyticsClient({
|
|
|
252
252
|
return transporter.request(request, requestOptions);
|
|
253
253
|
},
|
|
254
254
|
/**
|
|
255
|
-
* Retrieves the positions in the search results and their associated number of clicks. This lets you check how many clicks the first, second, or tenth search results receive.
|
|
255
|
+
* Retrieves the positions in the search results and their associated number of clicks. This lets you check how many clicks the first, second, or tenth search results receive. An average of `0` when `clickAnalytics` is enabled means Algolia didn\'t receive any [click events](https://www.algolia.com/doc/guides/sending-events/getting-started/) for the queries.
|
|
256
256
|
*
|
|
257
257
|
* Required API Key ACLs:
|
|
258
258
|
* - analytics
|
|
@@ -291,7 +291,7 @@ function createAnalyticsClient({
|
|
|
291
291
|
return transporter.request(request, requestOptions);
|
|
292
292
|
},
|
|
293
293
|
/**
|
|
294
|
-
* Retrieves the click-through rate for all
|
|
294
|
+
* Retrieves the click-through rate (CTR) for all your searches with at least one click event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day. **There\'s a difference between a 0 and null CTR when `clickAnalytics` is enabled:** - **Null** means there were no queries: since Algolia didn\'t receive any events, CTR is null. - **0** mean there _were_ queries but no [click events](https://www.algolia.com/doc/guides/sending-events/getting-started/) were received.
|
|
295
295
|
*
|
|
296
296
|
* Required API Key ACLs:
|
|
297
297
|
* - analytics
|
|
@@ -330,7 +330,7 @@ function createAnalyticsClient({
|
|
|
330
330
|
return transporter.request(request, requestOptions);
|
|
331
331
|
},
|
|
332
332
|
/**
|
|
333
|
-
* Retrieves the conversion rate for all
|
|
333
|
+
* Retrieves the conversion rate (CR) for all your searches with at least one conversion event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day. **There\'s a difference between a 0 and null CR when `clickAnalytics` is enabled:** - **Null** means there were no queries: since Algolia didn\'t receive any events, CR is null. - **0** mean there _were_ queries but no [conversion events](https://www.algolia.com/doc/guides/sending-events/getting-started/) were received.
|
|
334
334
|
*
|
|
335
335
|
* Required API Key ACLs:
|
|
336
336
|
* - analytics
|
|
@@ -369,7 +369,7 @@ function createAnalyticsClient({
|
|
|
369
369
|
return transporter.request(request, requestOptions);
|
|
370
370
|
},
|
|
371
371
|
/**
|
|
372
|
-
* Retrieves the fraction of searches that didn\'t lead to any click within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
|
|
372
|
+
* Retrieves the fraction of searches that didn\'t lead to any click within a time range, including a daily breakdown. It also returns the number of tracked searches and tracked searches without clicks. By default, the analyzed period includes the last eight days including the current day.
|
|
373
373
|
*
|
|
374
374
|
* Required API Key ACLs:
|
|
375
375
|
* - analytics
|
|
@@ -408,7 +408,7 @@ function createAnalyticsClient({
|
|
|
408
408
|
return transporter.request(request, requestOptions);
|
|
409
409
|
},
|
|
410
410
|
/**
|
|
411
|
-
* Retrieves the fraction of searches that didn\'t return any results within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
|
|
411
|
+
* Retrieves the fraction of searches that didn\'t return any results within a time range, including a daily breakdown. It also returns the count of searches and searches without results used to compute the rates. By default, the analyzed period includes the last eight days including the current day.
|
|
412
412
|
*
|
|
413
413
|
* Required API Key ACLs:
|
|
414
414
|
* - analytics
|
|
@@ -447,7 +447,7 @@ function createAnalyticsClient({
|
|
|
447
447
|
return transporter.request(request, requestOptions);
|
|
448
448
|
},
|
|
449
449
|
/**
|
|
450
|
-
* Retrieves the purchase rate for all
|
|
450
|
+
* Retrieves the purchase rate for all your searches with at least one purchase event, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day. The rate is the number of purchase conversion events divided by the number of tracked searches. A search is tracked if it returns a query ID (`clickAnalytics` is `true`). This differs from the response\'s `count`, which shows the overall number of searches, including those where `clickAnalytics` is `false`. **There\'s a difference between a 0 and null purchase rate when `clickAnalytics` is enabled:** - **Null** means there were no queries: since Algolia didn\'t receive any events, the purchase rate is null. - **0** mean there _were_ queries but no [purchase conversion events](https://www.algolia.com/doc/guides/sending-events/getting-started/) were received.
|
|
451
451
|
*
|
|
452
452
|
* Required API Key ACLs:
|
|
453
453
|
* - analytics
|
|
@@ -486,7 +486,7 @@ function createAnalyticsClient({
|
|
|
486
486
|
return transporter.request(request, requestOptions);
|
|
487
487
|
},
|
|
488
488
|
/**
|
|
489
|
-
* Retrieves revenue-related metrics, such as the total revenue or the average order value. To retrieve revenue-related metrics,
|
|
489
|
+
* Retrieves revenue-related metrics, such as the total revenue or the average order value. To retrieve revenue-related metrics, send purchase events. By default, the analyzed period includes the last eight days including the current day. Revenue is based on purchase conversion events (a conversion event with an `eventSubtype` attribute of `purchase`). The revenue is the `price` attribute multiplied by the `quantity` attribute for each object in the event\'s `objectData` array.
|
|
490
490
|
*
|
|
491
491
|
* Required API Key ACLs:
|
|
492
492
|
* - analytics
|
|
@@ -564,7 +564,7 @@ function createAnalyticsClient({
|
|
|
564
564
|
return transporter.request(request, requestOptions);
|
|
565
565
|
},
|
|
566
566
|
/**
|
|
567
|
-
* Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
|
|
567
|
+
* Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches. For each search, it also returns the number of displayed search results that remained unclicked.
|
|
568
568
|
*
|
|
569
569
|
* Required API Key ACLs:
|
|
570
570
|
* - analytics
|
|
@@ -611,7 +611,7 @@ function createAnalyticsClient({
|
|
|
611
611
|
return transporter.request(request, requestOptions);
|
|
612
612
|
},
|
|
613
613
|
/**
|
|
614
|
-
* Retrieves the most
|
|
614
|
+
* Retrieves the 1,000 most frequent searches that produced zero results.
|
|
615
615
|
*
|
|
616
616
|
* Required API Key ACLs:
|
|
617
617
|
* - analytics
|
|
@@ -658,7 +658,7 @@ function createAnalyticsClient({
|
|
|
658
658
|
return transporter.request(request, requestOptions);
|
|
659
659
|
},
|
|
660
660
|
/**
|
|
661
|
-
* Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5
|
|
661
|
+
* Retrieves the time when the Analytics data for the specified index was last updated. If the index has been recently created or no search has been performed yet the updated time is `null`. The Analytics data is updated every 5 minutes.
|
|
662
662
|
*
|
|
663
663
|
* Required API Key ACLs:
|
|
664
664
|
* - analytics
|
|
@@ -685,7 +685,7 @@ function createAnalyticsClient({
|
|
|
685
685
|
return transporter.request(request, requestOptions);
|
|
686
686
|
},
|
|
687
687
|
/**
|
|
688
|
-
* Retrieves the countries with the most searches
|
|
688
|
+
* Retrieves the countries with the most searches in your index.
|
|
689
689
|
*
|
|
690
690
|
* Required API Key ACLs:
|
|
691
691
|
* - analytics
|
|
@@ -732,7 +732,7 @@ function createAnalyticsClient({
|
|
|
732
732
|
return transporter.request(request, requestOptions);
|
|
733
733
|
},
|
|
734
734
|
/**
|
|
735
|
-
* Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
|
|
735
|
+
* Retrieves the 1,000 most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
|
|
736
736
|
*
|
|
737
737
|
* Required API Key ACLs:
|
|
738
738
|
* - analytics
|
|
@@ -783,7 +783,7 @@ function createAnalyticsClient({
|
|
|
783
783
|
return transporter.request(request, requestOptions);
|
|
784
784
|
},
|
|
785
785
|
/**
|
|
786
|
-
* Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
|
|
786
|
+
* Retrieves the 1,000 most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
|
|
787
787
|
*
|
|
788
788
|
* Required API Key ACLs:
|
|
789
789
|
* - analytics
|
|
@@ -838,7 +838,7 @@ function createAnalyticsClient({
|
|
|
838
838
|
return transporter.request(request, requestOptions);
|
|
839
839
|
},
|
|
840
840
|
/**
|
|
841
|
-
* Retrieves the most frequently used filters for a search that didn\'t return any results. To get the most frequent searches without results, use the [Retrieve searches without results](#tag/search/operation/getSearchesNoResults) operation.
|
|
841
|
+
* Retrieves the 1,000 most frequently used filters for a search that didn\'t return any results. To get the most frequent searches without results, use the [Retrieve searches without results](#tag/search/operation/getSearchesNoResults) operation.
|
|
842
842
|
*
|
|
843
843
|
* Required API Key ACLs:
|
|
844
844
|
* - analytics
|
|
@@ -889,7 +889,7 @@ function createAnalyticsClient({
|
|
|
889
889
|
return transporter.request(request, requestOptions);
|
|
890
890
|
},
|
|
891
891
|
/**
|
|
892
|
-
* Retrieves the object IDs of the most frequent search results.
|
|
892
|
+
* Retrieves the object IDs of the 1,000 most frequent search results. If you set the `clickAnalytics` query parameter to true, the response also includes: - Tracked searches count. Tracked searches are Search API requests with the `clickAnalytics` parameter set to `true`. This differs from the response\'s `count`, which shows the overall number of searches, including those where `clickAnalytics` is `false`. - Click count - Click-through rate (CTR) - Conversion count - Conversion rate (CR) - Average click position If you set the `revenueAnalytics` parameter to `true`, the response also includes: - Add-to-cart count - Add-to-cart rate (ATCR) - Purchase count - Purchase rate - Revenue details for each currency **There\'s a difference between 0% rates and null rates:** - **Null** means there were no queries: since Algolia didn\'t receive any events, the rates (CTR, CR, ATCR, purchase rate) are null. - **0% rates** mean there _were_ queries but no [click or conversion events](https://www.algolia.com/doc/guides/sending-events/getting-started/) were received.
|
|
893
893
|
*
|
|
894
894
|
* Required API Key ACLs:
|
|
895
895
|
* - analytics
|
|
@@ -897,7 +897,7 @@ function createAnalyticsClient({
|
|
|
897
897
|
* @param getTopHits.index - Index name.
|
|
898
898
|
* @param getTopHits.search - Search query.
|
|
899
899
|
* @param getTopHits.clickAnalytics - Whether to include metrics related to click and conversion events in the response.
|
|
900
|
-
* @param getTopHits.revenueAnalytics - Whether to include
|
|
900
|
+
* @param getTopHits.revenueAnalytics - Whether to include metrics related to revenue events in the response.
|
|
901
901
|
* @param getTopHits.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
|
|
902
902
|
* @param getTopHits.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
|
|
903
903
|
* @param getTopHits.limit - Number of items to return.
|
|
@@ -948,14 +948,14 @@ function createAnalyticsClient({
|
|
|
948
948
|
return transporter.request(request, requestOptions);
|
|
949
949
|
},
|
|
950
950
|
/**
|
|
951
|
-
* Returns the most popular search
|
|
951
|
+
* Returns the most popular searches. For each search, it also includes the average number of hits. If you set the `clickAnalytics` query parameter to `true`, the response also includes - Tracked searches count. Tracked searches are Search API requests with the `clickAnalytics` parameter set to `true`. This differs from the response\'s `count`, which shows the overall number of searches, including those where `clickAnalytics` is `false`. - Click count - Click-through rate (CTR) - Conversion count - Conversion rate (CR) - Average click position If you set the `revenueAnalytics` query parameter to `true`, the response also includes: - Add-to-cart count - Add-to-cart rate (ATCR) - Purchase count - Purchase rate - Revenue details for each currency **There\'s a difference between 0% rates and null rates:** - **Null** means there were no queries: since Algolia didn\'t receive any events, the rates (CTR, CR, ATCR, purchase rate) are null. - **0% rates** mean there _were_ queries but no [click or conversion events](https://www.algolia.com/doc/guides/sending-events/getting-started/) were received.
|
|
952
952
|
*
|
|
953
953
|
* Required API Key ACLs:
|
|
954
954
|
* - analytics
|
|
955
955
|
* @param getTopSearches - The getTopSearches object.
|
|
956
956
|
* @param getTopSearches.index - Index name.
|
|
957
957
|
* @param getTopSearches.clickAnalytics - Whether to include metrics related to click and conversion events in the response.
|
|
958
|
-
* @param getTopSearches.revenueAnalytics - Whether to include
|
|
958
|
+
* @param getTopSearches.revenueAnalytics - Whether to include metrics related to revenue events in the response.
|
|
959
959
|
* @param getTopSearches.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
|
|
960
960
|
* @param getTopSearches.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
|
|
961
961
|
* @param getTopSearches.orderBy - Attribute by which to order the response items. If the `clickAnalytics` parameter is false, only `searchCount` is available.
|
|
@@ -1022,7 +1022,7 @@ function createAnalyticsClient({
|
|
|
1022
1022
|
return transporter.request(request, requestOptions);
|
|
1023
1023
|
},
|
|
1024
1024
|
/**
|
|
1025
|
-
* Retrieves the number of unique users within a time range, including a daily breakdown. Since
|
|
1025
|
+
* Retrieves the number of unique users within a time range, including a daily breakdown. Since it returns the number of unique users, the sum of the daily values might be different from the total number. By default: - Algolia distinguishes search users by their IP address, _unless_ you include a pseudonymous user identifier in your search requests with the `userToken` API parameter or `x-algolia-usertoken` request header. - The analyzed period includes the last eight days including the current day.
|
|
1026
1026
|
*
|
|
1027
1027
|
* Required API Key ACLs:
|
|
1028
1028
|
* - analytics
|