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): add "insights" option for automatic events #5490

Merged
merged 22 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c4a7510
feat(insights): automatically load search-insights if not passed (#5484)
Haroenv Feb 21, 2023
fe958d6
feat(insights): prevent potential errors (#5487)
Haroenv Feb 21, 2023
95fcba2
feat(insights): automatically add insights middleware (#5488)
Haroenv Feb 23, 2023
99686da
feat(insights): option to disable automatic insights middleware (#5493)
Haroenv Feb 23, 2023
a1e42c5
fix(userToken): prevent search waterfall (#5512)
Haroenv Feb 28, 2023
56205ac
feat(metadata): register metadata around middleware (#5492)
Haroenv Mar 1, 2023
2e05291
feat(insights): enable default click events on hits and infinite hits…
sarahdayan Mar 3, 2023
45f9e01
refactor(bindEvent): move listener inside components (#5528)
Haroenv Mar 8, 2023
bc69429
fix(insights): user-defined send/bindEvent overrides internal click (…
Haroenv Mar 16, 2023
df2af08
feat(hits/infinite-hits): send a default click event and expose sendE…
Haroenv Mar 16, 2023
157004f
feat(insights): allow passing options to default middleware (#5545)
Haroenv Mar 16, 2023
e939cf1
feat(createInsightsMiddleware): always pass Algolia credentials local…
sarahdayan Mar 20, 2023
4c3b5ee
fix(insights): keep track of script loading in global (#5551)
Haroenv Mar 20, 2023
f99eb06
fix(insights): send extra parameters only for applicable versions (#5…
Haroenv Mar 23, 2023
3c0486f
fix(insights): only load script if we write window.aa (#5559)
Haroenv Apr 4, 2023
edd001a
feat(insights): require optin for insights option (#5578)
Haroenv Apr 5, 2023
f2ab2fc
feat(insights): annotate events with algoliaSource (#5580)
Haroenv Apr 6, 2023
fa98e21
fix(insights): only `init` if `version` allows it (#5529)
FabienMotte Apr 12, 2023
38f4f0e
feat(insights): remove useCookie from default parameters (#5606)
Haroenv Apr 21, 2023
94bb61e
Merge branch 'master' into feat/automatic-insights
Haroenv Apr 21, 2023
e789b6c
docs(examples): add insights to all examples (#5607)
Haroenv Apr 24, 2023
fd74f9e
refactor(sendEventForHits): remove indirection (#5608)
Haroenv Apr 24, 2023
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
12 changes: 6 additions & 6 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"files": [
{
"path": "./packages/instantsearch.js/dist/instantsearch.production.min.js",
"maxSize": "74 kB"
"maxSize": "74.25 kB"
},
{
"path": "./packages/instantsearch.js/dist/instantsearch.development.js",
"maxSize": "160 kB"
"maxSize": "165 kB"
},
{
"path": "packages/react-instantsearch/dist/umd/Core.min.js",
Expand All @@ -26,11 +26,11 @@
},
{
"path": "packages/react-instantsearch-hooks/dist/umd/ReactInstantSearchHooks.min.js",
"maxSize": "42.25 kB"
"maxSize": "44.50 kB"
},
{
"path": "packages/react-instantsearch-hooks-web/dist/umd/ReactInstantSearchHooksDOM.min.js",
"maxSize": "51.50 kB"
"maxSize": "53.50 kB"
},
{
"path": "packages/react-instantsearch-dom/dist/umd/ReactInstantSearchDOM.min.js",
Expand All @@ -42,11 +42,11 @@
},
{
"path": "packages/vue-instantsearch/vue2/umd/index.js",
"maxSize": "60 kB"
"maxSize": "62 kB"
},
{
"path": "packages/vue-instantsearch/vue3/umd/index.js",
"maxSize": "60.25 kB"
"maxSize": "62.25 kB"
},
{
"path": "packages/vue-instantsearch/vue2/cjs/index.js",
Expand Down
1 change: 1 addition & 0 deletions examples/js/calendar-widget/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const search = instantsearch({
indexName: 'concert_events_instantsearchjs',
searchClient: algoliasearch('latency', '059c79ddd276568e990286944276464a'),
routing: true,
insights: true,
});

search.addWidgets([
Expand Down
1 change: 1 addition & 0 deletions examples/js/e-commerce/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const search = instantsearch({
searchClient,
indexName: 'instant_search',
routing: getRouting({ indexName: 'instant_search' }),
insights: true,
});

search.addWidgets([
Expand Down
1 change: 1 addition & 0 deletions examples/js/getting-started/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const searchClient = algoliasearch(
const search = instantsearch({
indexName: 'instant_search',
searchClient,
insights: true,
});

search.addWidgets([
Expand Down
1 change: 1 addition & 0 deletions examples/js/media/src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const search = instantsearch({
routing: {
stateMapping: singleIndex('PROD_algolia_blog'),
},
insights: true,
});

const datesDesktop = createDates({
Expand Down
1 change: 1 addition & 0 deletions examples/js/tourism/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const search = instantsearch({
searchClient: algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76'),
indexName: 'airbnb',
routing: true,
insights: true,
});

search.addWidgets([
Expand Down
1 change: 1 addition & 0 deletions examples/react-hooks/default-theme/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function App() {
searchClient={searchClient}
indexName="instant_search"
routing={true}
insights={true}
>
<Configure ruleContexts={[]} />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import './Refresh.css';

export function Refresh() {
const { refresh } = useInstantSearch();

return (
<button
className="Refresh"
Expand Down
1 change: 1 addition & 0 deletions examples/react-hooks/e-commerce/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function App() {
searchClient={searchClient}
indexName={indexName}
routing={routing}
insights={true}
>
<header className="header" ref={headerRef}>
<p className="header-logo">
Expand Down
6 changes: 5 additions & 1 deletion examples/react-hooks/getting-started/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export function App() {
</header>

<div className="container">
<InstantSearch searchClient={searchClient} indexName="instant_search">
<InstantSearch
searchClient={searchClient}
indexName="instant_search"
insights={true}
>
<Configure hitsPerPage={8} />
<div className="search-panel">
<div className="search-panel__filters">
Expand Down
1 change: 1 addition & 0 deletions examples/react-hooks/next-routing/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function HomePage({ serverState, url }: HomePageProps) {
serverUrl: url,
}),
}}
insights={true}
>
<div className="Container">
<div>
Expand Down
1 change: 1 addition & 0 deletions examples/react-hooks/next/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default function HomePage({ serverState, url }: HomePageProps) {
singletonRouter,
}),
}}
insights={true}
>
<div className="Container">
<div>
Expand Down
1 change: 1 addition & 0 deletions examples/react-hooks/ssr/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function App({ serverState, location }) {
},
}),
}}
insights={true}
>
<Configure hitsPerPage={10} />

Expand Down
1 change: 1 addition & 0 deletions examples/vue/default-theme/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:search-client="searchClient"
index-name="instant_search"
:routing="routing"
:insights="true"
>
<ais-configure :hits-per-page.camel="16" />

Expand Down
1 change: 1 addition & 0 deletions examples/vue/e-commerce/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:search-client="searchClient"
index-name="instant_search"
:routing="routing"
:insights="true"
>
<ais-configure
:attributes-to-snippet.camel="['description:10']"
Expand Down
1 change: 1 addition & 0 deletions examples/vue/getting-started/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ais-instant-search
:search-client="searchClient"
index-name="instant_search"
:insights="true"
>
<ais-configure :hits-per-page.camel="8" />
<div class="search-panel">
Expand Down
1 change: 1 addition & 0 deletions examples/vue/media/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:search-client="searchClient"
index-name="movies"
:routing="routing"
:insights="true"
>
<header class="navbar">
<img
Expand Down
1 change: 1 addition & 0 deletions examples/vue/nuxt/pages/search.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default {
createServerRootMixin({
searchClient,
indexName: 'instant_search',
insights: true,
initialUiState: {
// eslint-disable-next-line camelcase
instant_search: {
Expand Down
1 change: 1 addition & 0 deletions examples/vue/ssr/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function createApp({
createServerRootMixin({
searchClient,
indexName: 'instant_search',
insights: true,
routing: {
router: {
read() {
Expand Down
2 changes: 1 addition & 1 deletion packages/instantsearch.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"htm": "^3.0.0",
"preact": "^10.10.0",
"qs": "^6.5.1 < 6.10",
"search-insights": "^2.1.0"
"search-insights": "^2.6.0"
},
"peerDependencies": {
"algoliasearch": ">= 3.1 < 6"
Expand Down
111 changes: 111 additions & 0 deletions packages/instantsearch.js/src/__tests__/common.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createPaginationTests,
createMenuTests,
createInfiniteHitsTests,
createHitsTests,
} from '@instantsearch/tests';

import instantsearch from '../index.es';
Expand All @@ -19,6 +20,8 @@ import {
pagination,
infiniteHits,
searchBox,
hits,
index,
} from '../widgets';

createHierarchicalMenuTests(({ instantSearchOptions, widgetParams }) => {
Expand Down Expand Up @@ -120,9 +123,117 @@ createInfiniteHitsTests(({ instantSearchOptions, widgetParams }) => {
container: document.body.appendChild(document.createElement('div')),
}),
infiniteHits({
container: document.body.appendChild(
Object.assign(document.createElement('div'), {
id: 'main-hits',
})
),
templates: {
item: (hit, { html, sendEvent }) =>
html`<div data-testid=${`main-hits-top-level-${hit.__position}`}>
${hit.objectID}
<button
data-testid=${`main-hits-convert-${hit.__position}`}
onClick=${() => sendEvent('conversion', hit, 'Converted')}
>
convert
</button>
<button
data-testid=${`main-hits-click-${hit.__position}`}
onClick=${() => sendEvent('click', hit, 'Clicked')}
>
click
</button>
</div>`,
},
...widgetParams,
}),
index({ indexName: 'nested' }).addWidgets([
infiniteHits({
container: document.body.appendChild(
Object.assign(document.createElement('div'), {
id: 'nested-hits',
})
),
templates: {
item: (hit, { html, sendEvent }) =>
html`<div
data-testid=${`nested-hits-top-level-${hit.__position}`}
>
${hit.objectID}
<button
data-testid=${`nested-hits-click-${hit.__position}`}
onClick=${() => sendEvent('click', hit, 'Clicked nested')}
>
click
</button>
</div>`,
},
}),
]),
])
.on('error', () => {
/*
* prevent rethrowing InstantSearch errors, so tests can be asserted.
* IRL this isn't needed, as the error doesn't stop execution.
*/
})
.start();
});

createHitsTests(({ instantSearchOptions, widgetParams }) => {
instantsearch(instantSearchOptions)
.addWidgets([
searchBox({
container: document.body.appendChild(document.createElement('div')),
}),
hits({
container: document.body.appendChild(
Object.assign(document.createElement('div'), {
id: 'main-hits',
})
),
templates: {
item: (hit, { html, sendEvent }) =>
html`<div data-testid=${`main-hits-top-level-${hit.__position}`}>
${hit.objectID}
<button
data-testid=${`main-hits-convert-${hit.__position}`}
onClick=${() => sendEvent('conversion', hit, 'Converted')}
>
convert
</button>
<button
data-testid=${`main-hits-click-${hit.__position}`}
onClick=${() => sendEvent('click', hit, 'Clicked')}
>
click
</button>
</div>`,
},
...widgetParams,
}),
index({ indexName: 'nested' }).addWidgets([
hits({
container: document.body.appendChild(
Object.assign(document.createElement('div'), {
id: 'nested-hits',
})
),
templates: {
item: (hit, { html, sendEvent }) =>
html`<div data-testid=${`nested-hits-${hit.__position}`}>
${hit.objectID}
<button
data-testid=${`nested-hits-click-${hit.__position}`}
onClick=${() => sendEvent('click', hit, 'Clicked nested')}
>
click
</button>
</div>`,
},
}),
]),
])
.on('error', () => {
/*
Expand Down
Loading