Skip to content

Commit 3e4c180

Browse files
authored
feat(insights): update default version to support authenticatedUserToken (#1225)
1 parent b7606d5 commit 3e4c180

File tree

9 files changed

+26
-16
lines changed

9 files changed

+26
-16
lines changed

examples/playground/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@algolia/client-search": "4.16.0",
1818
"algoliasearch": "4.16.0",
1919
"preact": "10.13.2",
20-
"search-insights": "2.6.0"
20+
"search-insights": "2.13.0"
2121
},
2222
"devDependencies": {
2323
"parcel": "2.8.3"

examples/query-suggestions-with-hits/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@algolia/client-search": "4.16.0",
1818
"algoliasearch": "4.16.0",
1919
"preact": "10.13.2",
20-
"search-insights": "2.6.0"
20+
"search-insights": "2.13.0"
2121
},
2222
"devDependencies": {
2323
"parcel": "2.8.3"

examples/reshape/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"algoliasearch": "4.16.0",
2020
"preact": "10.13.2",
2121
"ramda": "0.27.1",
22-
"search-insights": "2.6.0"
22+
"search-insights": "2.13.0"
2323
},
2424
"devDependencies": {
2525
"@algolia/autocomplete-core": "1.12.2",

examples/tags-in-searchbox/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"algoliasearch": "4.16.0",
1717
"preact": "10.13.2",
1818
"ramda": "0.27.1",
19-
"search-insights": "2.6.0"
19+
"search-insights": "2.13.0"
2020
},
2121
"devDependencies": {
2222
"parcel": "2.8.3"

examples/tags-with-hits/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"algoliasearch": "4.16.0",
1717
"preact": "10.13.2",
1818
"ramda": "0.27.1",
19-
"search-insights": "2.6.0"
19+
"search-insights": "2.13.0"
2020
},
2121
"devDependencies": {
2222
"parcel": "2.8.3"

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"rollup-plugin-license": "2.9.1",
8181
"rollup-plugin-terser": "7.0.2",
8282
"shipjs": "0.26.1",
83-
"search-insights": "2.6.0",
83+
"search-insights": "2.13.0",
8484
"start-server-and-test": "1.15.2",
8585
"stylelint": "13.13.1",
8686
"stylelint-a11y": "1.2.3",

packages/autocomplete-plugin-algolia-insights/src/__tests__/createAlgoliaInsightsPlugin.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe('createAlgoliaInsightsPlugin', () => {
294294
expect(document.body).toMatchInlineSnapshot(`
295295
<body>
296296
<script
297-
src="https://cdn.jsdelivr.net/npm/search-insights@2.6.0/dist/search-insights.min.js"
297+
src="https://cdn.jsdelivr.net/npm/search-insights@2.13.0/dist/search-insights.min.js"
298298
/>
299299
<form>
300300
<input />
@@ -306,7 +306,7 @@ describe('createAlgoliaInsightsPlugin', () => {
306306
`);
307307
expect((window as any).AlgoliaAnalyticsObject).toBe('aa');
308308
expect((window as any).aa).toEqual(expect.any(Function));
309-
expect((window as any).aa.version).toBe('2.6.0');
309+
expect((window as any).aa.version).toBe('2.13.0');
310310
});
311311

312312
it('notifies when the script fails to be added', () => {
@@ -867,7 +867,7 @@ describe('createAlgoliaInsightsPlugin', () => {
867867
test('sends a `clickedObjectIDsAfterSearch` event with additional parameters if client supports it', async () => {
868868
const insightsClient = jest.fn();
869869
// @ts-ignore
870-
insightsClient.version = '2.6.0';
870+
insightsClient.version = '2.13.0';
871871
const insightsPlugin = createAlgoliaInsightsPlugin({ insightsClient });
872872

873873
const { inputElement } = createPlayground(createAutocomplete, {

packages/autocomplete-plugin-algolia-insights/src/createAlgoliaInsightsPlugin.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from './types';
2727

2828
const VIEW_EVENT_DELAY = 400;
29-
const ALGOLIA_INSIGHTS_VERSION = '2.6.0';
29+
const ALGOLIA_INSIGHTS_VERSION = '2.13.0';
3030
const ALGOLIA_INSIGHTS_SRC = `https://cdn.jsdelivr.net/npm/search-insights@${ALGOLIA_INSIGHTS_VERSION}/dist/search-insights.min.js`;
3131

3232
type SendViewedObjectIDsParams = {
@@ -170,14 +170,16 @@ export function createAlgoliaInsightsPlugin(
170170
return {
171171
name: 'aa.algoliaInsightsPlugin',
172172
subscribe({ setContext, onSelect, onActive }) {
173-
function setInsightsContext(userToken?: string) {
173+
function setInsightsContext(userToken?: string | number) {
174174
setContext({
175175
algoliaInsightsPlugin: {
176176
__algoliaSearchParameters: {
177177
...(__autocomplete_clickAnalytics
178178
? { clickAnalytics: true }
179179
: {}),
180-
...(userToken ? { userToken } : {}),
180+
...(userToken
181+
? { userToken: normalizeUserToken(userToken) }
182+
: {}),
181183
},
182184
insights,
183185
},
@@ -304,3 +306,11 @@ function loadInsights(environment: typeof window) {
304306
console.error(errorMessage);
305307
}
306308
}
309+
310+
/**
311+
* While `search-insights` supports both string and number user tokens,
312+
* the Search API only accepts strings. This function normalizes the user token.
313+
*/
314+
function normalizeUserToken(userToken: string | number): string {
315+
return typeof userToken === 'number' ? userToken.toString() : userToken;
316+
}

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -17380,10 +17380,10 @@ schema-utils@^3.0.0, schema-utils@^3.1.1:
1738017380
ajv "^6.12.5"
1738117381
ajv-keywords "^3.5.2"
1738217382

17383-
search-insights@2.6.0:
17384-
version "2.6.0"
17385-
resolved "https://registry.yarnpkg.com/search-insights/-/search-insights-2.6.0.tgz#bb8771a73b83c4a0f1f207c2f64fea01acd3e7d0"
17386-
integrity sha512-vU2/fJ+h/Mkm/DJOe+EaM5cafJv/1rRTZpGJTuFPf/Q5LjzgMDsqPdSaZsAe+GAWHHsfsu+rQSAn6c8IGtBEVw==
17383+
search-insights@2.13.0:
17384+
version "2.13.0"
17385+
resolved "https://registry.yarnpkg.com/search-insights/-/search-insights-2.13.0.tgz#a79fdcf4b5dad2fba8975b06f2ebc37a865032b7"
17386+
integrity sha512-Orrsjf9trHHxFRuo9/rzm0KIWmgzE8RMlZMzuhZOJ01Rnz3D0YBAe+V6473t6/H6c7irs6Lt48brULAiRWb3Vw==
1738717387

1738817388
search-insights@^2.1.0:
1738917389
version "2.2.1"

0 commit comments

Comments
 (0)