Skip to content

Commit

Permalink
feat(Insights): add storybook example for hits
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrugg committed Mar 11, 2019
1 parent 518e041 commit 97625ca
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions stories/hits.stories.js
@@ -1,5 +1,7 @@
import { storiesOf } from '@storybook/html';
import { withHits } from '../.storybook/decorators';
import insights from '../src/helpers/insights';
import { action } from '@storybook/addon-actions';

storiesOf('Hits', module)
.add(
Expand Down Expand Up @@ -105,4 +107,39 @@ storiesOf('Hits', module)
})
);
})
)
.add(
'with insights helper',
withHits(
({ search, container, instantsearch }) => {
search.addWidget(
instantsearch.widgets.configure({
attributesToSnippet: ['name', 'description'],
})
);

search.addWidget(
instantsearch.widgets.hits({
container,
templates: {
item: item => `
<h4>${item.name}</h4>
<button
${insights('clickedObjectIDsAfterSearch', {
objectIDs: [item.objectID],
eventName: 'Add to cart',
})} >Add to cart</button>
`,
},
})
);
},
{
searchParameters: {
clickAnalytics: true,
},
insightsClient: (method, payload) =>
action(`[InsightsClient] sent ${method} with payload`)(payload),
}
)
);

0 comments on commit 97625ca

Please sign in to comment.