Some pages are incorrectly being tracked without www in domain

We have Matomo Tag Manager running on more than 20 websites. Last year we launched a new one.

It is more or less conventional Drupal website, no headless Drupal or whatever.

All pages on this website have ‘www’ in the domain. Visitors of a non-www URL are automatically redirected to the corresponding URL with www.

However, on this website we see a particular pattern:

  • most pages on this website are correctly being tracked with www in the domain
  • a handful of pages on this site are being tracked without www

The pages that are being tracked without www, are always the same. Indepedent of visitor, referral, browser type, cookies, etcetera.

In the Matomo visitors log we see sessions in which both occur: e.g. the first 2 pages are tracked with www, the third without and the fourth with www. All within the same session of the same visitor.

What we already checked:

  • Are all non-www URL’s being redirected to www? (yes)
  • Both internal and external links to this page.
  • Is the Matomo Tag Manager configured correctly? (it seems so)
  • All kinds of other stuff: Javascript errors, internal redirects within the site, page caching configuration, http headers, etcetera.

Both the webdevelopment party and the hosting provider have looked into this issue. It looks like a mystery.

We have a few other sites built by the same webdevelopers and that are hosted by the same hosting provider. Also with Matomo containers with exactly the same configuration (but of course with other domains). On these sites this mystery does not occur; all pages within the same site are consistently being tracked.

Anyone any idea?

Problem solved.

The problem turned out not to be in the website, but in the Matomo database. I found the pages that were tracked without www in the MySQL database with url_prefix = 2. Changing 2 => 3 solved the problem immediately, also retroactively.

Presumably some of the pages had been stored with url_prefix 2, because a redirect from non-www to www was missing during the go-live last year. It was added later after going live.