-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): introduce Insights plugin (#373)
- Loading branch information
1 parent
547719b
commit 2e967be
Showing
37 changed files
with
937 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { autocomplete } from '@algolia/autocomplete-js'; | ||
import { createAlgoliaInsightsPlugin } from '@algolia/autocomplete-plugin-algolia-insights'; | ||
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions'; | ||
import { createLocalStorageRecentSearchesPlugin } from '@algolia/autocomplete-plugin-recent-searches'; | ||
import algoliasearch from 'algoliasearch/lite'; | ||
import algoliasearch from 'algoliasearch'; | ||
import insightsClient from 'search-insights'; | ||
|
||
const searchClient = algoliasearch( | ||
'latency', | ||
'6be0576ff61c053d5f9a3225e2a90f76' | ||
); | ||
const appId = 'latency'; | ||
const apiKey = '6be0576ff61c053d5f9a3225e2a90f76'; | ||
const searchClient = algoliasearch(appId, apiKey); | ||
insightsClient('init', { appId, apiKey }); | ||
|
||
const algoliaInsightsPlugin = createAlgoliaInsightsPlugin({ insightsClient }); | ||
const recentSearchesPlugin = createLocalStorageRecentSearchesPlugin({ | ||
key: 'search', | ||
limit: 3, | ||
}); | ||
|
||
const querySuggestionsPlugin = createQuerySuggestionsPlugin({ | ||
searchClient, | ||
indexName: 'instant_search_demo_query_suggestions', | ||
getSearchParams() { | ||
return recentSearchesPlugin.data.getAlgoliaSearchParams(); | ||
return recentSearchesPlugin.data.getAlgoliaSearchParams({ | ||
clickAnalytics: true, | ||
}); | ||
}, | ||
}); | ||
|
||
autocomplete({ | ||
container: '#autocomplete', | ||
openOnFocus: true, | ||
plugins: [recentSearchesPlugin, querySuggestionsPlugin], | ||
plugins: [ | ||
algoliaInsightsPlugin, | ||
recentSearchesPlugin, | ||
querySuggestionsPlugin, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BaseItem, OnHighlightParams, OnSelectParams } from './api'; | ||
|
||
export type Subscriber<TItem extends BaseItem> = { | ||
onSelect(params: OnSelectParams<TItem>): void; | ||
onHighlight(params: OnHighlightParams<TItem>): void; | ||
}; | ||
|
||
export type Subscribers<TItem extends BaseItem> = Array< | ||
Partial<Subscriber<TItem>> | ||
>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# @algolia/autocomplete-plugin-algolia-insights | ||
|
||
A plugin to add Algolia Insights to Algolia Autocomplete. | ||
|
||
## Installation | ||
|
||
```sh | ||
yarn add @algolia/autocomplete-plugin-algolia-insights@alpha | ||
# or | ||
npm install @algolia/autocomplete-plugin-algolia-insights@alpha | ||
``` |
40 changes: 40 additions & 0 deletions
40
packages/autocomplete-plugin-algolia-insights/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "@algolia/autocomplete-plugin-algolia-insights", | ||
"description": "A plugin to add Algolia Insights to Algolia Autocomplete.", | ||
"version": "1.0.0-alpha.35", | ||
"license": "MIT", | ||
"homepage": "https://github.com/algolia/autocomplete.js", | ||
"repository": "algolia/autocomplete.js", | ||
"author": { | ||
"name": "Algolia, Inc.", | ||
"url": "https://www.algolia.com" | ||
}, | ||
"source": "src/index.ts", | ||
"types": "dist/esm/index.d.ts", | ||
"module": "dist/esm/index.js", | ||
"main": "dist/umd/index.production.js", | ||
"umd:main": "dist/umd/index.production.js", | ||
"unpkg": "dist/umd/index.production.js", | ||
"jsdelivr": "dist/umd/index.production.js", | ||
"sideEffects": false, | ||
"files": [ | ||
"dist/" | ||
], | ||
"scripts": { | ||
"build:clean": "rm -rf ./dist", | ||
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/'", | ||
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm", | ||
"build:umd": "rollup --config", | ||
"build": "rm -rf ./dist && yarn build:umd && yarn build:esm && yarn build:types", | ||
"on:change": "concurrently \"yarn build:esm\" \"yarn build:types\"", | ||
"prepare": "yarn run build:esm", | ||
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\"" | ||
}, | ||
"dependencies": { | ||
"@algolia/autocomplete-core": "1.0.0-alpha.35", | ||
"@algolia/autocomplete-shared": "1.0.0-alpha.35" | ||
}, | ||
"peerDependencies": { | ||
"search-insights": "^1.0.0" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/autocomplete-plugin-algolia-insights/rollup.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createRollupConfigs } from '../../scripts/rollup/config'; | ||
|
||
import pkg from './package.json'; | ||
|
||
export default createRollupConfigs({ pkg }); |
Oops, something went wrong.