Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(insights): add hits and attributes to InsightsEvent #4667

Merged
merged 5 commits into from
Mar 5, 2021

Conversation

eunjae-lee
Copy link
Contributor

Summary

This PR adds hits and attributes to InsightsEvent.

Detail

Previously we had this:

export type InsightsEvent = {
  insightsMethod?: InsightsClientMethod;
  payload: any;
  widgetType: string;
  eventType: string;
};

For example,

  • insightsMethod: "viewedObjectIDs"
  • widgetType: "ais.hits"
  • eventType: "view"

window.aa(insightsMethod, payload); just worked, which means payload is a tailored object for Algolia Insights.

When users want to send events to third party trackers, they might need more information other than what is in the payload.

In case of Hits Viewed, payload contains eventName, index and objectIDs. When they need to send events to, for example, Segment, they need other data like position, product name, etc.

So we're passing the whole hits object inside the InsightsEvent.

In case of facet widgets, we're adding attribute to InsightsEvent. It's to easily filter out events like:

onEvent: (event, aa) {
  if (event.attribute === 'price') {
    // do not track events for `price` attribute
  }
  aa(event.insightsMethod, event.payload);
}

Verified

This commit was signed with the committer’s verified signature.
edolstra Eelco Dolstra
@eunjae-lee eunjae-lee requested review from a team, Haroenv and shortcuts and removed request for a team March 3, 2021 10:31
@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 3, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7f9adfa:

Sandbox Source
InstantSearch.js Configuration

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

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

I see why it's not in payload, since that would cause the default implementation to need to strip them, but I kinda feel like it fits better under payload or metadata than as top-level key

@Haroenv
Copy link
Contributor

Haroenv commented Mar 3, 2021

(looks like some tests have failed due to the delete instead of spreading)

@eunjae-lee
Copy link
Contributor Author

I see why it's not in payload, since that would cause the default implementation to need to strip them, but I kinda feel like it fits better under payload or metadata than as top-level key

you're right. attribute could probably be there as a top-level key, but hits doesn't really fit much. Do you think it makes sense to have a key like metadata and have attribute or hits under it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants