-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite-events.js
More file actions
22 lines (22 loc) · 990 Bytes
/
Copy pathwebsite-events.js
File metadata and controls
22 lines (22 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* Optional, consent-aware conversion hooks. No tracker, network calls, or storage.
* An existing analytics integration can subscribe to `ctrlrun:conversion`.
* Free-text form fields and email content are never included in event details.
*/
(() => {
if (window.__ctrlrunWebsiteEvents) return;
window.__ctrlrunWebsiteEvents = true;
const emit = name => window.dispatchEvent(new CustomEvent('ctrlrun:conversion', { detail: { name } }));
document.addEventListener('click', event => {
const target = event.target instanceof Element ? event.target.closest('[data-cr-event]') : null;
if (target) emit(target.getAttribute('data-cr-event'));
});
let lastPath = '';
const visit = () => {
if (lastPath !== location.pathname) {
lastPath = location.pathname;
if (lastPath === '/' || lastPath === '/index') emit('homepage_visited');
}
};
visit();
new MutationObserver(visit).observe(document.documentElement, { childList: true, subtree: true });
})();