Ecommerce Shopify WordPress Discussion

Image Tracking Through WordPress [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed yesterday. Improve this question I am trying to track users who click or engage with Images listed on my Website, I have tried to use Js to accomplish this but it works well on my Local Computer but won't work on WordPress when i insert my Code, Now i am using a plugin to add custom code to my site Here's my JavaScript to view users whom engage with my Images. window.onload = function() { const imageLinks = document.querySelectorAll('a img'); // Select all images imageLinks.forEach(link => { const uniqueID = generateUniqueID(); // Generate a unique ID link.parentElement.href += (link.parentElement.href.includes('?') ? '&' : '?') + `utm_source=ImageInteraction&click_id=${uniqueID}`; }); // Google Analytics tracking code function trackImageLinkClick(event) { const link ='a'); if (link) { const linkPath = link.href; // Google Analytics tracking code for image link clicks gtag('event', 'click', { 'event_category': 'Image Link Click', 'event_label': linkPath, 'event_callback': function() { console.log('Google Analytics: Image link click tracked'); } }); } } document.body.addEventListener('click', function(event) { if ( === 'IMG' && === 'A') { trackImageLinkClick(event); } }); // Function to generate a unique ID (can be improved for better uniqueness) function generateUniqueID() { return + Math.random().toString(36).substr(2); } }; // Google Analytics initialization const googleAnalyticsScript = document.createElement('script'); googleAnalyticsScript.async = true; googleAnalyticsScript.src = ''; const googleAnalyticsConfig = document.createElement('script'); googleAnalyticsConfig.innerHTML = ` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-MFW1KVZZDQ'); `; document.head.appendChild(googleAnalyticsScript); document.head.appendChild(googleAnalyticsConfig); I tried WordPress because that's where i need my code to be executed, In my site. But it wont work yet everything is fine when i try using my Local Computer
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.