4 min readAnalyticsCase study

Analytics not working: a counter that never recorded a single visit

Analytics was installed, the code was in place, no errors in the console. And not one visit in the statistics. The cause was a single line that made the browser replace the counter function with a script tag.

A studio site had been running for over a year. Analytics was connected, the counter was listed in the dashboard, the code was visible in the page source. The statistics, meanwhile, were empty, and everyone assumed there was simply not much traffic.

There was traffic. The counter was not working — and it had not worked since day one.

Why the analytics counter was not working

The standard analytics snippet creates a function called ym and calls it to initialise. In our case the script tag was labelled like this:

<Script id="ym"> ... ym(12345678, "init", { webvisor: true }) ... </Script>

Browsers create a global variable for every element carrying an id attribute. So window.ym became a reference to the script tag itself, before the snippet had any chance to declare the function.

The snippet then checks "does the function already exist?", sees the variable is taken and leaves it alone. The initialisation call goes into a markup element instead of the counter, fails inside a try block and prints nothing to the console.

The signature of this failure: typeof window.ym returns "object" instead of "function". If that object also has properties such as l, you are looking at a script tag, not at a counter.

Why nobody noticed

There is no console error — it gets swallowed. The counter file shows up in the network requests, because it does load. The dashboard lists the counter as active. Everything looks operational except for one thing: no hits are sent and the statistics stay empty.

What you have to check is not that the code is present but that data is actually sent. In the browser, look at network requests to the analytics host: if there are no requests to the address carrying your counter number, nothing is being collected, whatever the dashboard says.

The fix, and a rule for the future

Renaming the tag identifier is enough: ym-init instead of ym. After that the counter initialises properly, hits are sent and session recording works.

The rule is broader than one analytics tool: never give an element an id that matches the name of a library global. The dangerous ones are ym, dataLayer, gtag, fbq. The browser will happily replace every one of them with your tag.

A year of advertising decisions was made blind because of two characters in an attribute. Checking takes fifteen seconds.

Check yours right now

Open your site, bring up the browser console and type typeof window.ym. If the answer is "function", you are fine. If it is "object" or "undefined", no data is reaching your analytics, and the statistics you base decisions on are incomplete.

Business process automation: what to automate first and what pays back fastestBusiness automation usually starts from the wrong end: a company commissions a good-looking dashboard while the money keeps leaking out of how enquiries are handled. Here is the test for choosing the first process, and the three that turn out to be worth it almost every time.31% of calls missing from reports: how sales oversight breaksEvery evening the owner received a summary of how the sales team had performed. The summary lied: a third of the conversations were missing from it, and one segment was inflated threefold. The cause was a single line of code.