@algolia/client-analytics 5.3.0 → 5.3.2

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/dist/browser.d.ts CHANGED
@@ -1349,7 +1349,7 @@ type GetUsersCountResponse = {
1349
1349
  dates: DailyUsers[];
1350
1350
  };
1351
1351
 
1352
- declare const apiClientVersion = "5.3.0";
1352
+ declare const apiClientVersion = "5.3.2";
1353
1353
  declare const REGIONS: readonly ["de", "us"];
1354
1354
  type Region = (typeof REGIONS)[number];
1355
1355
  declare function createAnalyticsClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & {
@@ -11,7 +11,7 @@ import { createXhrRequester } from "@algolia/requester-browser-xhr";
11
11
 
12
12
  // src/analyticsClient.ts
13
13
  import { createAuth, createTransporter, getAlgoliaAgent } from "@algolia/client-common";
14
- var apiClientVersion = "5.3.0";
14
+ var apiClientVersion = "5.3.2";
15
15
  var REGIONS = ["de", "us"];
16
16
  function getDefaultHosts(region) {
17
17
  const url = !region ? "analytics.algolia.com" : "analytics.{region}.algolia.com".replace("{region}", region);
@@ -26,25 +26,26 @@ function createAnalyticsClient({
26
26
  ...options
27
27
  }) {
28
28
  const auth = createAuth(appIdOption, apiKeyOption, authMode);
29
- return {
30
- transporter: createTransporter({
31
- hosts: getDefaultHosts(regionOption),
32
- ...options,
33
- algoliaAgent: getAlgoliaAgent({
34
- algoliaAgents,
35
- client: "Analytics",
36
- version: apiClientVersion
37
- }),
38
- baseHeaders: {
39
- "content-type": "text/plain",
40
- ...auth.headers(),
41
- ...options.baseHeaders
42
- },
43
- baseQueryParameters: {
44
- ...auth.queryParameters(),
45
- ...options.baseQueryParameters
46
- }
29
+ const transporter = createTransporter({
30
+ hosts: getDefaultHosts(regionOption),
31
+ ...options,
32
+ algoliaAgent: getAlgoliaAgent({
33
+ algoliaAgents,
34
+ client: "Analytics",
35
+ version: apiClientVersion
47
36
  }),
37
+ baseHeaders: {
38
+ "content-type": "text/plain",
39
+ ...auth.headers(),
40
+ ...options.baseHeaders
41
+ },
42
+ baseQueryParameters: {
43
+ ...auth.queryParameters(),
44
+ ...options.baseQueryParameters
45
+ }
46
+ });
47
+ return {
48
+ transporter,
48
49
  /**
49
50
  * The `appId` currently in use.
50
51
  */
@@ -53,15 +54,13 @@ function createAnalyticsClient({
53
54
  * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties.
54
55
  */
55
56
  clearCache() {
56
- return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then(
57
- () => void 0
58
- );
57
+ return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => void 0);
59
58
  },
60
59
  /**
61
60
  * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system.
62
61
  */
63
62
  get _ua() {
64
- return this.transporter.algoliaAgent.value;
63
+ return transporter.algoliaAgent.value;
65
64
  },
66
65
  /**
67
66
  * Adds a `segment` to the `x-algolia-agent` sent with every requests.
@@ -70,7 +69,7 @@ function createAnalyticsClient({
70
69
  * @param version - The version of the agent.
71
70
  */
72
71
  addAlgoliaAgent(segment, version) {
73
- this.transporter.algoliaAgent.add({ segment, version });
72
+ transporter.algoliaAgent.add({ segment, version });
74
73
  },
75
74
  /**
76
75
  * Helper method to switch the API key used to authenticate the requests.
@@ -79,7 +78,11 @@ function createAnalyticsClient({
79
78
  * @param params.apiKey - The new API Key to use.
80
79
  */
81
80
  setClientApiKey({ apiKey }) {
82
- this.transporter.baseHeaders["x-algolia-api-key"] = apiKey;
81
+ if (!authMode || authMode === "WithinHeaders") {
82
+ transporter.baseHeaders["x-algolia-api-key"] = apiKey;
83
+ } else {
84
+ transporter.baseQueryParameters["x-algolia-api-key"] = apiKey;
85
+ }
83
86
  },
84
87
  /**
85
88
  * This method allow you to send requests to the Algolia REST API.
@@ -102,7 +105,7 @@ function createAnalyticsClient({
102
105
  queryParameters,
103
106
  headers
104
107
  };
105
- return this.transporter.request(request, requestOptions);
108
+ return transporter.request(request, requestOptions);
106
109
  },
107
110
  /**
108
111
  * This method allow you to send requests to the Algolia REST API.
@@ -125,7 +128,7 @@ function createAnalyticsClient({
125
128
  queryParameters,
126
129
  headers
127
130
  };
128
- return this.transporter.request(request, requestOptions);
131
+ return transporter.request(request, requestOptions);
129
132
  },
130
133
  /**
131
134
  * This method allow you to send requests to the Algolia REST API.
@@ -150,7 +153,7 @@ function createAnalyticsClient({
150
153
  headers,
151
154
  data: body ? body : {}
152
155
  };
153
- return this.transporter.request(request, requestOptions);
156
+ return transporter.request(request, requestOptions);
154
157
  },
155
158
  /**
156
159
  * This method allow you to send requests to the Algolia REST API.
@@ -175,7 +178,7 @@ function createAnalyticsClient({
175
178
  headers,
176
179
  data: body ? body : {}
177
180
  };
178
- return this.transporter.request(request, requestOptions);
181
+ return transporter.request(request, requestOptions);
179
182
  },
180
183
  /**
181
184
  * 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.
@@ -215,7 +218,7 @@ function createAnalyticsClient({
215
218
  queryParameters,
216
219
  headers
217
220
  };
218
- return this.transporter.request(request, requestOptions);
221
+ return transporter.request(request, requestOptions);
219
222
  },
220
223
  /**
221
224
  * 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.
@@ -255,7 +258,7 @@ function createAnalyticsClient({
255
258
  queryParameters,
256
259
  headers
257
260
  };
258
- return this.transporter.request(request, requestOptions);
261
+ return transporter.request(request, requestOptions);
259
262
  },
260
263
  /**
261
264
  * 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.
@@ -295,7 +298,7 @@ function createAnalyticsClient({
295
298
  queryParameters,
296
299
  headers
297
300
  };
298
- return this.transporter.request(request, requestOptions);
301
+ return transporter.request(request, requestOptions);
299
302
  },
300
303
  /**
301
304
  * 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.
@@ -335,7 +338,7 @@ function createAnalyticsClient({
335
338
  queryParameters,
336
339
  headers
337
340
  };
338
- return this.transporter.request(request, requestOptions);
341
+ return transporter.request(request, requestOptions);
339
342
  },
340
343
  /**
341
344
  * 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.
@@ -375,7 +378,7 @@ function createAnalyticsClient({
375
378
  queryParameters,
376
379
  headers
377
380
  };
378
- return this.transporter.request(request, requestOptions);
381
+ return transporter.request(request, requestOptions);
379
382
  },
380
383
  /**
381
384
  * 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.
@@ -415,7 +418,7 @@ function createAnalyticsClient({
415
418
  queryParameters,
416
419
  headers
417
420
  };
418
- return this.transporter.request(request, requestOptions);
421
+ return transporter.request(request, requestOptions);
419
422
  },
420
423
  /**
421
424
  * 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.
@@ -455,7 +458,7 @@ function createAnalyticsClient({
455
458
  queryParameters,
456
459
  headers
457
460
  };
458
- return this.transporter.request(request, requestOptions);
461
+ return transporter.request(request, requestOptions);
459
462
  },
460
463
  /**
461
464
  * 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.
@@ -495,7 +498,7 @@ function createAnalyticsClient({
495
498
  queryParameters,
496
499
  headers
497
500
  };
498
- return this.transporter.request(request, requestOptions);
501
+ return transporter.request(request, requestOptions);
499
502
  },
500
503
  /**
501
504
  * 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.
@@ -535,7 +538,7 @@ function createAnalyticsClient({
535
538
  queryParameters,
536
539
  headers
537
540
  };
538
- return this.transporter.request(request, requestOptions);
541
+ return transporter.request(request, requestOptions);
539
542
  },
540
543
  /**
541
544
  * 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.
@@ -575,7 +578,7 @@ function createAnalyticsClient({
575
578
  queryParameters,
576
579
  headers
577
580
  };
578
- return this.transporter.request(request, requestOptions);
581
+ return transporter.request(request, requestOptions);
579
582
  },
580
583
  /**
581
584
  * Retrieves the most popular searches that didn\'t lead to any clicks, from the 1,000 most frequent searches.
@@ -623,7 +626,7 @@ function createAnalyticsClient({
623
626
  queryParameters,
624
627
  headers
625
628
  };
626
- return this.transporter.request(request, requestOptions);
629
+ return transporter.request(request, requestOptions);
627
630
  },
628
631
  /**
629
632
  * Retrieves the most popular searches that didn\'t return any results.
@@ -671,7 +674,7 @@ function createAnalyticsClient({
671
674
  queryParameters,
672
675
  headers
673
676
  };
674
- return this.transporter.request(request, requestOptions);
677
+ return transporter.request(request, requestOptions);
675
678
  },
676
679
  /**
677
680
  * Retrieves the time when the Analytics data for the specified index was last updated. The Analytics data is updated every 5 minutes.
@@ -699,7 +702,7 @@ function createAnalyticsClient({
699
702
  queryParameters,
700
703
  headers
701
704
  };
702
- return this.transporter.request(request, requestOptions);
705
+ return transporter.request(request, requestOptions);
703
706
  },
704
707
  /**
705
708
  * Retrieves the countries with the most searches to your index.
@@ -747,7 +750,7 @@ function createAnalyticsClient({
747
750
  queryParameters,
748
751
  headers
749
752
  };
750
- return this.transporter.request(request, requestOptions);
753
+ return transporter.request(request, requestOptions);
751
754
  },
752
755
  /**
753
756
  * Retrieves the most frequently used filter attributes. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -799,7 +802,7 @@ function createAnalyticsClient({
799
802
  queryParameters,
800
803
  headers
801
804
  };
802
- return this.transporter.request(request, requestOptions);
805
+ return transporter.request(request, requestOptions);
803
806
  },
804
807
  /**
805
808
  * Retrieves the most frequent filter (facet) values for a filter attribute. These are attributes of your records that you included in the `attributesForFaceting` setting.
@@ -855,7 +858,7 @@ function createAnalyticsClient({
855
858
  queryParameters,
856
859
  headers
857
860
  };
858
- return this.transporter.request(request, requestOptions);
861
+ return transporter.request(request, requestOptions);
859
862
  },
860
863
  /**
861
864
  * 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.
@@ -907,7 +910,7 @@ function createAnalyticsClient({
907
910
  queryParameters,
908
911
  headers
909
912
  };
910
- return this.transporter.request(request, requestOptions);
913
+ return transporter.request(request, requestOptions);
911
914
  },
912
915
  /**
913
916
  * Retrieves the object IDs of the most frequent search results.
@@ -967,7 +970,7 @@ function createAnalyticsClient({
967
970
  queryParameters,
968
971
  headers
969
972
  };
970
- return this.transporter.request(request, requestOptions);
973
+ return transporter.request(request, requestOptions);
971
974
  },
972
975
  /**
973
976
  * Returns the most popular search terms.
@@ -1042,7 +1045,7 @@ function createAnalyticsClient({
1042
1045
  queryParameters,
1043
1046
  headers
1044
1047
  };
1045
- return this.transporter.request(request, requestOptions);
1048
+ return transporter.request(request, requestOptions);
1046
1049
  },
1047
1050
  /**
1048
1051
  * 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.
@@ -1082,7 +1085,7 @@ function createAnalyticsClient({
1082
1085
  queryParameters,
1083
1086
  headers
1084
1087
  };
1085
- return this.transporter.request(request, requestOptions);
1088
+ return transporter.request(request, requestOptions);
1086
1089
  }
1087
1090
  };
1088
1091
  }