WordPress Google Analytics plugin fails to track on one site but works on another

I’m having trouble with my analytics tracking setup and could really use some help.

I’ve got a popular WordPress analytics plugin installed on two different websites. The weird thing is that it tracks visitors perfectly on the first site, but completely fails to work on the second one.

Both websites use custom themes that I built from scratch. Since the plugin works fine on one site, I’m starting to think the issue might be related to how the second theme is structured. Maybe the tracking code isn’t being inserted properly into the header or footer sections.

I’ve double-checked the plugin settings on both sites and they look identical. The tracking ID is correct and the plugin shows as active. But when I check my analytics dashboard, I see zero data from the problematic site.

Has anyone experienced something similar? What should I look for in my theme files that might be blocking the analytics code from loading correctly?

Check if your problem site has caching plugins or CDN settings that might block the analytics script. I had the exact same issue - one site worked perfectly, the other didn’t track anything. Turned out my caching plugin was stopping the tracking code from loading on the broken site. Disable all caching temporarily and see if analytics start working. Also check your browser’s developer console on the failing site for JavaScript errors that could block the tracking script. Sometimes a plugin conflict or theme JS error will completely kill analytics without any obvious signs.

I faced a similar issue a while back that took a lot of troubleshooting. In my case, it turned out that the lack of proper wp_head() and wp_footer() functions in my custom theme was the root of the problem. Be sure to check your header.php file to see if wp_head() is correctly placed before the closing tag and the presence of wp_footer() just before in footer.php. If these hooks are missing or incorrectly positioned, the analytics plugin won’t be able to add its tracking code. Furthermore, look out for potential JavaScript conflicts, as certain scripts can interfere with data collection. Disabling any custom scripts temporarily might help pinpoint the issue.

Had this exact issue last month - drove me nuts! Turns out the second site had custom JavaScript throwing errors that blocked analytics from loading. Open dev tools on the broken site and check the console tab for red errors. That’s how I found mine.

Been debugging similar tracking issues for years and there’s one thing nobody mentioned yet - theme security plugins or hardened theme code.

I’ve seen custom themes that strip out certain script tags or have Content Security Policy rules that block external tracking scripts. Check if your second theme has any security functions in functions.php that might be filtering script output.

Also run a quick test - temporarily switch your broken site to a default WordPress theme like Twenty Twenty-Four. If analytics suddenly work, you’ll know it’s definitely theme related.

Another quick check is viewing page source on both sites and searching for your Google Analytics tracking ID. If it’s missing from the broken site’s HTML, the plugin isn’t inserting the code at all.

If the tracking code is present in the HTML but still not working, then you’re dealing with JavaScript conflicts like others mentioned. But start with the theme swap test - saves a ton of debugging time.