Files
cannaiq/wordpress-plugin/dutchie-analytics/assets/js/dutchie-analytics.js
2025-11-28 19:45:44 -07:00

46 lines
1.3 KiB
JavaScript
Executable File

/**
* Dutchie Analytics - Frontend JavaScript
*/
(function($) {
'use strict';
// Lazy load images
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
if (img.dataset.src) {
img.src = img.dataset.src;
img.removeAttribute('data-src');
observer.unobserve(img);
}
}
});
});
$('.dutchie-product-image img[data-src]').each(function() {
imageObserver.observe(this);
});
}
// Add hover effects
$('.dutchie-product-card').on('mouseenter', function() {
$(this).addClass('dutchie-hover');
}).on('mouseleave', function() {
$(this).removeClass('dutchie-hover');
});
// Optional: Track product views for analytics
$('.dutchie-product-card').on('click', function() {
const productId = $(this).data('product-id');
if (productId && typeof gtag !== 'undefined') {
gtag('event', 'view_item', {
'item_id': productId
});
}
});
})(jQuery);