Problem/Motivation

Some users report that a single visitor session is being split into two visits in Matomo. For example, one user views two pages within a few seconds, but Matomo records them as two separate visits.

This appears to happen because the Matomo tracking code can be initialized more than once on the same page, which may cause duplicate or conflicting tracking requests.

Steps to reproduce

Install and enable the Matomo module.

Configure it with the standard async tracking snippet.

Visit one page on the site.

Quickly navigate to another page.

Check the Matomo visitor log.

Observe that the two page views may appear as two separate visits.

(You may also inspect the page source and see that the Matomo tracker is initialized more than once.)

Proposed resolution

Ensure that the Matomo tracker is only initialized once per page load.

The fix in MR !93 adds a global guard variable (for example, window.matomoDrupalTrackerInitialized) so that the tracking code runs only once. If the script is already initialized, it will not run again.

Workaround: Make sure the tracking snippet is not being added multiple times via theme templates or custom code.

Remaining tasks

Review and merge MR !93.

Perform manual testing to confirm visits are no longer split.

User interface changes

None.

Introduced terminology

window.matomoDrupalTrackerInitialized (new global flag to prevent double initialization).

API changes

None.

Data model changes

None.

Release notes snippet

Fixed an issue where the Matomo tracker could be initialized multiple times on a page, which could cause a single user session to be split into multiple visits.

Original report by mertero

A single user (same IP/computer) views two pages within seconds, but Matomo records this as two separate visits.

Comments