1/** 2 * Helper function to send events to GA4 or dataLayer 3 */ 4function siwSendEvent(eventName, eventParams = {}) { 5 console.log('SIW Debug:', eventName, eventParams); 6 7 if (typeof window.gtag === 'function') { 8 window.gtag('event', eventName, eventParams); 9 } else { 10 window.dataLayer = window.dataLayer || []; 11 window.dataLayer.push({ 12 'event': eventName, 13 ...eventParams 14 }); 15 } 16} 17 18function siwHandleYes(id) { 19 const wrapper = document.getElementById('siw-wrapper-' + id); 20 if (!wrapper) return; 21 22 const overlay = wrapper.querySelector('.sales-in-article-widget__overlay'); 23 const mainContent = wrapper.querySelector('.siw-main-content'); 24 25 if (overlay) overlay.style.display = 'none'; 26 if (mainContent) { 27 mainContent.style.visibility = 'visible'; 28 mainContent.style.opacity = '1'; 29 mainContent.style.pointerEvents = 'auto'; 30 } 31 32 siwSendEvent('siw_widget_' + id + '_q_yes_click', { 33 'widget_id': id 34 }); 35} 36 37function siwHandleNo(id) { 38 const wrapper = document.getElementById('siw-wrapper-' + id); 39 if (!wrapper) return; 40 41 const overlayContent = wrapper.querySelector('.sales-in-article-widget__overlay-content'); 42 if (overlayContent) { 43 overlayContent.innerHTML = '<h3>Äakujeme za odpoveÄ.</h3>'; 44 } 45 46 siwSendEvent('siw_widget_' + id + '_q_no_click', { 47 'widget_id': id 48 }); 49} 50 51function siwTrackClick(id) { 52 siwSendEvent('siw_widget_' + id + '_btn_click', { 53 'widget_id': id 54 }); 55} 56 57/** 58 * Initialize Intersection Observer for all widgets 59 */ 60function siwInitObservers() { 61 const widgets = document.querySelectorAll('.sales-in-article-widget__wrapper'); 62 63 const observerOptions = { 64 root: null, 65 rootMargin: '0px', 66 threshold: 0.1 // Trigger when 10% of the widget is visible 67 }; 68 69 const observer = new IntersectionObserver((entries, observer) => { 70 entries.forEach(entry => { 71 if (entry.isIntersecting) { 72 const widget = entry.target; 73 const widgetId = widget.getAttribute('id').replace('siw-wrapper-', ''); 74 75 // Track view event 76 siwSendEvent('siw_widget_' + widgetId + '_view', { 77 'widget_id': widgetId 78 }); 79 80 // Stop observing this element after it has been tracked once 81 observer.unobserve(widget); 82 } 83 }); 84 }, observerOptions); 85 86 widgets.forEach(widget => { 87 observer.observe(widget); 88 }); 89} 90 91// Initialize on DOM load 92document.addEventListener('DOMContentLoaded', siwInitObservers);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.