What happened
A site I look after stopped recording visits in Google Analytics on 22 September 2026. Nobody noticed until 13 October. The analytics script was on every page. It loaded without errors. It simply had nothing to do, because the line that tells it which property to report to was gone.
How WordPress prints a script
When a plugin registers a script and then adds inline code before or after it, WordPress prints all three together: the inline "before" block, the script tag, then the inline "after" block. The script_loader_tag filter receives that whole string, inline blocks included, as its $tag argument.
So a filter like this is fine:
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if ( 'my-analytics' === $handle ) {
$tag = str_replace( ' src=', ' defer src=', $tag );
}
return $tag;
}, 10, 2 );
And a filter like this is not:
add_filter( 'script_loader_tag', function ( $tag, $handle, $src ) {
if ( 'my-analytics' === $handle ) {
return '<script defer src="' . esc_url( $src ) . '"></script>';
}
return $tag;
}, 10, 3 );
The second one builds a fresh tag and returns it. The inline blocks that were part of $tag are not in the new string, so they are never printed. For an analytics tag the inline block is the configuration. Without it the loader arrives and waits for instructions that never come.
Why it is hard to see
- The script request succeeds, so the network panel is green.
- There is no JavaScript error, because nothing is wrong with the loader.
- Real-time reports show nothing, which looks the same as a quiet afternoon.
- Other tags on the page may still work, if they were not caught by the same filter.
How to check
- View the page source and find your analytics loader. Directly before or after it there should be an inline script that names your measurement ID. If the loader is there and the configuration is not, this is your problem.
- Search your theme and plugins for
script_loader_tagand read each callback. Any that return a newly built tag for a handle with inline code attached will drop that code. - Compare your daily sessions with a second, independent count if you have one. A step down to nothing on one of them is the giveaway.
What the plugin does about it
Ace Crawl Enhancer has a Tracking report. It recognises the analytics, advertising and consent scripts already present on your pages, and it requests your home page to look for a loader that has arrived without its configuration. It can chart two independent counts side by side so that a silent tag shows up as a gap, and a daily check raises a notice in the admin and sends an email when something that was working stops.
It does not install any tracking script itself. Recognising a script is not the same as loading it.
The rule
In a script_loader_tag callback, change the string you were given. Do not replace it.