/* === KANDIDEERI.EE — Meie portaalid: GA4 click tracking (SJB-safe) — v2026-01-PORTALS-JS-R1 === */ (function () { 'use strict'; function fireEvent(name, params) { params = params || {}; try { if (typeof window.gtag === 'function') { window.gtag('event', name, params); return; } } catch (e) {} try { window.dataLayer = window.dataLayer || []; window.dataLayer.push(Object.assign({ event: name }, params)); } catch (e2) {} } function onReady(fn){ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', fn, { once: true }); } else fn(); } onReady(function () { var root = document.getElementById('kand-portals-page'); if (!root) return; if (root.getAttribute('data-kand-track-ready') === '1') return; root.setAttribute('data-kand-track-ready', '1'); root.addEventListener('click', function (e) { var el = e.target; while (el && el !== root) { if (el.matches && (el.matches('a[data-kcta]') || el.matches('button[data-kcta]'))) { var key = (el.getAttribute('data-kcta') || 'unknown').trim(); var href = (el.getAttribute('href') || '').trim(); fireEvent('k_ecosystem_click', { k_action: key, k_href: href, k_page: (location.pathname || '').toLowerCase() }); // Optional: also record a more specific event for outbound clicks if (/^https?:\/\//i.test(href) && href.indexOf(location.origin) !== 0) { fireEvent('k_outbound_click', { k_action: key, k_href: href, k_page: (location.pathname || '').toLowerCase() }); } return; } el = el.parentNode; } }, true); }); })(); Skip to main content