Skip to content

Commit fed8834

Browse files
authored
Add event delegation for link click tracking (#1325)
* link-click-tracking: event delegation - Global event listeners are now used instead of per-element listeners - `refreshLinkClickTracking` is now deprecated and does nothing as it should no longer be required (but still exists for API compatibility) - There is now a `disableLinkClickTracking` method to balance `enableLinkClickTracking` - `trackLinkClick` can now optionally be passed a link element directly, rather than requiring manual construction of the event payload - Event listeners now use the capture phase instead of bubble - Link URIs are no longer unescaped - Additional unit tests for link click tracking
1 parent 2d5b8af commit fed8834

File tree

4 files changed

+434
-167
lines changed

4 files changed

+434
-167
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-plugin-link-click-tracking",
5+
"comment": "Update plugin to use global rather than per-element event listeners",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-link-click-tracking"
10+
}

plugins/browser-plugin-link-click-tracking/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,18 @@ newTracker('sp1', '{{collector}}', { plugins: [ LinkClickTrackingPlugin() ] });
4242
Then use the available functions from this package to track to all trackers which have been initialized with this plugin:
4343

4444
```js
45-
import { enableLinkClickTracking, refreshLinkClickTracking } from '@snowplow/browser-plugin-link-click-tracking';
45+
import { enableLinkClickTracking } from '@snowplow/browser-plugin-link-click-tracking';
4646

4747
enableLinkClickTracking({ options: { ... }, psuedoClicks: true });
48+
```
49+
50+
You can also explicitly track a click without installing listeners:
51+
52+
```js
53+
import { trackLinkClick } from '@snowplow/browser-plugin-link-click-tracking';
4854

49-
refreshLinkClickTracking();
55+
trackLinkClick({ element: document.querySelector("a, area") });
56+
trackLinkClick({ targetUrl: "http://example.com/" });
5057
```
5158

5259
## Copyright and license

0 commit comments

Comments
 (0)