Skip to content

Commit

Permalink
Use capture-phase listeners for button click tracking (#1348)
Browse files Browse the repository at this point in the history
In v4 we switched the Form Tracking (#1329) and Link Click Tracking (#1325) plugins to using capture-phase event listeners instead of bubble-phase.

This makes the same change for the Button Click Tracking plugin to make it consistent.

This has caused issues for some clients historically, e.g. BCPF-1421 where pages stopping propagation of event bubbling prevented buttons being tracked.
  • Loading branch information
jethron authored Oct 9, 2024
1 parent ddd9ce1 commit d888e38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/browser-plugin-button-click-tracking",
"comment": "Use capture-phase event listeners",
"type": "none"
}
],
"packageName": "@snowplow/browser-plugin-button-click-tracking"
}
4 changes: 2 additions & 2 deletions plugins/browser-plugin-button-click-tracking/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function enableButtonClickTracking(
};

const addClickListener = () => {
document.addEventListener('click', _listeners[trackerId]);
document.addEventListener('click', _listeners[trackerId], true);
};

if (_trackers[trackerId]?.sharedState.hasLoaded) {
Expand All @@ -83,7 +83,7 @@ export function enableButtonClickTracking(
export function disableButtonClickTracking() {
for (const trackerId in _trackers) {
if (_listeners[trackerId]) {
document.removeEventListener('click', _listeners[trackerId]);
document.removeEventListener('click', _listeners[trackerId], true);
}
}
}
Expand Down

0 comments on commit d888e38

Please sign in to comment.