@algolia/client-analytics 5.2.4 → 5.2.5

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.
Files changed (142) hide show
  1. package/dist/browser.d.ts +1399 -0
  2. package/dist/builds/browser.js +1115 -0
  3. package/dist/builds/browser.js.map +1 -0
  4. package/dist/builds/browser.min.js +2 -0
  5. package/dist/builds/browser.min.js.map +1 -0
  6. package/dist/builds/browser.umd.js +12 -0
  7. package/dist/builds/node.cjs +1133 -0
  8. package/dist/builds/node.cjs.map +1 -0
  9. package/dist/builds/node.js +1113 -0
  10. package/dist/builds/node.js.map +1 -0
  11. package/dist/node.d.cts +1399 -0
  12. package/dist/node.d.ts +1399 -0
  13. package/dist/src/analyticsClient.cjs +1100 -0
  14. package/dist/src/analyticsClient.cjs.map +1 -0
  15. package/dist/src/{analyticsClient.d.ts → analyticsClient.js} +739 -58
  16. package/dist/src/analyticsClient.js.map +1 -0
  17. package/index.d.ts +1 -1
  18. package/index.js +1 -1
  19. package/package.json +28 -25
  20. package/dist/builds/browser.d.ts +0 -40
  21. package/dist/builds/browser.d.ts.map +0 -1
  22. package/dist/builds/node.d.ts +0 -40
  23. package/dist/builds/node.d.ts.map +0 -1
  24. package/dist/client-analytics.cjs +0 -1089
  25. package/dist/client-analytics.esm.browser.js +0 -1763
  26. package/dist/client-analytics.esm.node.js +0 -1086
  27. package/dist/client-analytics.umd.js +0 -2
  28. package/dist/model/clickPosition.d.ts +0 -14
  29. package/dist/model/clickPosition.d.ts.map +0 -1
  30. package/dist/model/clientMethodProps.d.ts +0 -579
  31. package/dist/model/clientMethodProps.d.ts.map +0 -1
  32. package/dist/model/currencyCode.d.ts +0 -14
  33. package/dist/model/currencyCode.d.ts.map +0 -1
  34. package/dist/model/dailyAddToCartRates.d.ts +0 -19
  35. package/dist/model/dailyAddToCartRates.d.ts.map +0 -1
  36. package/dist/model/dailyAverageClicks.d.ts +0 -15
  37. package/dist/model/dailyAverageClicks.d.ts.map +0 -1
  38. package/dist/model/dailyClickThroughRates.d.ts +0 -19
  39. package/dist/model/dailyClickThroughRates.d.ts.map +0 -1
  40. package/dist/model/dailyConversionRates.d.ts +0 -19
  41. package/dist/model/dailyConversionRates.d.ts.map +0 -1
  42. package/dist/model/dailyNoClickRates.d.ts +0 -19
  43. package/dist/model/dailyNoClickRates.d.ts.map +0 -1
  44. package/dist/model/dailyNoResultsRates.d.ts +0 -19
  45. package/dist/model/dailyNoResultsRates.d.ts.map +0 -1
  46. package/dist/model/dailyPurchaseRates.d.ts +0 -19
  47. package/dist/model/dailyPurchaseRates.d.ts.map +0 -1
  48. package/dist/model/dailyRevenue.d.ts +0 -12
  49. package/dist/model/dailyRevenue.d.ts.map +0 -1
  50. package/dist/model/dailySearches.d.ts +0 -11
  51. package/dist/model/dailySearches.d.ts.map +0 -1
  52. package/dist/model/dailySearchesNoClicks.d.ts +0 -15
  53. package/dist/model/dailySearchesNoClicks.d.ts.map +0 -1
  54. package/dist/model/dailySearchesNoResults.d.ts +0 -15
  55. package/dist/model/dailySearchesNoResults.d.ts.map +0 -1
  56. package/dist/model/dailyUsers.d.ts +0 -11
  57. package/dist/model/dailyUsers.d.ts.map +0 -1
  58. package/dist/model/direction.d.ts +0 -2
  59. package/dist/model/direction.d.ts.map +0 -1
  60. package/dist/model/errorBase.d.ts +0 -7
  61. package/dist/model/errorBase.d.ts.map +0 -1
  62. package/dist/model/getAddToCartRateResponse.d.ts +0 -20
  63. package/dist/model/getAddToCartRateResponse.d.ts.map +0 -1
  64. package/dist/model/getAverageClickPositionResponse.d.ts +0 -16
  65. package/dist/model/getAverageClickPositionResponse.d.ts.map +0 -1
  66. package/dist/model/getClickPositionsResponse.d.ts +0 -8
  67. package/dist/model/getClickPositionsResponse.d.ts.map +0 -1
  68. package/dist/model/getClickThroughRateResponse.d.ts +0 -20
  69. package/dist/model/getClickThroughRateResponse.d.ts.map +0 -1
  70. package/dist/model/getConversionRateResponse.d.ts +0 -20
  71. package/dist/model/getConversionRateResponse.d.ts.map +0 -1
  72. package/dist/model/getNoClickRateResponse.d.ts +0 -20
  73. package/dist/model/getNoClickRateResponse.d.ts.map +0 -1
  74. package/dist/model/getNoResultsRateResponse.d.ts +0 -20
  75. package/dist/model/getNoResultsRateResponse.d.ts.map +0 -1
  76. package/dist/model/getPurchaseRateResponse.d.ts +0 -20
  77. package/dist/model/getPurchaseRateResponse.d.ts.map +0 -1
  78. package/dist/model/getRevenue.d.ts +0 -13
  79. package/dist/model/getRevenue.d.ts.map +0 -1
  80. package/dist/model/getSearchesCountResponse.d.ts +0 -12
  81. package/dist/model/getSearchesCountResponse.d.ts.map +0 -1
  82. package/dist/model/getSearchesNoClicksResponse.d.ts +0 -8
  83. package/dist/model/getSearchesNoClicksResponse.d.ts.map +0 -1
  84. package/dist/model/getSearchesNoResultsResponse.d.ts +0 -8
  85. package/dist/model/getSearchesNoResultsResponse.d.ts.map +0 -1
  86. package/dist/model/getStatusResponse.d.ts +0 -7
  87. package/dist/model/getStatusResponse.d.ts.map +0 -1
  88. package/dist/model/getTopCountriesResponse.d.ts +0 -8
  89. package/dist/model/getTopCountriesResponse.d.ts.map +0 -1
  90. package/dist/model/getTopFilterAttribute.d.ts +0 -11
  91. package/dist/model/getTopFilterAttribute.d.ts.map +0 -1
  92. package/dist/model/getTopFilterAttributesResponse.d.ts +0 -8
  93. package/dist/model/getTopFilterAttributesResponse.d.ts.map +0 -1
  94. package/dist/model/getTopFilterForAttribute.d.ts +0 -17
  95. package/dist/model/getTopFilterForAttribute.d.ts.map +0 -1
  96. package/dist/model/getTopFilterForAttributeResponse.d.ts +0 -8
  97. package/dist/model/getTopFilterForAttributeResponse.d.ts.map +0 -1
  98. package/dist/model/getTopFiltersNoResultsResponse.d.ts +0 -8
  99. package/dist/model/getTopFiltersNoResultsResponse.d.ts.map +0 -1
  100. package/dist/model/getTopFiltersNoResultsValue.d.ts +0 -13
  101. package/dist/model/getTopFiltersNoResultsValue.d.ts.map +0 -1
  102. package/dist/model/getTopFiltersNoResultsValues.d.ts +0 -12
  103. package/dist/model/getTopFiltersNoResultsValues.d.ts.map +0 -1
  104. package/dist/model/getTopHitsResponse.d.ts +0 -5
  105. package/dist/model/getTopHitsResponse.d.ts.map +0 -1
  106. package/dist/model/getTopSearchesResponse.d.ts +0 -5
  107. package/dist/model/getTopSearchesResponse.d.ts.map +0 -1
  108. package/dist/model/getUsersCountResponse.d.ts +0 -12
  109. package/dist/model/getUsersCountResponse.d.ts.map +0 -1
  110. package/dist/model/index.d.ts +0 -57
  111. package/dist/model/index.d.ts.map +0 -1
  112. package/dist/model/operator.d.ts +0 -5
  113. package/dist/model/operator.d.ts.map +0 -1
  114. package/dist/model/orderBy.d.ts +0 -5
  115. package/dist/model/orderBy.d.ts.map +0 -1
  116. package/dist/model/topCountry.d.ts +0 -11
  117. package/dist/model/topCountry.d.ts.map +0 -1
  118. package/dist/model/topHit.d.ts +0 -11
  119. package/dist/model/topHit.d.ts.map +0 -1
  120. package/dist/model/topHitWithAnalytics.d.ts +0 -31
  121. package/dist/model/topHitWithAnalytics.d.ts.map +0 -1
  122. package/dist/model/topHitWithRevenueAnalytics.d.ts +0 -52
  123. package/dist/model/topHitWithRevenueAnalytics.d.ts.map +0 -1
  124. package/dist/model/topHitsResponse.d.ts +0 -8
  125. package/dist/model/topHitsResponse.d.ts.map +0 -1
  126. package/dist/model/topHitsResponseWithAnalytics.d.ts +0 -8
  127. package/dist/model/topHitsResponseWithAnalytics.d.ts.map +0 -1
  128. package/dist/model/topHitsResponseWithRevenueAnalytics.d.ts +0 -8
  129. package/dist/model/topHitsResponseWithRevenueAnalytics.d.ts.map +0 -1
  130. package/dist/model/topSearch.d.ts +0 -15
  131. package/dist/model/topSearch.d.ts.map +0 -1
  132. package/dist/model/topSearchWithAnalytics.d.ts +0 -44
  133. package/dist/model/topSearchWithAnalytics.d.ts.map +0 -1
  134. package/dist/model/topSearchWithRevenueAnalytics.d.ts +0 -65
  135. package/dist/model/topSearchWithRevenueAnalytics.d.ts.map +0 -1
  136. package/dist/model/topSearchesResponse.d.ts +0 -8
  137. package/dist/model/topSearchesResponse.d.ts.map +0 -1
  138. package/dist/model/topSearchesResponseWithAnalytics.d.ts +0 -8
  139. package/dist/model/topSearchesResponseWithAnalytics.d.ts.map +0 -1
  140. package/dist/model/topSearchesResponseWithRevenueAnalytics.d.ts +0 -8
  141. package/dist/model/topSearchesResponseWithRevenueAnalytics.d.ts.map +0 -1
  142. package/dist/src/analyticsClient.d.ts.map +0 -1
@@ -1,1763 +0,0 @@
1
- function createAuth(appId, apiKey, authMode = 'WithinHeaders') {
2
- const credentials = {
3
- 'x-algolia-api-key': apiKey,
4
- 'x-algolia-application-id': appId
5
- };
6
- return {
7
- headers() {
8
- return authMode === 'WithinHeaders' ? credentials : {};
9
- },
10
- queryParameters() {
11
- return authMode === 'WithinQueryParameters' ? credentials : {};
12
- }
13
- };
14
- }
15
-
16
- function createBrowserLocalStorageCache(options) {
17
- let storage;
18
- // We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change
19
- const namespaceKey = `algolia-client-js-${options.key}`;
20
- function getStorage() {
21
- if (storage === undefined) {
22
- storage = options.localStorage || window.localStorage;
23
- }
24
- return storage;
25
- }
26
- function getNamespace() {
27
- return JSON.parse(getStorage().getItem(namespaceKey) || '{}');
28
- }
29
- function setNamespace(namespace) {
30
- getStorage().setItem(namespaceKey, JSON.stringify(namespace));
31
- }
32
- function removeOutdatedCacheItems() {
33
- const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;
34
- const namespace = getNamespace();
35
- const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(Object.entries(namespace).filter(([, cacheItem]) => {
36
- return cacheItem.timestamp !== undefined;
37
- }));
38
- setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);
39
- if (!timeToLive) {
40
- return;
41
- }
42
- const filteredNamespaceWithoutExpiredItems = Object.fromEntries(Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
43
- const currentTimestamp = new Date().getTime();
44
- const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
45
- return !isExpired;
46
- }));
47
- setNamespace(filteredNamespaceWithoutExpiredItems);
48
- }
49
- return {
50
- get(key, defaultValue, events = {
51
- miss: () => Promise.resolve()
52
- }) {
53
- return Promise.resolve().then(() => {
54
- removeOutdatedCacheItems();
55
- return getNamespace()[JSON.stringify(key)];
56
- }).then(value => {
57
- return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
58
- }).then(([value, exists]) => {
59
- return Promise.all([value, exists || events.miss(value)]);
60
- }).then(([value]) => value);
61
- },
62
- set(key, value) {
63
- return Promise.resolve().then(() => {
64
- const namespace = getNamespace();
65
- namespace[JSON.stringify(key)] = {
66
- timestamp: new Date().getTime(),
67
- value
68
- };
69
- getStorage().setItem(namespaceKey, JSON.stringify(namespace));
70
- return value;
71
- });
72
- },
73
- delete(key) {
74
- return Promise.resolve().then(() => {
75
- const namespace = getNamespace();
76
- delete namespace[JSON.stringify(key)];
77
- getStorage().setItem(namespaceKey, JSON.stringify(namespace));
78
- });
79
- },
80
- clear() {
81
- return Promise.resolve().then(() => {
82
- getStorage().removeItem(namespaceKey);
83
- });
84
- }
85
- };
86
- }
87
-
88
- function createNullCache() {
89
- return {
90
- get(_key, defaultValue, events = {
91
- miss: () => Promise.resolve()
92
- }) {
93
- const value = defaultValue();
94
- return value.then(result => Promise.all([result, events.miss(result)])).then(([result]) => result);
95
- },
96
- set(_key, value) {
97
- return Promise.resolve(value);
98
- },
99
- delete(_key) {
100
- return Promise.resolve();
101
- },
102
- clear() {
103
- return Promise.resolve();
104
- }
105
- };
106
- }
107
-
108
- function createFallbackableCache(options) {
109
- const caches = [...options.caches];
110
- const current = caches.shift();
111
- if (current === undefined) {
112
- return createNullCache();
113
- }
114
- return {
115
- get(key, defaultValue, events = {
116
- miss: () => Promise.resolve()
117
- }) {
118
- return current.get(key, defaultValue, events).catch(() => {
119
- return createFallbackableCache({
120
- caches
121
- }).get(key, defaultValue, events);
122
- });
123
- },
124
- set(key, value) {
125
- return current.set(key, value).catch(() => {
126
- return createFallbackableCache({
127
- caches
128
- }).set(key, value);
129
- });
130
- },
131
- delete(key) {
132
- return current.delete(key).catch(() => {
133
- return createFallbackableCache({
134
- caches
135
- }).delete(key);
136
- });
137
- },
138
- clear() {
139
- return current.clear().catch(() => {
140
- return createFallbackableCache({
141
- caches
142
- }).clear();
143
- });
144
- }
145
- };
146
- }
147
-
148
- function createMemoryCache(options = {
149
- serializable: true
150
- }) {
151
- let cache = {};
152
- return {
153
- get(key, defaultValue, events = {
154
- miss: () => Promise.resolve()
155
- }) {
156
- const keyAsString = JSON.stringify(key);
157
- if (keyAsString in cache) {
158
- return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
159
- }
160
- const promise = defaultValue();
161
- return promise.then(value => events.miss(value)).then(() => promise);
162
- },
163
- set(key, value) {
164
- cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;
165
- return Promise.resolve(value);
166
- },
167
- delete(key) {
168
- delete cache[JSON.stringify(key)];
169
- return Promise.resolve();
170
- },
171
- clear() {
172
- cache = {};
173
- return Promise.resolve();
174
- }
175
- };
176
- }
177
-
178
- // By default, API Clients at Algolia have expiration delay of 5 mins.
179
- // In the JavaScript client, we have 2 mins.
180
- const EXPIRATION_DELAY = 2 * 60 * 1000;
181
- function createStatefulHost(host, status = 'up') {
182
- const lastUpdate = Date.now();
183
- function isUp() {
184
- return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;
185
- }
186
- function isTimedOut() {
187
- return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
188
- }
189
- return {
190
- ...host,
191
- status,
192
- lastUpdate,
193
- isUp,
194
- isTimedOut
195
- };
196
- }
197
-
198
- function _defineProperty(e, r, t) {
199
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
200
- value: t,
201
- enumerable: !0,
202
- configurable: !0,
203
- writable: !0
204
- }) : e[r] = t, e;
205
- }
206
- function _toPrimitive(t, r) {
207
- if ("object" != typeof t || !t) return t;
208
- var e = t[Symbol.toPrimitive];
209
- if (void 0 !== e) {
210
- var i = e.call(t, r || "default");
211
- if ("object" != typeof i) return i;
212
- throw new TypeError("@@toPrimitive must return a primitive value.");
213
- }
214
- return ("string" === r ? String : Number)(t);
215
- }
216
- function _toPropertyKey(t) {
217
- var i = _toPrimitive(t, "string");
218
- return "symbol" == typeof i ? i : i + "";
219
- }
220
-
221
- class AlgoliaError extends Error {
222
- constructor(message, name) {
223
- super(message);
224
- _defineProperty(this, "name", 'AlgoliaError');
225
- if (name) {
226
- this.name = name;
227
- }
228
- }
229
- }
230
- class ErrorWithStackTrace extends AlgoliaError {
231
- constructor(message, stackTrace, name) {
232
- super(message, name);
233
- // the array and object should be frozen to reflect the stackTrace at the time of the error
234
- _defineProperty(this, "stackTrace", void 0);
235
- this.stackTrace = stackTrace;
236
- }
237
- }
238
- class RetryError extends ErrorWithStackTrace {
239
- constructor(stackTrace) {
240
- 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.', stackTrace, 'RetryError');
241
- }
242
- }
243
- class ApiError extends ErrorWithStackTrace {
244
- constructor(message, status, stackTrace, name = 'ApiError') {
245
- super(message, stackTrace, name);
246
- _defineProperty(this, "status", void 0);
247
- this.status = status;
248
- }
249
- }
250
- class DeserializationError extends AlgoliaError {
251
- constructor(message, response) {
252
- super(message, 'DeserializationError');
253
- _defineProperty(this, "response", void 0);
254
- this.response = response;
255
- }
256
- }
257
- // DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.
258
- class DetailedApiError extends ApiError {
259
- constructor(message, status, error, stackTrace) {
260
- super(message, status, stackTrace, 'DetailedApiError');
261
- _defineProperty(this, "error", void 0);
262
- this.error = error;
263
- }
264
- }
265
- function serializeUrl(host, path, queryParameters) {
266
- const queryParametersAsString = serializeQueryParameters(queryParameters);
267
- let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${path.charAt(0) === '/' ? path.substring(1) : path}`;
268
- if (queryParametersAsString.length) {
269
- url += `?${queryParametersAsString}`;
270
- }
271
- return url;
272
- }
273
- function serializeQueryParameters(parameters) {
274
- return Object.keys(parameters).filter(key => parameters[key] !== undefined).sort().map(key => `${key}=${encodeURIComponent(Object.prototype.toString.call(parameters[key]) === '[object Array]' ? parameters[key].join(',') : parameters[key]).replaceAll('+', '%20')}`).join('&');
275
- }
276
- function serializeData(request, requestOptions) {
277
- if (request.method === 'GET' || request.data === undefined && requestOptions.data === undefined) {
278
- return undefined;
279
- }
280
- const data = Array.isArray(request.data) ? request.data : {
281
- ...request.data,
282
- ...requestOptions.data
283
- };
284
- return JSON.stringify(data);
285
- }
286
- function serializeHeaders(baseHeaders, requestHeaders, requestOptionsHeaders) {
287
- const headers = {
288
- Accept: 'application/json',
289
- ...baseHeaders,
290
- ...requestHeaders,
291
- ...requestOptionsHeaders
292
- };
293
- const serializedHeaders = {};
294
- Object.keys(headers).forEach(header => {
295
- const value = headers[header];
296
- serializedHeaders[header.toLowerCase()] = value;
297
- });
298
- return serializedHeaders;
299
- }
300
- function deserializeSuccess(response) {
301
- try {
302
- return JSON.parse(response.content);
303
- } catch (e) {
304
- throw new DeserializationError(e.message, response);
305
- }
306
- }
307
- function deserializeFailure({
308
- content,
309
- status
310
- }, stackFrame) {
311
- try {
312
- const parsed = JSON.parse(content);
313
- if ('error' in parsed) {
314
- return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
315
- }
316
- return new ApiError(parsed.message, status, stackFrame);
317
- } catch {
318
- // ..
319
- }
320
- return new ApiError(content, status, stackFrame);
321
- }
322
-
323
- function isNetworkError({
324
- isTimedOut,
325
- status
326
- }) {
327
- return !isTimedOut && ~~status === 0;
328
- }
329
- function isRetryable({
330
- isTimedOut,
331
- status
332
- }) {
333
- return isTimedOut || isNetworkError({
334
- isTimedOut,
335
- status
336
- }) || ~~(status / 100) !== 2 && ~~(status / 100) !== 4;
337
- }
338
- function isSuccess({
339
- status
340
- }) {
341
- return ~~(status / 100) === 2;
342
- }
343
-
344
- function stackTraceWithoutCredentials(stackTrace) {
345
- return stackTrace.map(stackFrame => stackFrameWithoutCredentials(stackFrame));
346
- }
347
- function stackFrameWithoutCredentials(stackFrame) {
348
- const modifiedHeaders = stackFrame.request.headers['x-algolia-api-key'] ? {
349
- 'x-algolia-api-key': '*****'
350
- } : {};
351
- return {
352
- ...stackFrame,
353
- request: {
354
- ...stackFrame.request,
355
- headers: {
356
- ...stackFrame.request.headers,
357
- ...modifiedHeaders
358
- }
359
- }
360
- };
361
- }
362
-
363
- function createTransporter({
364
- hosts,
365
- hostsCache,
366
- baseHeaders,
367
- baseQueryParameters,
368
- algoliaAgent,
369
- timeouts,
370
- requester,
371
- requestsCache,
372
- responsesCache
373
- }) {
374
- async function createRetryableOptions(compatibleHosts) {
375
- const statefulHosts = await Promise.all(compatibleHosts.map(compatibleHost => {
376
- return hostsCache.get(compatibleHost, () => {
377
- return Promise.resolve(createStatefulHost(compatibleHost));
378
- });
379
- }));
380
- const hostsUp = statefulHosts.filter(host => host.isUp());
381
- const hostsTimedOut = statefulHosts.filter(host => host.isTimedOut());
382
- // Note, we put the hosts that previously timed out on the end of the list.
383
- const hostsAvailable = [...hostsUp, ...hostsTimedOut];
384
- const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
385
- return {
386
- hosts: compatibleHostsAvailable,
387
- getTimeout(timeoutsCount, baseTimeout) {
388
- /**
389
- * Imagine that you have 4 hosts, if timeouts will increase
390
- * on the following way: 1 (timed out) > 4 (timed out) > 5 (200).
391
- *
392
- * Note that, the very next request, we start from the previous timeout.
393
- *
394
- * 5 (timed out) > 6 (timed out) > 7 ...
395
- *
396
- * This strategy may need to be reviewed, but is the strategy on the our
397
- * current v3 version.
398
- */
399
- const timeoutMultiplier = hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;
400
- return timeoutMultiplier * baseTimeout;
401
- }
402
- };
403
- }
404
- async function retryableRequest(request, requestOptions, isRead = true) {
405
- const stackTrace = [];
406
- /**
407
- * First we prepare the payload that do not depend from hosts.
408
- */
409
- const data = serializeData(request, requestOptions);
410
- const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);
411
- // On `GET`, the data is proxied to query parameters.
412
- const dataQueryParameters = request.method === 'GET' ? {
413
- ...request.data,
414
- ...requestOptions.data
415
- } : {};
416
- const queryParameters = {
417
- ...baseQueryParameters,
418
- ...request.queryParameters,
419
- ...dataQueryParameters
420
- };
421
- if (algoliaAgent.value) {
422
- queryParameters['x-algolia-agent'] = algoliaAgent.value;
423
- }
424
- if (requestOptions && requestOptions.queryParameters) {
425
- for (const key of Object.keys(requestOptions.queryParameters)) {
426
- // We want to keep `undefined` and `null` values,
427
- // but also avoid stringifying `object`s, as they are
428
- // handled in the `serializeUrl` step right after.
429
- if (!requestOptions.queryParameters[key] || Object.prototype.toString.call(requestOptions.queryParameters[key]) === '[object Object]') {
430
- queryParameters[key] = requestOptions.queryParameters[key];
431
- } else {
432
- queryParameters[key] = requestOptions.queryParameters[key].toString();
433
- }
434
- }
435
- }
436
- let timeoutsCount = 0;
437
- const retry = async (retryableHosts, getTimeout) => {
438
- /**
439
- * We iterate on each host, until there is no host left.
440
- */
441
- const host = retryableHosts.pop();
442
- if (host === undefined) {
443
- throw new RetryError(stackTraceWithoutCredentials(stackTrace));
444
- }
445
- const timeout = {
446
- ...timeouts,
447
- ...requestOptions.timeouts
448
- };
449
- const payload = {
450
- data,
451
- headers,
452
- method: request.method,
453
- url: serializeUrl(host, request.path, queryParameters),
454
- connectTimeout: getTimeout(timeoutsCount, timeout.connect),
455
- responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write)
456
- };
457
- /**
458
- * The stackFrame is pushed to the stackTrace so we
459
- * can have information about onRetry and onFailure
460
- * decisions.
461
- */
462
- const pushToStackTrace = response => {
463
- const stackFrame = {
464
- request: payload,
465
- response,
466
- host,
467
- triesLeft: retryableHosts.length
468
- };
469
- stackTrace.push(stackFrame);
470
- return stackFrame;
471
- };
472
- const response = await requester.send(payload);
473
- if (isRetryable(response)) {
474
- const stackFrame = pushToStackTrace(response);
475
- // If response is a timeout, we increase the number of timeouts so we can increase the timeout later.
476
- if (response.isTimedOut) {
477
- timeoutsCount++;
478
- }
479
- /**
480
- * Failures are individually sent to the logger, allowing
481
- * the end user to debug / store stack frames even
482
- * when a retry error does not happen.
483
- */
484
- // eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
485
- console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));
486
- /**
487
- * We also store the state of the host in failure cases. If the host, is
488
- * down it will remain down for the next 2 minutes. In a timeout situation,
489
- * this host will be added end of the list of hosts on the next request.
490
- */
491
- await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));
492
- return retry(retryableHosts, getTimeout);
493
- }
494
- if (isSuccess(response)) {
495
- return deserializeSuccess(response);
496
- }
497
- pushToStackTrace(response);
498
- throw deserializeFailure(response, stackTrace);
499
- };
500
- /**
501
- * Finally, for each retryable host perform request until we got a non
502
- * retryable response. Some notes here:
503
- *
504
- * 1. The reverse here is applied so we can apply a `pop` later on => more performant.
505
- * 2. We also get from the retryable options a timeout multiplier that is tailored
506
- * for the current context.
507
- */
508
- const compatibleHosts = hosts.filter(host => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'));
509
- const options = await createRetryableOptions(compatibleHosts);
510
- return retry([...options.hosts].reverse(), options.getTimeout);
511
- }
512
- function createRequest(request, requestOptions = {}) {
513
- /**
514
- * A read request is either a `GET` request, or a request that we make
515
- * via the `read` transporter (e.g. `search`).
516
- */
517
- const isRead = request.useReadTransporter || request.method === 'GET';
518
- if (!isRead) {
519
- /**
520
- * On write requests, no cache mechanisms are applied, and we
521
- * proxy the request immediately to the requester.
522
- */
523
- return retryableRequest(request, requestOptions, isRead);
524
- }
525
- const createRetryableRequest = () => {
526
- /**
527
- * Then, we prepare a function factory that contains the construction of
528
- * the retryable request. At this point, we may *not* perform the actual
529
- * request. But we want to have the function factory ready.
530
- */
531
- return retryableRequest(request, requestOptions);
532
- };
533
- /**
534
- * Once we have the function factory ready, we need to determine of the
535
- * request is "cacheable" - should be cached. Note that, once again,
536
- * the user can force this option.
537
- */
538
- const cacheable = requestOptions.cacheable || request.cacheable;
539
- /**
540
- * If is not "cacheable", we immediately trigger the retryable request, no
541
- * need to check cache implementations.
542
- */
543
- if (cacheable !== true) {
544
- return createRetryableRequest();
545
- }
546
- /**
547
- * If the request is "cacheable", we need to first compute the key to ask
548
- * the cache implementations if this request is on progress or if the
549
- * response already exists on the cache.
550
- */
551
- const key = {
552
- request,
553
- requestOptions,
554
- transporter: {
555
- queryParameters: baseQueryParameters,
556
- headers: baseHeaders
557
- }
558
- };
559
- /**
560
- * With the computed key, we first ask the responses cache
561
- * implementation if this request was been resolved before.
562
- */
563
- return responsesCache.get(key, () => {
564
- /**
565
- * If the request has never resolved before, we actually ask if there
566
- * is a current request with the same key on progress.
567
- */
568
- return requestsCache.get(key, () =>
569
- /**
570
- * Finally, if there is no request in progress with the same key,
571
- * this `createRetryableRequest()` will actually trigger the
572
- * retryable request.
573
- */
574
- requestsCache.set(key, createRetryableRequest()).then(response => Promise.all([requestsCache.delete(key), response]), err => Promise.all([requestsCache.delete(key), Promise.reject(err)])).then(([_, response]) => response));
575
- }, {
576
- /**
577
- * Of course, once we get this response back from the server, we
578
- * tell response cache to actually store the received response
579
- * to be used later.
580
- */
581
- miss: response => responsesCache.set(key, response)
582
- });
583
- }
584
- return {
585
- hostsCache,
586
- requester,
587
- timeouts,
588
- algoliaAgent,
589
- baseHeaders,
590
- baseQueryParameters,
591
- hosts,
592
- request: createRequest,
593
- requestsCache,
594
- responsesCache
595
- };
596
- }
597
-
598
- function createAlgoliaAgent(version) {
599
- const algoliaAgent = {
600
- value: `Algolia for JavaScript (${version})`,
601
- add(options) {
602
- const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;
603
- if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
604
- algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
605
- }
606
- return algoliaAgent;
607
- }
608
- };
609
- return algoliaAgent;
610
- }
611
-
612
- function getAlgoliaAgent({
613
- algoliaAgents,
614
- client,
615
- version
616
- }) {
617
- const defaultAlgoliaAgent = createAlgoliaAgent(version).add({
618
- segment: client,
619
- version
620
- });
621
- algoliaAgents.forEach(algoliaAgent => defaultAlgoliaAgent.add(algoliaAgent));
622
- return defaultAlgoliaAgent;
623
- }
624
-
625
- const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
626
- const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
627
- const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
628
-
629
- function createXhrRequester() {
630
- function send(request) {
631
- return new Promise((resolve) => {
632
- const baseRequester = new XMLHttpRequest();
633
- baseRequester.open(request.method, request.url, true);
634
- Object.keys(request.headers).forEach((key) => baseRequester.setRequestHeader(key, request.headers[key]));
635
- const createTimeout = (timeout, content) => {
636
- return setTimeout(() => {
637
- baseRequester.abort();
638
- resolve({
639
- status: 0,
640
- content,
641
- isTimedOut: true,
642
- });
643
- }, timeout);
644
- };
645
- const connectTimeout = createTimeout(request.connectTimeout, 'Connection timeout');
646
- let responseTimeout;
647
- baseRequester.onreadystatechange = () => {
648
- if (baseRequester.readyState > baseRequester.OPENED && responseTimeout === undefined) {
649
- clearTimeout(connectTimeout);
650
- responseTimeout = createTimeout(request.responseTimeout, 'Socket timeout');
651
- }
652
- };
653
- baseRequester.onerror = () => {
654
- // istanbul ignore next
655
- if (baseRequester.status === 0) {
656
- clearTimeout(connectTimeout);
657
- clearTimeout(responseTimeout);
658
- resolve({
659
- content: baseRequester.responseText || 'Network request failed',
660
- status: baseRequester.status,
661
- isTimedOut: false,
662
- });
663
- }
664
- };
665
- baseRequester.onload = () => {
666
- clearTimeout(connectTimeout);
667
- clearTimeout(responseTimeout);
668
- resolve({
669
- content: baseRequester.responseText,
670
- status: baseRequester.status,
671
- isTimedOut: false,
672
- });
673
- };
674
- baseRequester.send(request.data);
675
- });
676
- }
677
- return { send };
678
- }
679
-
680
- // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
681
- const apiClientVersion = '5.2.4';
682
- const REGIONS = ['de', 'us'];
683
- function getDefaultHosts(region) {
684
- const url = !region ? 'analytics.algolia.com' : 'analytics.{region}.algolia.com'.replace('{region}', region);
685
- return [{ url, accept: 'readWrite', protocol: 'https' }];
686
- }
687
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
688
- function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }) {
689
- const auth = createAuth(appIdOption, apiKeyOption, authMode);
690
- const transporter = createTransporter({
691
- hosts: getDefaultHosts(regionOption),
692
- ...options,
693
- algoliaAgent: getAlgoliaAgent({
694
- algoliaAgents,
695
- client: 'Analytics',
696
- version: apiClientVersion,
697
- }),
698
- baseHeaders: {
699
- 'content-type': 'text/plain',
700
- ...auth.headers(),
701
- ...options.baseHeaders,
702
- },
703
- baseQueryParameters: {
704
- ...auth.queryParameters(),
705
- ...options.baseQueryParameters,
706
- },
707
- });
708
- return {
709
- transporter,
710
- /**
711
- * The `appId` currently in use.
712
- */
713
- appId: appIdOption,
714
- /**
715
- * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
716
- */
717
- clearCache() {
718
- return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined);
719
- },
720
- /**
721
- * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
722
- */
723
- get _ua() {
724
- return transporter.algoliaAgent.value;
725
- },
726
- /**
727
- * Adds a `segment` to the `x-algolia-agent` sent with every requests.
728
- *
729
- * @param segment - The algolia agent (user-agent) segment to add.
730
- * @param version - The version of the agent.
731
- */
732
- addAlgoliaAgent(segment, version) {
733
- transporter.algoliaAgent.add({ segment, version });
734
- },
735
- /**
736
- * This method allow you to send requests to the Algolia REST API.
737
- *
738
- * @param customDelete - The customDelete object.
739
- * @param customDelete.path - Path of the endpoint, anything after \"/1\" must be specified.
740
- * @param customDelete.parameters - Query parameters to apply to the current query.
741
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
742
- */
743
- customDelete({ path, parameters }, requestOptions) {
744
- if (!path) {
745
- throw new Error('Parameter `path` is required when calling `customDelete`.');
746
- }
747
- const requestPath = '/{path}'.replace('{path}', path);
748
- const headers = {};
749
- const queryParameters = parameters ? parameters : {};
750
- const request = {
751
- method: 'DELETE',
752
- path: requestPath,
753
- queryParameters,
754
- headers,
755
- };
756
- return transporter.request(request, requestOptions);
757
- },
758
- /**
759
- * This method allow you to send requests to the Algolia REST API.
760
- *
761
- * @param customGet - The customGet object.
762
- * @param customGet.path - Path of the endpoint, anything after \"/1\" must be specified.
763
- * @param customGet.parameters - Query parameters to apply to the current query.
764
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
765
- */
766
- customGet({ path, parameters }, requestOptions) {
767
- if (!path) {
768
- throw new Error('Parameter `path` is required when calling `customGet`.');
769
- }
770
- const requestPath = '/{path}'.replace('{path}', path);
771
- const headers = {};
772
- const queryParameters = parameters ? parameters : {};
773
- const request = {
774
- method: 'GET',
775
- path: requestPath,
776
- queryParameters,
777
- headers,
778
- };
779
- return transporter.request(request, requestOptions);
780
- },
781
- /**
782
- * This method allow you to send requests to the Algolia REST API.
783
- *
784
- * @param customPost - The customPost object.
785
- * @param customPost.path - Path of the endpoint, anything after \"/1\" must be specified.
786
- * @param customPost.parameters - Query parameters to apply to the current query.
787
- * @param customPost.body - Parameters to send with the custom request.
788
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
789
- */
790
- customPost({ path, parameters, body }, requestOptions) {
791
- if (!path) {
792
- throw new Error('Parameter `path` is required when calling `customPost`.');
793
- }
794
- const requestPath = '/{path}'.replace('{path}', path);
795
- const headers = {};
796
- const queryParameters = parameters ? parameters : {};
797
- const request = {
798
- method: 'POST',
799
- path: requestPath,
800
- queryParameters,
801
- headers,
802
- data: body ? body : {},
803
- };
804
- return transporter.request(request, requestOptions);
805
- },
806
- /**
807
- * This method allow you to send requests to the Algolia REST API.
808
- *
809
- * @param customPut - The customPut object.
810
- * @param customPut.path - Path of the endpoint, anything after \"/1\" must be specified.
811
- * @param customPut.parameters - Query parameters to apply to the current query.
812
- * @param customPut.body - Parameters to send with the custom request.
813
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
814
- */
815
- customPut({ path, parameters, body }, requestOptions) {
816
- if (!path) {
817
- throw new Error('Parameter `path` is required when calling `customPut`.');
818
- }
819
- const requestPath = '/{path}'.replace('{path}', path);
820
- const headers = {};
821
- const queryParameters = parameters ? parameters : {};
822
- const request = {
823
- method: 'PUT',
824
- path: requestPath,
825
- queryParameters,
826
- headers,
827
- data: body ? body : {},
828
- };
829
- return transporter.request(request, requestOptions);
830
- },
831
- /**
832
- * Retrieves the add-to-cart rate for all of 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.
833
- *
834
- * Required API Key ACLs:
835
- * - analytics.
836
- *
837
- * @param getAddToCartRate - The getAddToCartRate object.
838
- * @param getAddToCartRate.index - Index name.
839
- * @param getAddToCartRate.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
840
- * @param getAddToCartRate.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
841
- * @param getAddToCartRate.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
842
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
843
- */
844
- getAddToCartRate({ index, startDate, endDate, tags }, requestOptions) {
845
- if (!index) {
846
- throw new Error('Parameter `index` is required when calling `getAddToCartRate`.');
847
- }
848
- const requestPath = '/2/conversions/addToCartRate';
849
- const headers = {};
850
- const queryParameters = {};
851
- if (index !== undefined) {
852
- queryParameters.index = index.toString();
853
- }
854
- if (startDate !== undefined) {
855
- queryParameters.startDate = startDate.toString();
856
- }
857
- if (endDate !== undefined) {
858
- queryParameters.endDate = endDate.toString();
859
- }
860
- if (tags !== undefined) {
861
- queryParameters.tags = tags.toString();
862
- }
863
- const request = {
864
- method: 'GET',
865
- path: requestPath,
866
- queryParameters,
867
- headers,
868
- };
869
- return transporter.request(request, requestOptions);
870
- },
871
- /**
872
- * Retrieves the average click position of your search results, including a daily breakdown. The average click position is the average of all clicked search results\' 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.
873
- *
874
- * Required API Key ACLs:
875
- * - analytics.
876
- *
877
- * @param getAverageClickPosition - The getAverageClickPosition object.
878
- * @param getAverageClickPosition.index - Index name.
879
- * @param getAverageClickPosition.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
880
- * @param getAverageClickPosition.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
881
- * @param getAverageClickPosition.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
882
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
883
- */
884
- getAverageClickPosition({ index, startDate, endDate, tags }, requestOptions) {
885
- if (!index) {
886
- throw new Error('Parameter `index` is required when calling `getAverageClickPosition`.');
887
- }
888
- const requestPath = '/2/clicks/averageClickPosition';
889
- const headers = {};
890
- const queryParameters = {};
891
- if (index !== undefined) {
892
- queryParameters.index = index.toString();
893
- }
894
- if (startDate !== undefined) {
895
- queryParameters.startDate = startDate.toString();
896
- }
897
- if (endDate !== undefined) {
898
- queryParameters.endDate = endDate.toString();
899
- }
900
- if (tags !== undefined) {
901
- queryParameters.tags = tags.toString();
902
- }
903
- const request = {
904
- method: 'GET',
905
- path: requestPath,
906
- queryParameters,
907
- headers,
908
- };
909
- return transporter.request(request, requestOptions);
910
- },
911
- /**
912
- * 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.
913
- *
914
- * Required API Key ACLs:
915
- * - analytics.
916
- *
917
- * @param getClickPositions - The getClickPositions object.
918
- * @param getClickPositions.index - Index name.
919
- * @param getClickPositions.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
920
- * @param getClickPositions.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
921
- * @param getClickPositions.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
922
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
923
- */
924
- getClickPositions({ index, startDate, endDate, tags }, requestOptions) {
925
- if (!index) {
926
- throw new Error('Parameter `index` is required when calling `getClickPositions`.');
927
- }
928
- const requestPath = '/2/clicks/positions';
929
- const headers = {};
930
- const queryParameters = {};
931
- if (index !== undefined) {
932
- queryParameters.index = index.toString();
933
- }
934
- if (startDate !== undefined) {
935
- queryParameters.startDate = startDate.toString();
936
- }
937
- if (endDate !== undefined) {
938
- queryParameters.endDate = endDate.toString();
939
- }
940
- if (tags !== undefined) {
941
- queryParameters.tags = tags.toString();
942
- }
943
- const request = {
944
- method: 'GET',
945
- path: requestPath,
946
- queryParameters,
947
- headers,
948
- };
949
- return transporter.request(request, requestOptions);
950
- },
951
- /**
952
- * Retrieves the click-through rate for all of 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.
953
- *
954
- * Required API Key ACLs:
955
- * - analytics.
956
- *
957
- * @param getClickThroughRate - The getClickThroughRate object.
958
- * @param getClickThroughRate.index - Index name.
959
- * @param getClickThroughRate.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
960
- * @param getClickThroughRate.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
961
- * @param getClickThroughRate.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
962
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
963
- */
964
- getClickThroughRate({ index, startDate, endDate, tags }, requestOptions) {
965
- if (!index) {
966
- throw new Error('Parameter `index` is required when calling `getClickThroughRate`.');
967
- }
968
- const requestPath = '/2/clicks/clickThroughRate';
969
- const headers = {};
970
- const queryParameters = {};
971
- if (index !== undefined) {
972
- queryParameters.index = index.toString();
973
- }
974
- if (startDate !== undefined) {
975
- queryParameters.startDate = startDate.toString();
976
- }
977
- if (endDate !== undefined) {
978
- queryParameters.endDate = endDate.toString();
979
- }
980
- if (tags !== undefined) {
981
- queryParameters.tags = tags.toString();
982
- }
983
- const request = {
984
- method: 'GET',
985
- path: requestPath,
986
- queryParameters,
987
- headers,
988
- };
989
- return transporter.request(request, requestOptions);
990
- },
991
- /**
992
- * Retrieves the conversion rate for all of 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.
993
- *
994
- * Required API Key ACLs:
995
- * - analytics.
996
- *
997
- * @param getConversionRate - The getConversionRate object.
998
- * @param getConversionRate.index - Index name.
999
- * @param getConversionRate.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1000
- * @param getConversionRate.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1001
- * @param getConversionRate.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1002
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1003
- */
1004
- getConversionRate({ index, startDate, endDate, tags }, requestOptions) {
1005
- if (!index) {
1006
- throw new Error('Parameter `index` is required when calling `getConversionRate`.');
1007
- }
1008
- const requestPath = '/2/conversions/conversionRate';
1009
- const headers = {};
1010
- const queryParameters = {};
1011
- if (index !== undefined) {
1012
- queryParameters.index = index.toString();
1013
- }
1014
- if (startDate !== undefined) {
1015
- queryParameters.startDate = startDate.toString();
1016
- }
1017
- if (endDate !== undefined) {
1018
- queryParameters.endDate = endDate.toString();
1019
- }
1020
- if (tags !== undefined) {
1021
- queryParameters.tags = tags.toString();
1022
- }
1023
- const request = {
1024
- method: 'GET',
1025
- path: requestPath,
1026
- queryParameters,
1027
- headers,
1028
- };
1029
- return transporter.request(request, requestOptions);
1030
- },
1031
- /**
1032
- * 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.
1033
- *
1034
- * Required API Key ACLs:
1035
- * - analytics.
1036
- *
1037
- * @param getNoClickRate - The getNoClickRate object.
1038
- * @param getNoClickRate.index - Index name.
1039
- * @param getNoClickRate.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1040
- * @param getNoClickRate.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1041
- * @param getNoClickRate.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1042
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1043
- */
1044
- getNoClickRate({ index, startDate, endDate, tags }, requestOptions) {
1045
- if (!index) {
1046
- throw new Error('Parameter `index` is required when calling `getNoClickRate`.');
1047
- }
1048
- const requestPath = '/2/searches/noClickRate';
1049
- const headers = {};
1050
- const queryParameters = {};
1051
- if (index !== undefined) {
1052
- queryParameters.index = index.toString();
1053
- }
1054
- if (startDate !== undefined) {
1055
- queryParameters.startDate = startDate.toString();
1056
- }
1057
- if (endDate !== undefined) {
1058
- queryParameters.endDate = endDate.toString();
1059
- }
1060
- if (tags !== undefined) {
1061
- queryParameters.tags = tags.toString();
1062
- }
1063
- const request = {
1064
- method: 'GET',
1065
- path: requestPath,
1066
- queryParameters,
1067
- headers,
1068
- };
1069
- return transporter.request(request, requestOptions);
1070
- },
1071
- /**
1072
- * 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.
1073
- *
1074
- * Required API Key ACLs:
1075
- * - analytics.
1076
- *
1077
- * @param getNoResultsRate - The getNoResultsRate object.
1078
- * @param getNoResultsRate.index - Index name.
1079
- * @param getNoResultsRate.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1080
- * @param getNoResultsRate.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1081
- * @param getNoResultsRate.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1082
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1083
- */
1084
- getNoResultsRate({ index, startDate, endDate, tags }, requestOptions) {
1085
- if (!index) {
1086
- throw new Error('Parameter `index` is required when calling `getNoResultsRate`.');
1087
- }
1088
- const requestPath = '/2/searches/noResultRate';
1089
- const headers = {};
1090
- const queryParameters = {};
1091
- if (index !== undefined) {
1092
- queryParameters.index = index.toString();
1093
- }
1094
- if (startDate !== undefined) {
1095
- queryParameters.startDate = startDate.toString();
1096
- }
1097
- if (endDate !== undefined) {
1098
- queryParameters.endDate = endDate.toString();
1099
- }
1100
- if (tags !== undefined) {
1101
- queryParameters.tags = tags.toString();
1102
- }
1103
- const request = {
1104
- method: 'GET',
1105
- path: requestPath,
1106
- queryParameters,
1107
- headers,
1108
- };
1109
- return transporter.request(request, requestOptions);
1110
- },
1111
- /**
1112
- * Retrieves the purchase rate for all of 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.
1113
- *
1114
- * Required API Key ACLs:
1115
- * - analytics.
1116
- *
1117
- * @param getPurchaseRate - The getPurchaseRate object.
1118
- * @param getPurchaseRate.index - Index name.
1119
- * @param getPurchaseRate.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1120
- * @param getPurchaseRate.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1121
- * @param getPurchaseRate.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1122
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1123
- */
1124
- getPurchaseRate({ index, startDate, endDate, tags }, requestOptions) {
1125
- if (!index) {
1126
- throw new Error('Parameter `index` is required when calling `getPurchaseRate`.');
1127
- }
1128
- const requestPath = '/2/conversions/purchaseRate';
1129
- const headers = {};
1130
- const queryParameters = {};
1131
- if (index !== undefined) {
1132
- queryParameters.index = index.toString();
1133
- }
1134
- if (startDate !== undefined) {
1135
- queryParameters.startDate = startDate.toString();
1136
- }
1137
- if (endDate !== undefined) {
1138
- queryParameters.endDate = endDate.toString();
1139
- }
1140
- if (tags !== undefined) {
1141
- queryParameters.tags = tags.toString();
1142
- }
1143
- const request = {
1144
- method: 'GET',
1145
- path: requestPath,
1146
- queryParameters,
1147
- headers,
1148
- };
1149
- return transporter.request(request, requestOptions);
1150
- },
1151
- /**
1152
- * Retrieves revenue-related metrics, such as the total revenue or the average order value. To retrieve revenue-related metrics, sent purchase events. By default, the analyzed period includes the last eight days including the current day.
1153
- *
1154
- * Required API Key ACLs:
1155
- * - analytics.
1156
- *
1157
- * @param getRevenue - The getRevenue object.
1158
- * @param getRevenue.index - Index name.
1159
- * @param getRevenue.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1160
- * @param getRevenue.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1161
- * @param getRevenue.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1162
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1163
- */
1164
- getRevenue({ index, startDate, endDate, tags }, requestOptions) {
1165
- if (!index) {
1166
- throw new Error('Parameter `index` is required when calling `getRevenue`.');
1167
- }
1168
- const requestPath = '/2/conversions/revenue';
1169
- const headers = {};
1170
- const queryParameters = {};
1171
- if (index !== undefined) {
1172
- queryParameters.index = index.toString();
1173
- }
1174
- if (startDate !== undefined) {
1175
- queryParameters.startDate = startDate.toString();
1176
- }
1177
- if (endDate !== undefined) {
1178
- queryParameters.endDate = endDate.toString();
1179
- }
1180
- if (tags !== undefined) {
1181
- queryParameters.tags = tags.toString();
1182
- }
1183
- const request = {
1184
- method: 'GET',
1185
- path: requestPath,
1186
- queryParameters,
1187
- headers,
1188
- };
1189
- return transporter.request(request, requestOptions);
1190
- },
1191
- /**
1192
- * Retrieves the number of searches within a time range, including a daily breakdown. By default, the analyzed period includes the last eight days including the current day.
1193
- *
1194
- * Required API Key ACLs:
1195
- * - analytics.
1196
- *
1197
- * @param getSearchesCount - The getSearchesCount object.
1198
- * @param getSearchesCount.index - Index name.
1199
- * @param getSearchesCount.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1200
- * @param getSearchesCount.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1201
- * @param getSearchesCount.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1202
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1203
- */
1204
- getSearchesCount({ index, startDate, endDate, tags }, requestOptions) {
1205
- if (!index) {
1206
- throw new Error('Parameter `index` is required when calling `getSearchesCount`.');
1207
- }
1208
- const requestPath = '/2/searches/count';
1209
- const headers = {};
1210
- const queryParameters = {};
1211
- if (index !== undefined) {
1212
- queryParameters.index = index.toString();
1213
- }
1214
- if (startDate !== undefined) {
1215
- queryParameters.startDate = startDate.toString();
1216
- }
1217
- if (endDate !== undefined) {
1218
- queryParameters.endDate = endDate.toString();
1219
- }
1220
- if (tags !== undefined) {
1221
- queryParameters.tags = tags.toString();
1222
- }
1223
- const request = {
1224
- method: 'GET',
1225
- path: requestPath,
1226
- queryParameters,
1227
- headers,
1228
- };
1229
- return transporter.request(request, requestOptions);
1230
- },
1231
- /**
1232
- * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
1233
- *
1234
- * Required API Key ACLs:
1235
- * - analytics.
1236
- *
1237
- * @param getSearchesNoClicks - The getSearchesNoClicks object.
1238
- * @param getSearchesNoClicks.index - Index name.
1239
- * @param getSearchesNoClicks.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1240
- * @param getSearchesNoClicks.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1241
- * @param getSearchesNoClicks.limit - Number of items to return.
1242
- * @param getSearchesNoClicks.offset - Position of the first item to return.
1243
- * @param getSearchesNoClicks.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1244
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1245
- */
1246
- getSearchesNoClicks({ index, startDate, endDate, limit, offset, tags }, requestOptions) {
1247
- if (!index) {
1248
- throw new Error('Parameter `index` is required when calling `getSearchesNoClicks`.');
1249
- }
1250
- const requestPath = '/2/searches/noClicks';
1251
- const headers = {};
1252
- const queryParameters = {};
1253
- if (index !== undefined) {
1254
- queryParameters.index = index.toString();
1255
- }
1256
- if (startDate !== undefined) {
1257
- queryParameters.startDate = startDate.toString();
1258
- }
1259
- if (endDate !== undefined) {
1260
- queryParameters.endDate = endDate.toString();
1261
- }
1262
- if (limit !== undefined) {
1263
- queryParameters.limit = limit.toString();
1264
- }
1265
- if (offset !== undefined) {
1266
- queryParameters.offset = offset.toString();
1267
- }
1268
- if (tags !== undefined) {
1269
- queryParameters.tags = tags.toString();
1270
- }
1271
- const request = {
1272
- method: 'GET',
1273
- path: requestPath,
1274
- queryParameters,
1275
- headers,
1276
- };
1277
- return transporter.request(request, requestOptions);
1278
- },
1279
- /**
1280
- * Retrieves the most popular searches that didn\'t return any results.
1281
- *
1282
- * Required API Key ACLs:
1283
- * - analytics.
1284
- *
1285
- * @param getSearchesNoResults - The getSearchesNoResults object.
1286
- * @param getSearchesNoResults.index - Index name.
1287
- * @param getSearchesNoResults.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1288
- * @param getSearchesNoResults.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1289
- * @param getSearchesNoResults.limit - Number of items to return.
1290
- * @param getSearchesNoResults.offset - Position of the first item to return.
1291
- * @param getSearchesNoResults.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1292
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1293
- */
1294
- getSearchesNoResults({ index, startDate, endDate, limit, offset, tags }, requestOptions) {
1295
- if (!index) {
1296
- throw new Error('Parameter `index` is required when calling `getSearchesNoResults`.');
1297
- }
1298
- const requestPath = '/2/searches/noResults';
1299
- const headers = {};
1300
- const queryParameters = {};
1301
- if (index !== undefined) {
1302
- queryParameters.index = index.toString();
1303
- }
1304
- if (startDate !== undefined) {
1305
- queryParameters.startDate = startDate.toString();
1306
- }
1307
- if (endDate !== undefined) {
1308
- queryParameters.endDate = endDate.toString();
1309
- }
1310
- if (limit !== undefined) {
1311
- queryParameters.limit = limit.toString();
1312
- }
1313
- if (offset !== undefined) {
1314
- queryParameters.offset = offset.toString();
1315
- }
1316
- if (tags !== undefined) {
1317
- queryParameters.tags = tags.toString();
1318
- }
1319
- const request = {
1320
- method: 'GET',
1321
- path: requestPath,
1322
- queryParameters,
1323
- headers,
1324
- };
1325
- return transporter.request(request, requestOptions);
1326
- },
1327
- /**
1328
- * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
1329
- *
1330
- * Required API Key ACLs:
1331
- * - analytics.
1332
- *
1333
- * @param getStatus - The getStatus object.
1334
- * @param getStatus.index - Index name.
1335
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1336
- */
1337
- getStatus({ index }, requestOptions) {
1338
- if (!index) {
1339
- throw new Error('Parameter `index` is required when calling `getStatus`.');
1340
- }
1341
- const requestPath = '/2/status';
1342
- const headers = {};
1343
- const queryParameters = {};
1344
- if (index !== undefined) {
1345
- queryParameters.index = index.toString();
1346
- }
1347
- const request = {
1348
- method: 'GET',
1349
- path: requestPath,
1350
- queryParameters,
1351
- headers,
1352
- };
1353
- return transporter.request(request, requestOptions);
1354
- },
1355
- /**
1356
- * Retrieves the countries with the most searches to your index.
1357
- *
1358
- * Required API Key ACLs:
1359
- * - analytics.
1360
- *
1361
- * @param getTopCountries - The getTopCountries object.
1362
- * @param getTopCountries.index - Index name.
1363
- * @param getTopCountries.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1364
- * @param getTopCountries.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1365
- * @param getTopCountries.limit - Number of items to return.
1366
- * @param getTopCountries.offset - Position of the first item to return.
1367
- * @param getTopCountries.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1368
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1369
- */
1370
- getTopCountries({ index, startDate, endDate, limit, offset, tags }, requestOptions) {
1371
- if (!index) {
1372
- throw new Error('Parameter `index` is required when calling `getTopCountries`.');
1373
- }
1374
- const requestPath = '/2/countries';
1375
- const headers = {};
1376
- const queryParameters = {};
1377
- if (index !== undefined) {
1378
- queryParameters.index = index.toString();
1379
- }
1380
- if (startDate !== undefined) {
1381
- queryParameters.startDate = startDate.toString();
1382
- }
1383
- if (endDate !== undefined) {
1384
- queryParameters.endDate = endDate.toString();
1385
- }
1386
- if (limit !== undefined) {
1387
- queryParameters.limit = limit.toString();
1388
- }
1389
- if (offset !== undefined) {
1390
- queryParameters.offset = offset.toString();
1391
- }
1392
- if (tags !== undefined) {
1393
- queryParameters.tags = tags.toString();
1394
- }
1395
- const request = {
1396
- method: 'GET',
1397
- path: requestPath,
1398
- queryParameters,
1399
- headers,
1400
- };
1401
- return transporter.request(request, requestOptions);
1402
- },
1403
- /**
1404
- * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
1405
- *
1406
- * Required API Key ACLs:
1407
- * - analytics.
1408
- *
1409
- * @param getTopFilterAttributes - The getTopFilterAttributes object.
1410
- * @param getTopFilterAttributes.index - Index name.
1411
- * @param getTopFilterAttributes.search - Search query.
1412
- * @param getTopFilterAttributes.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1413
- * @param getTopFilterAttributes.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1414
- * @param getTopFilterAttributes.limit - Number of items to return.
1415
- * @param getTopFilterAttributes.offset - Position of the first item to return.
1416
- * @param getTopFilterAttributes.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1417
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1418
- */
1419
- getTopFilterAttributes({ index, search, startDate, endDate, limit, offset, tags }, requestOptions) {
1420
- if (!index) {
1421
- throw new Error('Parameter `index` is required when calling `getTopFilterAttributes`.');
1422
- }
1423
- const requestPath = '/2/filters';
1424
- const headers = {};
1425
- const queryParameters = {};
1426
- if (index !== undefined) {
1427
- queryParameters.index = index.toString();
1428
- }
1429
- if (search !== undefined) {
1430
- queryParameters.search = search.toString();
1431
- }
1432
- if (startDate !== undefined) {
1433
- queryParameters.startDate = startDate.toString();
1434
- }
1435
- if (endDate !== undefined) {
1436
- queryParameters.endDate = endDate.toString();
1437
- }
1438
- if (limit !== undefined) {
1439
- queryParameters.limit = limit.toString();
1440
- }
1441
- if (offset !== undefined) {
1442
- queryParameters.offset = offset.toString();
1443
- }
1444
- if (tags !== undefined) {
1445
- queryParameters.tags = tags.toString();
1446
- }
1447
- const request = {
1448
- method: 'GET',
1449
- path: requestPath,
1450
- queryParameters,
1451
- headers,
1452
- };
1453
- return transporter.request(request, requestOptions);
1454
- },
1455
- /**
1456
- * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
1457
- *
1458
- * Required API Key ACLs:
1459
- * - analytics.
1460
- *
1461
- * @param getTopFilterForAttribute - The getTopFilterForAttribute object.
1462
- * @param getTopFilterForAttribute.attribute - Attribute name.
1463
- * @param getTopFilterForAttribute.index - Index name.
1464
- * @param getTopFilterForAttribute.search - Search query.
1465
- * @param getTopFilterForAttribute.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1466
- * @param getTopFilterForAttribute.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1467
- * @param getTopFilterForAttribute.limit - Number of items to return.
1468
- * @param getTopFilterForAttribute.offset - Position of the first item to return.
1469
- * @param getTopFilterForAttribute.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1470
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1471
- */
1472
- getTopFilterForAttribute({ attribute, index, search, startDate, endDate, limit, offset, tags }, requestOptions) {
1473
- if (!attribute) {
1474
- throw new Error('Parameter `attribute` is required when calling `getTopFilterForAttribute`.');
1475
- }
1476
- if (!index) {
1477
- throw new Error('Parameter `index` is required when calling `getTopFilterForAttribute`.');
1478
- }
1479
- const requestPath = '/2/filters/{attribute}'.replace('{attribute}', encodeURIComponent(attribute));
1480
- const headers = {};
1481
- const queryParameters = {};
1482
- if (index !== undefined) {
1483
- queryParameters.index = index.toString();
1484
- }
1485
- if (search !== undefined) {
1486
- queryParameters.search = search.toString();
1487
- }
1488
- if (startDate !== undefined) {
1489
- queryParameters.startDate = startDate.toString();
1490
- }
1491
- if (endDate !== undefined) {
1492
- queryParameters.endDate = endDate.toString();
1493
- }
1494
- if (limit !== undefined) {
1495
- queryParameters.limit = limit.toString();
1496
- }
1497
- if (offset !== undefined) {
1498
- queryParameters.offset = offset.toString();
1499
- }
1500
- if (tags !== undefined) {
1501
- queryParameters.tags = tags.toString();
1502
- }
1503
- const request = {
1504
- method: 'GET',
1505
- path: requestPath,
1506
- queryParameters,
1507
- headers,
1508
- };
1509
- return transporter.request(request, requestOptions);
1510
- },
1511
- /**
1512
- * 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.
1513
- *
1514
- * Required API Key ACLs:
1515
- * - analytics.
1516
- *
1517
- * @param getTopFiltersNoResults - The getTopFiltersNoResults object.
1518
- * @param getTopFiltersNoResults.index - Index name.
1519
- * @param getTopFiltersNoResults.search - Search query.
1520
- * @param getTopFiltersNoResults.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1521
- * @param getTopFiltersNoResults.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1522
- * @param getTopFiltersNoResults.limit - Number of items to return.
1523
- * @param getTopFiltersNoResults.offset - Position of the first item to return.
1524
- * @param getTopFiltersNoResults.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1525
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1526
- */
1527
- getTopFiltersNoResults({ index, search, startDate, endDate, limit, offset, tags }, requestOptions) {
1528
- if (!index) {
1529
- throw new Error('Parameter `index` is required when calling `getTopFiltersNoResults`.');
1530
- }
1531
- const requestPath = '/2/filters/noResults';
1532
- const headers = {};
1533
- const queryParameters = {};
1534
- if (index !== undefined) {
1535
- queryParameters.index = index.toString();
1536
- }
1537
- if (search !== undefined) {
1538
- queryParameters.search = search.toString();
1539
- }
1540
- if (startDate !== undefined) {
1541
- queryParameters.startDate = startDate.toString();
1542
- }
1543
- if (endDate !== undefined) {
1544
- queryParameters.endDate = endDate.toString();
1545
- }
1546
- if (limit !== undefined) {
1547
- queryParameters.limit = limit.toString();
1548
- }
1549
- if (offset !== undefined) {
1550
- queryParameters.offset = offset.toString();
1551
- }
1552
- if (tags !== undefined) {
1553
- queryParameters.tags = tags.toString();
1554
- }
1555
- const request = {
1556
- method: 'GET',
1557
- path: requestPath,
1558
- queryParameters,
1559
- headers,
1560
- };
1561
- return transporter.request(request, requestOptions);
1562
- },
1563
- /**
1564
- * Retrieves the object IDs of the most frequent search results.
1565
- *
1566
- * Required API Key ACLs:
1567
- * - analytics.
1568
- *
1569
- * @param getTopHits - The getTopHits object.
1570
- * @param getTopHits.index - Index name.
1571
- * @param getTopHits.search - Search query.
1572
- * @param getTopHits.clickAnalytics - Whether to include metrics related to click and conversion events in the response.
1573
- * @param getTopHits.revenueAnalytics - Whether to include revenue-related metrics in the response. If true, metrics related to click and conversion events are also included in the response.
1574
- * @param getTopHits.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1575
- * @param getTopHits.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1576
- * @param getTopHits.limit - Number of items to return.
1577
- * @param getTopHits.offset - Position of the first item to return.
1578
- * @param getTopHits.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1579
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1580
- */
1581
- getTopHits({ index, search, clickAnalytics, revenueAnalytics, startDate, endDate, limit, offset, tags }, requestOptions) {
1582
- if (!index) {
1583
- throw new Error('Parameter `index` is required when calling `getTopHits`.');
1584
- }
1585
- const requestPath = '/2/hits';
1586
- const headers = {};
1587
- const queryParameters = {};
1588
- if (index !== undefined) {
1589
- queryParameters.index = index.toString();
1590
- }
1591
- if (search !== undefined) {
1592
- queryParameters.search = search.toString();
1593
- }
1594
- if (clickAnalytics !== undefined) {
1595
- queryParameters.clickAnalytics = clickAnalytics.toString();
1596
- }
1597
- if (revenueAnalytics !== undefined) {
1598
- queryParameters.revenueAnalytics = revenueAnalytics.toString();
1599
- }
1600
- if (startDate !== undefined) {
1601
- queryParameters.startDate = startDate.toString();
1602
- }
1603
- if (endDate !== undefined) {
1604
- queryParameters.endDate = endDate.toString();
1605
- }
1606
- if (limit !== undefined) {
1607
- queryParameters.limit = limit.toString();
1608
- }
1609
- if (offset !== undefined) {
1610
- queryParameters.offset = offset.toString();
1611
- }
1612
- if (tags !== undefined) {
1613
- queryParameters.tags = tags.toString();
1614
- }
1615
- const request = {
1616
- method: 'GET',
1617
- path: requestPath,
1618
- queryParameters,
1619
- headers,
1620
- };
1621
- return transporter.request(request, requestOptions);
1622
- },
1623
- /**
1624
- * Returns the most popular search terms.
1625
- *
1626
- * Required API Key ACLs:
1627
- * - analytics.
1628
- *
1629
- * @param getTopSearches - The getTopSearches object.
1630
- * @param getTopSearches.index - Index name.
1631
- * @param getTopSearches.clickAnalytics - Whether to include metrics related to click and conversion events in the response.
1632
- * @param getTopSearches.revenueAnalytics - Whether to include revenue-related metrics in the response. If true, metrics related to click and conversion events are also included in the response.
1633
- * @param getTopSearches.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1634
- * @param getTopSearches.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1635
- * @param getTopSearches.orderBy - Attribute by which to order the response items. If the `clickAnalytics` parameter is false, only `searchCount` is available.
1636
- * @param getTopSearches.direction - Sorting direction of the results: ascending or descending.
1637
- * @param getTopSearches.limit - Number of items to return.
1638
- * @param getTopSearches.offset - Position of the first item to return.
1639
- * @param getTopSearches.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1640
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1641
- */
1642
- getTopSearches({ index, clickAnalytics, revenueAnalytics, startDate, endDate, orderBy, direction, limit, offset, tags, }, requestOptions) {
1643
- if (!index) {
1644
- throw new Error('Parameter `index` is required when calling `getTopSearches`.');
1645
- }
1646
- const requestPath = '/2/searches';
1647
- const headers = {};
1648
- const queryParameters = {};
1649
- if (index !== undefined) {
1650
- queryParameters.index = index.toString();
1651
- }
1652
- if (clickAnalytics !== undefined) {
1653
- queryParameters.clickAnalytics = clickAnalytics.toString();
1654
- }
1655
- if (revenueAnalytics !== undefined) {
1656
- queryParameters.revenueAnalytics = revenueAnalytics.toString();
1657
- }
1658
- if (startDate !== undefined) {
1659
- queryParameters.startDate = startDate.toString();
1660
- }
1661
- if (endDate !== undefined) {
1662
- queryParameters.endDate = endDate.toString();
1663
- }
1664
- if (orderBy !== undefined) {
1665
- queryParameters.orderBy = orderBy.toString();
1666
- }
1667
- if (direction !== undefined) {
1668
- queryParameters.direction = direction.toString();
1669
- }
1670
- if (limit !== undefined) {
1671
- queryParameters.limit = limit.toString();
1672
- }
1673
- if (offset !== undefined) {
1674
- queryParameters.offset = offset.toString();
1675
- }
1676
- if (tags !== undefined) {
1677
- queryParameters.tags = tags.toString();
1678
- }
1679
- const request = {
1680
- method: 'GET',
1681
- path: requestPath,
1682
- queryParameters,
1683
- headers,
1684
- };
1685
- return transporter.request(request, requestOptions);
1686
- },
1687
- /**
1688
- * Retrieves the number of unique users within a time range, including a daily breakdown. Since this endpoint 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. By default, the analyzed period includes the last eight days including the current day.
1689
- *
1690
- * Required API Key ACLs:
1691
- * - analytics.
1692
- *
1693
- * @param getUsersCount - The getUsersCount object.
1694
- * @param getUsersCount.index - Index name.
1695
- * @param getUsersCount.startDate - Start date of the period to analyze, in `YYYY-MM-DD` format.
1696
- * @param getUsersCount.endDate - End date of the period to analyze, in `YYYY-MM-DD` format.
1697
- * @param getUsersCount.tags - Tags by which to segment the analytics. You can combine multiple tags with `OR` and `AND`. Tags must be URL-encoded. For more information, see [Segment your analytics data](https://www.algolia.com/doc/guides/search-analytics/guides/segments/).
1698
- * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
1699
- */
1700
- getUsersCount({ index, startDate, endDate, tags }, requestOptions) {
1701
- if (!index) {
1702
- throw new Error('Parameter `index` is required when calling `getUsersCount`.');
1703
- }
1704
- const requestPath = '/2/users/count';
1705
- const headers = {};
1706
- const queryParameters = {};
1707
- if (index !== undefined) {
1708
- queryParameters.index = index.toString();
1709
- }
1710
- if (startDate !== undefined) {
1711
- queryParameters.startDate = startDate.toString();
1712
- }
1713
- if (endDate !== undefined) {
1714
- queryParameters.endDate = endDate.toString();
1715
- }
1716
- if (tags !== undefined) {
1717
- queryParameters.tags = tags.toString();
1718
- }
1719
- const request = {
1720
- method: 'GET',
1721
- path: requestPath,
1722
- queryParameters,
1723
- headers,
1724
- };
1725
- return transporter.request(request, requestOptions);
1726
- },
1727
- };
1728
- }
1729
-
1730
- // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT.
1731
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
1732
- function analyticsClient(appId, apiKey, region, options) {
1733
- if (!appId || typeof appId !== 'string') {
1734
- throw new Error('`appId` is missing.');
1735
- }
1736
- if (!apiKey || typeof apiKey !== 'string') {
1737
- throw new Error('`apiKey` is missing.');
1738
- }
1739
- if (region && (typeof region !== 'string' || !REGIONS.includes(region))) {
1740
- throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`);
1741
- }
1742
- return createAnalyticsClient({
1743
- appId,
1744
- apiKey,
1745
- region,
1746
- timeouts: {
1747
- connect: DEFAULT_CONNECT_TIMEOUT_BROWSER,
1748
- read: DEFAULT_READ_TIMEOUT_BROWSER,
1749
- write: DEFAULT_WRITE_TIMEOUT_BROWSER,
1750
- },
1751
- requester: createXhrRequester(),
1752
- algoliaAgents: [{ segment: 'Browser' }],
1753
- authMode: 'WithinQueryParameters',
1754
- responsesCache: createMemoryCache(),
1755
- requestsCache: createMemoryCache({ serializable: false }),
1756
- hostsCache: createFallbackableCache({
1757
- caches: [createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), createMemoryCache()],
1758
- }),
1759
- ...options,
1760
- });
1761
- }
1762
-
1763
- export { analyticsClient, apiClientVersion };