Skip to article body
A woman on a Cairo rooftop at dusk speaking into an old telephone handset, its loose cord swinging below her
A woman on a Cairo rooftop at dusk speaking into an old telephone handset, its loose cord swinging below her

Web Development · Field Notes

The Analytics Snippet That Sent Nothing

One tidy rewrite of the gtag stub left Google Analytics silent for 22 days.

By Shehab Waleed, Founder, Cairo Studio 2 min read

Three weeks after we launched the new site, Google Analytics had recorded nothing. The tag was there, the script loaded with a 200, and the console was clean. Umami, the other analytics tool on the same pages, was counting visitors as usual. We only found out when someone went to install the snippet, assuming it had never been added.

The two versions

This is the stub Google gives you.

function gtag() {
dataLayer.push(arguments);
}

This is the one we shipped.

function gtag(...args) {
dataLayer.push(args);
}

They look the same, and most reviewers would prefer the second. ESLint has a rule, prefer-rest-params, that asks for exactly that change. The difference is what lands in dataLayer: the first pushes an arguments object and the second pushes a real array. gtag.js treats those differently. Our commands went into the queue and stayed there.

Proving it

We ran both stubs in headless Chromium with the same tag and the same calls, and blocked the outgoing hits so no test data reached the account.

await page.route('**/g/collect*', (route) => {
hits += 1;
return route.abort();
});

With the array version, the script returned 200 and we counted 0 hits and 0 errors. With arguments, we counted 4 hits. Nothing on the page tells you which one you have.

What counts as checking

We had checked that the script loaded, and that only proves the script loaded. The proof that analytics works is the outgoing request, so look for that in the network panel or in a test.

  • Filter for /g/collect. That is the request that carries the hit.
  • Give it a few seconds, because hits are batched and can arrive late.
  • Test on the live host if your analytics only runs in production, as ours does.

A second tool is what makes this kind of failure visible, as long as someone compares the two. Google Analytics cannot recover those 22 days, but Umami has them.

For more on the setup behind this site, read why we moved it to our own server.

Share
X LinkedIn Facebook WhatsApp Email
A hand holding the loose end of a coiled telephone cord, the cord smeared by motion

Everything connected, except the last inch.

0

gtag.js loaded with a 200, no console errors

4

Same page, same calls

22

From our launch on 8 October to the fix on 30 October

Tested in headless Chromium with hits blocked, November 2026.

Check your stub first. If it pushes an array, such as function gtag(...args) { dataLayer.push(args) }, the script loads and sends nothing. It has to push the arguments object.

Open the network panel and filter for /g/collect. Each request there carries a hit. Allow a few seconds, because they can be batched.

Leave the code as it is and disable the rule for that one line if you need to. This is the one place where the modern rewrite changes the behaviour.

We can check what your analytics is really sending, then fix what is quiet.

More from the Journal

view all →