Browse AjaxPress docs

Analytics, Tag Manager and consent banners

On this page

Analytics usually needs no setup with AjaxPress. This page explains why, covers the one Google Analytics 4 setting worth changing, and shows how to check your numbers.

Why your tracking keeps working

With AjaxPress, each page your visitors see still loads as a complete WordPress page. It loads out of sight and is then swapped in. So the tracking code your site already has (the Google tag, Tag Manager, Site Kit, MonsterInsights, Matomo, Plausible, Fathom, the Meta Pixel) runs on every page, just as it did before, and records each page view with the right address and title.

Google Analytics 4’s Average engagement time is measured correctly as well. It read zero on AjaxPress versions before 2.4.2.

One GA4 setting to change

Turn off GA4’s history-based page views, so no page is counted twice:

  1. In Google Analytics, go to Admin → Data streams and open your web stream.
  2. Click the gear icon next to Enhanced measurement.
  3. Open Page views → Show advanced settings.
  4. Untick Page changes based on browser history events, and save.

Page views still come from each page load. This setting only makes GA4 count address-bar changes as extra views, and AjaxPress changes the address bar on every navigation.

Google Tag Manager

Your container’s All Pages and DOM Ready triggers fire on every page, as before, because every page is a full page load.

AjaxPress also pushes an event to the top window’s dataLayer after each page change (not on the first page):

{
  event: 'ajaxpress_page_view',
  page_location: 'https://example.com/new-page/',
  page_title: 'New page',
  engagement_time_msec: 12840  // time spent on the previous page
}

Most sites don’t need it, because their tags already run on every page. Use it only for a tag that has to live in the top window and follow navigation, and don’t combine it with page-view tags that already fire on All Pages, or you’ll count every page twice.

Consent banners (Complianz, CookieYes, Cookiebot, iubenda, Borlabs and others) show once, as usual. A visitor’s choice is stored the normal way (in a cookie or local storage), and every following page reads it, so the banner doesn’t come back after they have chosen.

On AjaxPress versions before 2.4.2, a banner could appear twice on the first page a visitor loaded. Update if you see that.

Prefetch and page views

With prefetch (AjaxPress Pro), a page starts loading when a visitor’s pointer rests on its link. It loads in full, out of sight, with its tracking code. So a page that was hovered but never opened can be recorded as a page view, and if the visitor then clicks, the view is already recorded before the page is shown.

If exact page view numbers matter more to you than the speed gain, leave prefetch off, or compare a week with it on and a week with it off.

Check your numbers

  1. Open GA4 Admin → DebugView, or Tag Manager’s Preview mode.
  2. Browse five or six pages on your site, then press Back and Forward a few times.
  3. Check that there is exactly one page view for each page you saw, with the right address and title.
SymptomCause
Each page counted twiceHistory-based page views are still on in GA4, or an ajaxpress_page_view tag duplicates an All Pages tag
More page views than expected, on a site with prefetch onHovered pages are counted. See Prefetch and page views
Engagement time reads zeroAjaxPress is older than 2.4.2. Update
The consent banner appears twiceAjaxPress is older than 2.4.2. Update

Developers: every event AjaxPress fires is listed in the JavaScript events and markup reference.