Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

feat(insights): add connectInsights connector [PART-2] #2217

Merged
merged 13 commits into from
Apr 1, 2019

Conversation

tkrugg
Copy link
Contributor

@tkrugg tkrugg commented Mar 22, 2019

Summary
This connector is to be used on the hitComponent provided to and

Usage:

// window.aa is the insightsClient

const Product = ({ hit, insights }) => <span />
const ProductWithInsights = connectInsights(aa)(Product)

<Hits hitComponent={ProductWithInsights} />
const Product = ({ hit, insights }) => (
   <>
   	<a href={`/product/${hit.objectID}/?queryID=${hit.__queryID}`}>
	 	{hit.name}
	</a>

        <button onClick={() => insights("clickedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>

        <button onClick={() => insights("convertedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>
   </>
)

This sends to the API

aa('clickedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
	positions: [hit.__position],
})

aa('convertedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
})

Result

Test here:

Global Outline

@algobot
Copy link
Contributor

algobot commented Mar 22, 2019

Deploy preview for react-instantsearch ready!

Built with commit 7f35e04

https://deploy-preview-2217--react-instantsearch.netlify.com

@tkrugg tkrugg changed the title feat(insights): add connectInsights connector feat(insights): add connectInsights connector [PART-2] Mar 22, 2019
@algobot
Copy link
Contributor

algobot commented Mar 22, 2019

Deploy preview for react-instantsearch ready!

Built with commit 4dc11ef

https://deploy-preview-2217--react-instantsearch.netlify.com

@tkrugg tkrugg force-pushed the feat-insights-2-connectInsights branch 2 times, most recently from 6e74bac to 5d66c8f Compare March 22, 2019 14:23
@tkrugg tkrugg marked this pull request as ready for review March 22, 2019 14:31
@tkrugg tkrugg force-pushed the feat-insights-2-connectInsights branch 2 times, most recently from 8ab8132 to e9029ea Compare March 24, 2019 12:23
@tkrugg tkrugg requested review from francoischalifour and a team March 24, 2019 12:31
@samouss samouss removed the request for review from francoischalifour March 25, 2019 11:33
@tkrugg tkrugg force-pushed the feat-insights-1-hits branch 2 times, most recently from 58e837b to 6929935 Compare March 25, 2019 14:39
This connector is to be used on the hitComponent provided to <Hits /> and <InfiniteHits />

**Usage**:

```tsx
// window.aa is the insightsClient

const Product = ({ hit, insights }) => <span />
const ProductWithInsights = connectInsights(aa)(Product)

<Hits hitComponent={ProductWithInsights} />
```

```tsx
const Product = ({ hit, insights }) => (
   <>
   	<a href={`/product/${hit.objectID}/?queryID=${hit.__queryID}`}>
	 	{hit.name}
	</a>

        <button onClick={() => insights("clickedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>

        <button onClick={() => insights("convertedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>
   </>
)

```

This sends to the API
```js
aa('clickedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
	positions: [hit.__position],
})

aa('convertedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
})
```
@tkrugg tkrugg force-pushed the feat-insights-2-connectInsights branch from e9029ea to 3f79bc6 Compare March 25, 2019 14:40
@tkrugg tkrugg force-pushed the feat-insights-2-connectInsights branch from b53006c to 2eb25d4 Compare March 27, 2019 12:05
@tkrugg tkrugg force-pushed the feat-insights-2-connectInsights branch from 9158a4d to 449066a Compare March 27, 2019 13:42
@tkrugg tkrugg requested a review from samouss March 27, 2019 13:47
Copy link
Collaborator

@samouss samouss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to increase the size for two bundle. I usually take the .25 above.

packages/react-instantsearch-dom/src/index.js Outdated Show resolved Hide resolved
packages/react-instantsearch-native/src/index.js Outdated Show resolved Hide resolved
packages/react-instantsearch/connectors.js Outdated Show resolved Hide resolved
@tkrugg tkrugg merged commit e036b37 into feat-insights-1-hits Apr 1, 2019
tkrugg added a commit that referenced this pull request Apr 1, 2019
* feat(insights): compute insights data in connectHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID

* feat(insights): add connectInsights connector [PART-2]  (#2217)

* feat(insights): add connectInsights connector

This connector is to be used on the hitComponent provided to <Hits /> and <InfiniteHits />

**Usage**:

```tsx
// window.aa is the insightsClient

const Product = ({ hit, insights }) => <span />
const ProductWithInsights = connectInsights(aa)(Product)

<Hits hitComponent={ProductWithInsights} />
```

```tsx
const Product = ({ hit, insights }) => (
   <>
   	<a href={`/product/${hit.objectID}/?queryID=${hit.__queryID}`}>
	 	{hit.name}
	</a>

        <button onClick={() => insights("clickedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>

        <button onClick={() => insights("convertedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>
   </>
)

```

This sends to the API
```js
aa('clickedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
	positions: [hit.__position],
})

aa('convertedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
})
```

* feat(insights): add insights example to Hits and InfiniteHits stories

* feedback: simplify types

remove Without<InsightsClientPayload, 'eventName' | 'positions'>

* feedback: fix error message thrown on unsupported method

* feedback: simplified tests

* feedback: clarify skipping of elements in infiniteHits tests on hitPerPage change

* renamed connectInsights to connectHitsInsights

* feedback: decontruct all props used from results for consistency

* feedback: using toEqual

* feedback: rename connectHitsInsights to connectHitInsights

* feedback: expose connectHitInsights from dom and native

* feedback: sort imports

* feedback: add .25 to react-instantsearc & react-instantsearch-dom bundle sizes
@samouss samouss deleted the feat-insights-2-connectInsights branch April 1, 2019 17:51
tkrugg added a commit that referenced this pull request Apr 2, 2019
* feat(insights): add utility functions

addAbsolutePositions & addQueryID

* feat(insights): compute insights data in connectInfiniteHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID$

* feedback: revert sorting of lodash imports

* feedback: curly styles

* feat(insights): compute insights data in connectHits [PART-1]  (#2216)

* feat(insights): compute insights data in connectHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID

* feat(insights): add connectInsights connector [PART-2]  (#2217)

* feat(insights): add connectInsights connector

This connector is to be used on the hitComponent provided to <Hits /> and <InfiniteHits />

**Usage**:

```tsx
// window.aa is the insightsClient

const Product = ({ hit, insights }) => <span />
const ProductWithInsights = connectInsights(aa)(Product)

<Hits hitComponent={ProductWithInsights} />
```

```tsx
const Product = ({ hit, insights }) => (
   <>
   	<a href={`/product/${hit.objectID}/?queryID=${hit.__queryID}`}>
	 	{hit.name}
	</a>

        <button onClick={() => insights("clickedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>

        <button onClick={() => insights("convertedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>
   </>
)

```

This sends to the API
```js
aa('clickedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
	positions: [hit.__position],
})

aa('convertedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
})
```

* feat(insights): add insights example to Hits and InfiniteHits stories

* feedback: simplify types

remove Without<InsightsClientPayload, 'eventName' | 'positions'>

* feedback: fix error message thrown on unsupported method

* feedback: simplified tests

* feedback: clarify skipping of elements in infiniteHits tests on hitPerPage change

* renamed connectInsights to connectHitsInsights

* feedback: decontruct all props used from results for consistency

* feedback: using toEqual

* feedback: rename connectHitsInsights to connectHitInsights

* feedback: expose connectHitInsights from dom and native

* feedback: sort imports

* feedback: add .25 to react-instantsearc & react-instantsearch-dom bundle sizes
francoischalifour pushed a commit that referenced this pull request Apr 8, 2019
* feat(insights): add utility functions

addAbsolutePositions & addQueryID

* feat(insights): compute insights data in connectInfiniteHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID$

* feedback: revert sorting of lodash imports

* feedback: curly styles

* feat(insights): compute insights data in connectHits [PART-1]  (#2216)

* feat(insights): compute insights data in connectHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID

* feat(insights): add connectInsights connector [PART-2]  (#2217)

* feat(insights): add connectInsights connector

This connector is to be used on the hitComponent provided to <Hits /> and <InfiniteHits />

**Usage**:

```tsx
// window.aa is the insightsClient

const Product = ({ hit, insights }) => <span />
const ProductWithInsights = connectInsights(aa)(Product)

<Hits hitComponent={ProductWithInsights} />
```

```tsx
const Product = ({ hit, insights }) => (
   <>
   	<a href={`/product/${hit.objectID}/?queryID=${hit.__queryID}`}>
	 	{hit.name}
	</a>

        <button onClick={() => insights("clickedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>

        <button onClick={() => insights("convertedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>
   </>
)

```

This sends to the API
```js
aa('clickedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
	positions: [hit.__position],
})

aa('convertedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
})
```

* feat(insights): add insights example to Hits and InfiniteHits stories

* feedback: simplify types

remove Without<InsightsClientPayload, 'eventName' | 'positions'>

* feedback: fix error message thrown on unsupported method

* feedback: simplified tests

* feedback: clarify skipping of elements in infiniteHits tests on hitPerPage change

* renamed connectInsights to connectHitsInsights

* feedback: decontruct all props used from results for consistency

* feedback: using toEqual

* feedback: rename connectHitsInsights to connectHitInsights

* feedback: expose connectHitInsights from dom and native

* feedback: sort imports

* feedback: add .25 to react-instantsearc & react-instantsearch-dom bundle sizes
Haroenv pushed a commit that referenced this pull request Apr 9, 2019
* feat(insights): add utility functions

addAbsolutePositions & addQueryID

* feat(insights): compute insights data in connectInfiniteHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID$

* feedback: revert sorting of lodash imports

* feedback: curly styles

* feat(insights): compute insights data in connectHits [PART-1]  (#2216)

* feat(insights): compute insights data in connectHits

adds __positions and __queryID to every hit

* feedback: move helper methods to utils.js

* feedback: rename hits to hitsWithPositions and hitsWithPositionsAndQueryID

* feat(insights): add connectInsights connector [PART-2]  (#2217)

* feat(insights): add connectInsights connector

This connector is to be used on the hitComponent provided to <Hits /> and <InfiniteHits />

**Usage**:

```tsx
// window.aa is the insightsClient

const Product = ({ hit, insights }) => <span />
const ProductWithInsights = connectInsights(aa)(Product)

<Hits hitComponent={ProductWithInsights} />
```

```tsx
const Product = ({ hit, insights }) => (
   <>
   	<a href={`/product/${hit.objectID}/?queryID=${hit.__queryID}`}>
	 	{hit.name}
	</a>

        <button onClick={() => insights("clickedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>

        <button onClick={() => insights("convertedObjectIDsAfterSearch",
	{"eventName": "Add to cart"})}>
		Add to Cart
	</button>
   </>
)

```

This sends to the API
```js
aa('clickedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
	positions: [hit.__position],
})

aa('convertedObjectIDsAfterSearch', {
	eventName: "Add to cart",
	index: "...", // infered
	queryID: [hit.__queryID],
	objectIDs: [hit.objectID],
})
```

* feat(insights): add insights example to Hits and InfiniteHits stories

* feedback: simplify types

remove Without<InsightsClientPayload, 'eventName' | 'positions'>

* feedback: fix error message thrown on unsupported method

* feedback: simplified tests

* feedback: clarify skipping of elements in infiniteHits tests on hitPerPage change

* renamed connectInsights to connectHitsInsights

* feedback: decontruct all props used from results for consistency

* feedback: using toEqual

* feedback: rename connectHitsInsights to connectHitInsights

* feedback: expose connectHitInsights from dom and native

* feedback: sort imports

* feedback: add .25 to react-instantsearc & react-instantsearch-dom bundle sizes
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants