Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(insights): require optin for insights option #5578

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure-r
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
facetFilters: ['objectID:-1'],
tagFilters: '',
Expand Down Expand Up @@ -169,7 +168,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure-r
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
facetFilters: ['objectID:-1'],
tagFilters: '',
Expand Down Expand Up @@ -215,7 +213,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/configure-r
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
facetFilters: ['objectID:-1'],
tagFilters: '',
Expand Down Expand Up @@ -279,7 +276,6 @@ See https://www.algolia.com/doc/api-reference/api-parameters/optionalFilters/`);
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
facetFilters: ['objectID:-1'],
tagFilters: '',
Expand Down
6 changes: 3 additions & 3 deletions packages/instantsearch.js/src/lib/InstantSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ export type InstantSearchOptions<
routing?: RouterProps<TUiState, TRouteState> | boolean;

/**
* Automatically enables the Insights middleware and loads the Insights library
* Enables the Insights middleware and loads the Insights library
* if not already loaded.
*
* The Insights middleware sends view and click events automatically, and lets
* you set up your own events.
*
* @default true
* @default false
*/
insights?: InsightsProps | boolean;

Expand Down Expand Up @@ -228,7 +228,7 @@ Use \`InstantSearch.status === "stalled"\` instead.`
numberLocale,
initialUiState = {} as TUiState,
routing = null,
insights = true,
insights = false,
searchFunction,
stalledSearchDelay = 200,
searchClient = null,
Expand Down
24 changes: 5 additions & 19 deletions packages/instantsearch.js/src/lib/__tests__/InstantSearch-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
});

describe('insights middleware', () => {
test('adds insights middleware by default', () => {
test('does not add insights middleware by default', () => {
const search = new InstantSearch({
searchClient: createSearchClient(),
indexName: 'test',
Expand All @@ -440,15 +440,10 @@ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
$$type,
$$internal,
}))
).toEqual([
{
$$type: 'ais.insights',
$$internal: true,
},
]);
).toEqual([]);
});

test('insights: true still adds only one middleware', () => {
test('insights: true adds only one insights middleware', () => {
const search = new InstantSearch({
searchClient: createSearchClient(),
indexName: 'test',
Expand All @@ -468,7 +463,7 @@ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
]);
});

test('insights: options still creates one middleware only', () => {
test('insights: options adds only one insights middleware', () => {
const search = new InstantSearch({
searchClient: createSearchClient(),
indexName: 'test',
Expand Down Expand Up @@ -610,12 +605,7 @@ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
$$type,
$$internal,
}))
).toEqual([
{
$$type: 'ais.insights',
$$internal: true,
},
]);
).toEqual([]);
});

it('adds metadata middleware on the Crawler user agent', () => {
Expand All @@ -632,10 +622,6 @@ See https://www.algolia.com/doc/api-reference/widgets/configure/js/`);
$$internal,
}))
).toEqual([
{
$$type: 'ais.insights',
$$internal: true,
},
{
$$type: 'ais.metadata',
$$internal: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('createMetadataMiddleware', () => {
expect(document.head).toMatchInlineSnapshot(`
<head>
<meta
content="{\\"widgets\\":[{\\"type\\":\\"ais.searchBox\\",\\"widgetType\\":\\"ais.searchBox\\",\\"params\\":[]},{\\"type\\":\\"ais.searchBox\\",\\"widgetType\\":\\"ais.searchBox\\",\\"params\\":[]},{\\"type\\":\\"ais.hits\\",\\"widgetType\\":\\"ais.hits\\",\\"params\\":[\\"escapeHTML\\"]},{\\"type\\":\\"ais.index\\",\\"widgetType\\":\\"ais.index\\",\\"params\\":[]},{\\"type\\":\\"ais.pagination\\",\\"widgetType\\":\\"ais.pagination\\",\\"params\\":[]},{\\"type\\":\\"ais.configure\\",\\"widgetType\\":\\"ais.configure\\",\\"params\\":[\\"searchParameters\\"]},{\\"middleware\\":true,\\"type\\":\\"ais.insights\\",\\"internal\\":true},{\\"middleware\\":true,\\"type\\":\\"ais.metadata\\",\\"internal\\":true}]}"
content="{\\"widgets\\":[{\\"type\\":\\"ais.searchBox\\",\\"widgetType\\":\\"ais.searchBox\\",\\"params\\":[]},{\\"type\\":\\"ais.searchBox\\",\\"widgetType\\":\\"ais.searchBox\\",\\"params\\":[]},{\\"type\\":\\"ais.hits\\",\\"widgetType\\":\\"ais.hits\\",\\"params\\":[\\"escapeHTML\\"]},{\\"type\\":\\"ais.index\\",\\"widgetType\\":\\"ais.index\\",\\"params\\":[]},{\\"type\\":\\"ais.pagination\\",\\"widgetType\\":\\"ais.pagination\\",\\"params\\":[]},{\\"type\\":\\"ais.configure\\",\\"widgetType\\":\\"ais.configure\\",\\"params\\":[\\"searchParameters\\"]},{\\"middleware\\":true,\\"type\\":\\"ais.metadata\\",\\"internal\\":true}]}"
name="instantsearch:widgets"
/>
</head>
Expand Down Expand Up @@ -171,11 +171,6 @@ describe('createMetadataMiddleware', () => {
"type": "ais.configure",
"widgetType": "ais.configure",
},
{
"internal": true,
"middleware": true,
"type": "ais.insights",
},
{
"internal": true,
"middleware": true,
Expand Down Expand Up @@ -207,7 +202,7 @@ describe('createMetadataMiddleware', () => {
expect(document.head).toMatchInlineSnapshot(`
<head>
<meta
content="{\\"widgets\\":[{\\"middleware\\":true,\\"type\\":\\"ais.router({router:ais.browser, stateMapping:ais.simple})\\",\\"internal\\":true},{\\"middleware\\":true,\\"type\\":\\"ais.insights\\",\\"internal\\":true},{\\"middleware\\":true,\\"type\\":\\"ais.metadata\\",\\"internal\\":true},{\\"middleware\\":true,\\"type\\":\\"test\\",\\"internal\\":false},{\\"middleware\\":true,\\"type\\":\\"__unknown__\\",\\"internal\\":false}]}"
content="{\\"widgets\\":[{\\"middleware\\":true,\\"type\\":\\"ais.router({router:ais.browser, stateMapping:ais.simple})\\",\\"internal\\":true},{\\"middleware\\":true,\\"type\\":\\"ais.metadata\\",\\"internal\\":true},{\\"middleware\\":true,\\"type\\":\\"test\\",\\"internal\\":false},{\\"middleware\\":true,\\"type\\":\\"__unknown__\\",\\"internal\\":false}]}"
name="instantsearch:widgets"
/>
</head>
Expand All @@ -221,11 +216,6 @@ describe('createMetadataMiddleware', () => {
"middleware": true,
"type": "ais.router({router:ais.browser, stateMapping:ais.simple})",
},
{
"internal": true,
"middleware": true,
"type": "ais.insights",
},
{
"internal": true,
"middleware": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
{
indexName: 'test',
params: {
clickAnalytics: true,
facets: ['hierarchy.1'],
maxValuesPerFacet: 10,
tagFilters: '',
Expand All @@ -366,7 +365,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/hierarchica
{
indexName: 'test',
params: {
clickAnalytics: true,
facetFilters: [['hierarchy.1:zero']],
facets: ['hierarchy.1', 'hierarchy.2'],
maxValuesPerFacet: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3017,7 +3017,6 @@ See documentation: https://www.algolia.com/doc/api-reference/widgets/index-widge
],
_state: {
index: 'indexName',
clickAnalytics: true,
disjunctiveFacets: [],
disjunctiveFacetsRefinements: {},
facets: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ describe('menuSelect', () => {
expect(search.helper!.state).toEqual(
new SearchParameters({
index: 'test',
clickAnalytics: true,
})
);

Expand All @@ -249,7 +248,6 @@ describe('menuSelect', () => {
expect(search.helper!.state).toEqual(
new SearchParameters({
index: 'test',
clickAnalytics: true,
hierarchicalFacets: [{ attributes: ['test'], name: 'test' }],
hierarchicalFacetsRefinements: { test: [] },
maxValuesPerFacet: 10,
Expand All @@ -263,7 +261,7 @@ describe('menuSelect', () => {
expect(render).toHaveBeenCalledTimes(2);
expect(render).toHaveBeenLastCalledWith(null, container);
expect(search.helper!.state).toEqual(
new SearchParameters({ index: 'test', clickAnalytics: true })
new SearchParameters({ index: 'test' })
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`getServerState returns initialResults 1`] = `
"nbHits": 0,
"nbPages": 0,
"page": 0,
"params": "clickAnalytics=true&facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"params": "facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"processingTimeMS": 0,
"query": "",
},
Expand All @@ -32,7 +32,6 @@ exports[`getServerState returns initialResults 1`] = `
},
],
"state": {
"clickAnalytics": true,
"disjunctiveFacets": [
"brand",
],
Expand Down Expand Up @@ -66,7 +65,7 @@ exports[`getServerState returns initialResults 1`] = `
"nbHits": 0,
"nbPages": 0,
"page": 0,
"params": "clickAnalytics=true&facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"params": "facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"processingTimeMS": 0,
"query": "",
},
Expand Down Expand Up @@ -110,7 +109,7 @@ exports[`getServerState returns initialResults 1`] = `
"nbHits": 0,
"nbPages": 0,
"page": 0,
"params": "clickAnalytics=true&facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"params": "facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"processingTimeMS": 0,
"query": "",
},
Expand Down Expand Up @@ -154,7 +153,7 @@ exports[`getServerState returns initialResults 1`] = `
"nbHits": 0,
"nbPages": 0,
"page": 0,
"params": "clickAnalytics=true&facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"params": "facetFilters=%5B%5B%22brand%3AApple%22%5D%5D&facets=%5B%22brand%22%5D&highlightPostTag=__%2Fais-highlight__&highlightPreTag=__ais-highlight__&maxValuesPerFacet=10&query=iphone&tagFilters=",
"processingTimeMS": 0,
"query": "",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ describe('getServerState', () => {
{
indexName: 'instant_search',
params: {
clickAnalytics: true,
facetFilters: [['brand:Apple']],
facets: ['brand'],
highlightPostTag: '__/ais-highlight__',
Expand All @@ -223,7 +222,6 @@ describe('getServerState', () => {
{
indexName: 'instant_search_price_asc',
params: {
clickAnalytics: true,
facetFilters: [['brand:Apple']],
facets: ['brand'],
highlightPostTag: '__/ais-highlight__',
Expand All @@ -250,7 +248,6 @@ describe('getServerState', () => {
{
indexName: 'instant_search_rating_desc',
params: {
clickAnalytics: true,
facetFilters: [['brand:Apple']],
facets: ['brand'],
highlightPostTag: '__/ais-highlight__',
Expand All @@ -277,7 +274,6 @@ describe('getServerState', () => {
{
indexName: 'instant_search_price_desc',
params: {
clickAnalytics: true,
facetFilters: [['brand:Apple']],
facets: ['brand'],
highlightPostTag: '__/ais-highlight__',
Expand Down Expand Up @@ -387,7 +383,6 @@ describe('getServerState', () => {
expect(searchClient.search.mock.calls[0][0][0]).toEqual({
indexName: 'instant_search',
params: {
clickAnalytics: true,
facets: ['*'],
highlightPostTag: '__/ais-highlight__',
highlightPreTag: '__ais-highlight__',
Expand All @@ -401,7 +396,6 @@ describe('getServerState', () => {
expect(searchClient.search.mock.calls[1][0][0]).toEqual({
indexName: 'instant_search',
params: {
clickAnalytics: true,
facetFilters: [['categories:refined!']],
facets: ['*'],
highlightPostTag: '__/ais-highlight__',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ describe('InfiniteHits', () => {
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
highlightPostTag: '__/ais-highlight__',
highlightPreTag: '__ais-highlight__',
Expand All @@ -224,7 +223,6 @@ describe('InfiniteHits', () => {
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
highlightPostTag: '__/ais-highlight__',
highlightPreTag: '__ais-highlight__',
Expand Down Expand Up @@ -260,7 +258,6 @@ describe('InfiniteHits', () => {
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
highlightPostTag: '__/ais-highlight__',
highlightPreTag: '__ais-highlight__',
Expand All @@ -284,7 +281,6 @@ describe('InfiniteHits', () => {
{
indexName: 'indexName',
params: {
clickAnalytics: true,
facets: [],
highlightPostTag: '__/ais-highlight__',
highlightPreTag: '__ais-highlight__',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ describe('ToggleRefinement', () => {
expect.arrayContaining([
expect.objectContaining({
params: {
clickAnalytics: true,
facetFilters: [['free_shipping:true']],
facets: ['free_shipping'],
tagFilters: '',
Expand Down Expand Up @@ -157,7 +156,6 @@ describe('ToggleRefinement', () => {
expect.arrayContaining([
expect.objectContaining({
params: {
clickAnalytics: true,
facetFilters: [['free_shipping:yes']],
facets: ['free_shipping'],
tagFilters: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ describe('insights', () => {

render(
<StrictMode>
<InstantSearch searchClient={searchClient} indexName="123" />
<InstantSearch
searchClient={searchClient}
indexName="123"
insights={true}
/>
</StrictMode>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,11 @@ describe('InstantSearch', () => {
expect(searchClient.search).toHaveBeenLastCalledWith([
{
indexName: 'indexName',
params: { clickAnalytics: true, facets: [], query: '', tagFilters: '' },
params: { facets: [], query: '', tagFilters: '' },
},
{
indexName: 'subIndexName',
params: {
clickAnalytics: true,
facets: ['brand'],
maxValuesPerFacet: 10,
query: '',
Expand Down Expand Up @@ -217,12 +216,11 @@ describe('InstantSearch', () => {
expect(searchClient.search).toHaveBeenLastCalledWith([
{
indexName: 'indexName',
params: { clickAnalytics: true, facets: [], query: '', tagFilters: '' },
params: { facets: [], query: '', tagFilters: '' },
},
{
indexName: 'subIndexName',
params: {
clickAnalytics: true,
facets: ['brand'],
maxValuesPerFacet: 10,
query: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ describe('useConnector', () => {
});

const helperState = {
clickAnalytics: true,
disjunctiveFacets: [],
disjunctiveFacetsRefinements: {},
facets: [],
Expand Down
Loading