Skip to content
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
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ search configuration options:
| `customEvents` | `Object` | To set the custom events, for e.g `{ "platform": mac }` |
| `filters` | `Object` | It allows to record the applied facets on the search query, for e.g `{ "year": 2018 }` |
| `hits` | `Array` | To set the search hits, a hit object can have the `id`, `type` & `source` properties . |
| `impressions` | `Array` | To set the impressions, a hit object can have the `id` & `index` properties. |

<b>Note: </b>

Expand Down Expand Up @@ -627,16 +628,13 @@ deleteSavedSearch(savedSearchId: string, callback: Function)
An example with all possible options:

```ts
deleteSavedSearch(
'analytics-js-test',
(err, res) => {
if (err) {
// handle error
} else if (res) {
// handle response
}
deleteSavedSearch('analytics-js-test', (err, res) => {
if (err) {
// handle error
} else if (res) {
// handle response
}
);
});
```

#### Get saved searches
Expand Down
11 changes: 9 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type Hit = {
source?: Object
};

type Impression = {
id: string,
index: 'good-books-ds'
};

type AnalyticsConfig = {
index: string,
url: string,
Expand All @@ -31,7 +36,8 @@ type SearchConfig = {
queryID?: string,
customEvents?: { [key: string]: string },
filters?: { [key: string]: string },
hits?: Array<Hit>
hits?: Array<Hit>,
impressions?: Array<Impression>
};

type SearchRequestBody = {
Expand Down Expand Up @@ -233,7 +239,8 @@ function initClient(config: AnalyticsConfig = {}) {
query_id: searchConfig.queryID,
custom_events: searchConfig.customEvents,
filters: searchConfig.filters,
hits: searchConfig.hits
hits: searchConfig.hits,
impressions: searchConfig.impressions
};
metrics._request(
'PUT',
Expand Down
18 changes: 18 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ test('registerSearch', done => {
},
type: '_doc'
}
],
impressions: [
{
id: '3DftXXEBdEU4aeo6Gdqs',
index: 'good-books-ds'
},
{
id: '3TftXXEBdEU4aeo6Gdqs',
index: 'good-books-ds'
},
{
id: '3jftXXEBdEU4aeo6Gdqs',
index: 'good-books-ds'
},
{
id: '3zftXXEBdEU4aeo6Gdqs',
index: 'good-books-ds'
}
]
},
(err, res) => {
Expand Down