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

fix(insights): user-defined send/bindEvent overrides internal click #5527

Merged
merged 16 commits into from
Mar 16, 2023

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Mar 3, 2023

in sendEvent, we mark internal events (click and conversion), and prevent them being sent if there was a custom click right before. We also move bindEvent so that it happens before sendEvent

This prevents automatic click when:

  • there's a bindEvent child
  • there's a sendEvent click before

This doesn't prevent when:

  • there's a sendEvent convert before
  • there's a view before
  • there's two internal clicks in a row

FX-2246

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 3, 2023

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 1be6e7a:

Sandbox Source
InstantSearch.js Configuration
react-instantsearch-app Configuration
example-react-instantsearch-hooks-default-theme Configuration
example-vue-instantsearch-default-theme Configuration

@Haroenv Haroenv changed the title fix(insights): user-defined click overrides fix(insights): user-defined click overrides internal click Mar 3, 2023
@Haroenv Haroenv changed the title fix(insights): user-defined click overrides internal click fix(insights): user-defined send/bindEvent overrides internal click Mar 6, 2023
@Haroenv Haroenv force-pushed the feat/automatic-insights branch from b4e9504 to 7f415a8 Compare March 8, 2023 16:00
Haroenv added 2 commits March 14, 2023 11:00
in sendEvent, we mark internal events (click and conversion), and prevent them being sent if there was a custom click right before.

Note that this doesn't yet work with bindEvent, as it's higher in the bubbling tree
@Haroenv Haroenv force-pushed the fix/prevent-dupe-events-click branch from ecf5ec7 to 35028d0 Compare March 14, 2023 10:03
@Haroenv Haroenv marked this pull request as ready for review March 14, 2023 10:32
@Haroenv Haroenv requested review from sarahdayan and dhayab March 14, 2023 10:34
same idea as this test in hits-integration-test.ts
@Haroenv Haroenv requested a review from sarahdayan March 14, 2023 13:40
Haroenv added 3 commits March 14, 2023 14:59
people can't bind events higher anyway, so this is safe to do
this allows the dedupe to work for both bindEvent and sendEvent in a single codebase.

Tiny aside: this means that the "next internal click" is now global, meaning if you click on geo, then on hits, we'll see that as an internal click to prevent sending. This is an extreme edge case, as almost nowhere sends click events.
Copy link
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

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

Awesome ✨ , I just have 2 nitpicky notes, otherwise it's good for me!

onClick: () => {
sendEvent('click', hit, 'Hit Clicked');
onClick: (event: MouseEvent) => {
handleInsightsClick(event);
Copy link
Member

Choose a reason for hiding this comment

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

💯

packages/instantsearch.js/src/lib/insights/listener.tsx Outdated Show resolved Hide resolved
@Haroenv Haroenv requested a review from sarahdayan March 15, 2023 16:28
@Haroenv Haroenv requested a review from dhayab March 15, 2023 16:29
Comment on lines +208 to +212
fakeAct,
{
// Vue InstantSearch doesn't support modern insights with sendEvent + default events
insights: true,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved by #5549

Copy link
Member

Choose a reason for hiding this comment

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

This and the infinite hits insights test look really similar. Do you think we could go one step further and rely on a reusable test suite for both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it, but didn't get to a suitable shape for the tests. The common tests shape will become clearer when we have more of them I think

@Haroenv Haroenv merged commit 94c385b into feat/automatic-insights Mar 16, 2023
@Haroenv Haroenv deleted the fix/prevent-dupe-events-click branch March 16, 2023 09:10
Haroenv added a commit that referenced this pull request Apr 18, 2023
…5527)

* fix(insights): prevent duplicate events

in sendEvent, we mark internal events (click and conversion), and prevent them being sent if there was a custom click right before.

Note that this doesn't yet work with bindEvent, as it's higher in the bubbling tree

* fix(internal): bail out of default click if element has a bindEvent parent

* test

* fix: only prevent next clicks after a regular click

* bundlesize

* test(infiniteHits): add sendEvent tests

same idea as this test in hits-integration-test.ts

* wip infinite hits

* move bindEvent click listener

people can't bind events higher anyway, so this is safe to do

* refactor: move dedupe into middleware

this allows the dedupe to work for both bindEvent and sendEvent in a single codebase.

Tiny aside: this means that the "next internal click" is now global, meaning if you click on geo, then on hits, we'll see that as an internal click to prevent sending. This is an extreme edge case, as almost nowhere sends click events.

* fix(events): move back inside connector

this prevents a custom blocking an internal in a different widget

* get rid of global cruft

* refactor: use timers instead of order-based ignoring

* test(common): insights clicks + view for hits + infinitehits

* fix(react): send an internal event

* PR feedback

* internal
Haroenv added a commit that referenced this pull request Apr 24, 2023
…5527)

* fix(insights): prevent duplicate events

in sendEvent, we mark internal events (click and conversion), and prevent them being sent if there was a custom click right before.

Note that this doesn't yet work with bindEvent, as it's higher in the bubbling tree

* fix(internal): bail out of default click if element has a bindEvent parent

* test

* fix: only prevent next clicks after a regular click

* bundlesize

* test(infiniteHits): add sendEvent tests

same idea as this test in hits-integration-test.ts

* wip infinite hits

* move bindEvent click listener

people can't bind events higher anyway, so this is safe to do

* refactor: move dedupe into middleware

this allows the dedupe to work for both bindEvent and sendEvent in a single codebase.

Tiny aside: this means that the "next internal click" is now global, meaning if you click on geo, then on hits, we'll see that as an internal click to prevent sending. This is an extreme edge case, as almost nowhere sends click events.

* fix(events): move back inside connector

this prevents a custom blocking an internal in a different widget

* get rid of global cruft

* refactor: use timers instead of order-based ignoring

* test(common): insights clicks + view for hits + infinitehits

* fix(react): send an internal event

* PR feedback

* internal
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.

3 participants