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
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,19 @@ describe('AlgoliaInsights.productClickedEvents', () => {
expect(algoliaEvent.userToken).toBe(event.anonymousId)
expect(algoliaEvent.authenticatedUserToken).toBe(event.userId)
})

it('should pass position if 0', async () => {
const event = createTestEvent({
type: 'track',
event: 'Product Clicked',
properties: {
query_id: '1234',
search_index: 'fashion_1',
product_id: '9876',
position: 0
}
})
const algoliaEvent = await testAlgoliaDestination(event)
expect(algoliaEvent.positions?.[0]).toBe(event.properties?.position)
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const productClickedEvents: ActionDefinition<Settings, Payload> = {
},
position: {
label: 'Position',
description: 'Position of the click in the list of Algolia search results.',
description: 'Position of the click in the list of Algolia search results. Positions should start from 1, not 0.',
type: 'integer',
required: false,
default: {
Expand Down Expand Up @@ -116,7 +116,7 @@ export const productClickedEvents: ActionDefinition<Settings, Payload> = {
objectIDs: [data.payload.objectID],
userToken: data.payload.userToken,
authenticatedUserToken: data.payload.authenticatedUserToken,
positions: data.payload.position ? [data.payload.position] : undefined,
positions: data.payload.position != null ? [data.payload.position] : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you also check for undefined as well as null? Or are you happy to default it to 0 if there is no value passed?

Copy link
Contributor

Choose a reason for hiding this comment

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

hi @jkaho just checking if you saw my comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, so sorry, I didn't see this, thanks for the quick review! data.payload.position != null should resolve to false if data.payload.position is true as we've used the non-strict inequality operator. Let me know if there's a syntax you'd prefer.

timestamp: data.payload.timestamp ? new Date(data.payload.timestamp).valueOf() : undefined
}
const insightPayload = { events: [insightEvent] }
Expand Down
Loading