Check which Analytics code the site uses. If it is the old version at the bottom of each page, replace it with the asynchronous snippet just before the end of the head, then compare the figures.

Visits the phone heard about

A roofing company's site was built a few years ago and still does its job. Its home page carries a slider of finished roofs, a Facebook box, a Twitter feed and a dozen scripts for menus and forms.

At the very end of each page, after all of that, sits the Google Analytics code. Callers often say they looked the company up on their phones, yet the reports show few visits from phones.

Some of those visits were never recorded at all. The visitor arrived, found the phone number and called before the code at the bottom had a chance to run.

Why the bottom of the page counts last

A browser reads a page from top to bottom. Most scripts make it stop at each one, fetch it and run it before going further, so everything below waits.

The tracking code records a visit only when it runs. At the end of a slow page, that is after the slider, the feeds and every other script have loaded.

A visitor who taps back, follows a link or loses the signal before that point leaves no trace in Analytics. The visit happened; the report simply never heard about it.

The visits that go missing

The fourth matters most. Those visitors got exactly what they came for, and the reports leave them out entirely.

Which code is on the site

Open a page, view its source from the browser's menu, and search for a few words. The oldest code mentions urchin, and the version after it uses pageTracker; both were meant for the bottom of the page.

The current version, the asynchronous snippet, contains _gaq and belongs just before the end of the head section, near the top of the page's code.

Check every kind of page, not only the home page. Older sites often have the code in several templates, and one may differ from the rest or carry two copies.

A worked example

A smoothie bar a block from the beach in Tofino has a site built three summers ago: a photo slider, a Facebook box, a Twitter feed, a menu page and a map.

Most of its visitors look it up on phones, often from a campsite or a beach parking lot with a poor signal. Analytics showed few phone visits and an oddly low bounce rate.

The tracking code was the pageTracker version, in the footer template, below the Facebook box and the slider's scripts. On a slow connection it ran last, if it ran at all.

The company that maintains the site put the asynchronous snippet in the header template and removed the old code.

It then watched the Real-Time report while loading pages on a phone, first on the bar's wireless and then on a cellular signal down the road.

Two weeks on, the reports included phone visits and quick exits that had always happened but had never been counted, and the bounce rate looked worse for it.

The bar itself had not changed. The figures had simply started to describe the visitors it actually had.

Moving to the asynchronous snippet

The asynchronous snippet loads Analytics alongside the page instead of holding it up, so it can sit near the top and record the visit early without slowing anything down.

Copy it from the tracking code page in the account's admin settings, and put it in the site's header template once, so every page gets it. Remove the old code at the same time.

If the old code did more than count visits, such as recording ecommerce sales or tracking across two domains, those lines must be rewritten in the new form. That part is worth handing to whoever set them up.

Where the code lives

On most sites the tracking code sits in one template shared by every page. On older hand-built sites it may be pasted into each page separately, which is how copies drift out of step.

On a WordPress site it is normally in the theme's header template or a box in the theme's settings. Code pasted into a theme file can vanish when the theme is updated or replaced, so note where it went.

Checking the change

With the Real-Time report open, load a page on a phone. The visit should show up within seconds.

View the source of several pages to confirm the snippet appears once and the old code is gone. Two copies would count every page view twice, which is harder to spot than a missing one.

Reading the figures afterwards

Mark the date of the switch with an annotation, so the jump in the line makes sense to anyone reading the reports in a year.

Compare a few weeks after with the same weeks before, looking at visits from phones, the bounce rate and time on site. Expect all three to shift, because the quickest and slowest visits are now part of the count.

A jump in recorded visits after the change is not a jump in visitors. It is the gap between what happened and what was counted, closing.

The counter-case

A light, fast page that loads in a second or two loses few visits to old code at the bottom. The difference after moving it may be small.

A site about to be replaced may not be worth touching; the new build should simply start with the current snippet in the right place.

For any site staying up for months, the change is a small job, and every report after it rests on a fuller count.

Moving the code up

  1. View the source of several kinds of page.
  2. Identify the version of the tracking code.
  3. Copy the asynchronous snippet from the account.
  4. Place it once in the header template.
  5. Rewrite any extra settings in the new form.
  6. Test with the Real-Time report on a phone.
  7. Annotate the date and compare the weeks before and after.

Step seven protects the next decision. Without a note on the date, someone reading the reports in six months may credit the change in the figures to an advertisement or the season.

Once every visit is counted, the timings in the Site Speed report are worth reading too, with the sampling caveat explained in the site speed report built from a handful of visits.


Frequently asked questions

Why would Analytics miss visits?

The code records a visit only when it runs. At the bottom of a slow page, visitors who leave before it loads are never counted.

How can I tell which tracking code my site uses?

View the page source and search. Urchin or pageTracker means older code meant for the bottom; _gaq means the asynchronous snippet, which belongs in the head.

Will the asynchronous snippet slow my pages?

No. It loads alongside the page instead of holding it up, which is why it can sit near the top and record each visit early.

Why did the bounce rate rise after the change?

The quickest visits, which the old code often missed, are now counted. The visitors have not changed; the count has simply become more complete.

What if the old code tracked sales or events?

Those extra lines must be rewritten for the new snippet, or the ecommerce and event reports will stop. Ask whoever set them up to do it.

How do I check that the new code works?

Watch the Real-Time report while someone loads a page on a phone; the visit should show up within seconds. Then confirm the source holds one copy.

West Coast Media Solutions Inc. provides web design, web development, hosting, digital marketing, and business consulting to organisations across Canada, drawing on more than twenty-five years in the field.

Analytics code still at the bottom of the page?

Point us to your site, and we will check which tracking code it runs and move it to where it belongs.

Start a Conversation