Check 41.04 · Tracking and analytics setup

Set up GA4, Matomo or an equivalent

Choose between GA4, Matomo or an alternative, make the settings that matter and install the code on WordPress, Shopify, Laravel or Next.js.

Priority
Critical
Difficulty
Intermediate
Estimated time
1 to 3 h
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

A web analytics tool (Google Analytics 4, Matomo, Plausible, Piwik PRO…) measures what visitors do once they reach the site: where they come from, which pages they view, whether they get in touch or buy. The task is to choose one main tool, create it with the right settings and install its code once on every page. Once this is done, each visit is attributed to its source, including AI assistants that pass on a referrer.

Why it matters

Search Console and Bing Webmaster Tools stop at the click. They tell you how many people arrive from search engines, not what they do next. The analytics tool takes over from there: landing pages, engagement, journeys, conversions, revenue.

It is also the tool that shows traffic from generative engines. When a user clicks a source in ChatGPT, Perplexity, Gemini, Copilot or Claude, the visit often arrives with an identifiable referrer (chatgpt.com, perplexity.ai…) or a UTM parameter. Without an analytics tool, this traffic is invisible. See identify ChatGPT, Perplexity, Gemini, Copilot and Claude referrers (opens in a new tab).

A badly configured tool (duplicate code, data kept for two months, internal traffic mixed in) leads to decisions based on wrong figures.

What it improves

  • Attribution Each visit and each conversion attributed to a channel (organic search, AI, social media, email, advertising).
  • Content management Organic and AI landing pages, pages that convert, pages that drive visitors away.
  • Measuring SEO and GEO ROI Conversions and revenue by channel, the basis for track conversions, forms and quote requests (opens in a new tab).
  • Rankings No effect. Google does not use Google Analytics data to rank pages.
  • Performance A possible negative effect. Every third-party script costs a little loading time; a single tool, loaded asynchronously, limits that cost.

How to check

  1. Is the code present? View a page's source (Ctrl+U) and search for G- (Google tag), GTM- (Tag Manager), matomo.js or piwik.js.
  2. Only once? The same G- ID must appear only once, or only through Tag Manager.
  3. Is data being sent? Browser developer tools, Network tab, filter collect: one request to …/g/collect?v=2&tid=G-… per page for GA4. For Matomo, filter on matomo.php.
  4. Is data arriving? GA4's “Realtime” report, or Matomo's “Visitors > Visits Log”, while you browse.

The full procedure, including consent handling, is in check data collection (opens in a new tab).

How to implement

Before you start: choose the tool

Tool Data hosting Cost Strengths Points to watch
Google Analytics 4 Google Free (360 is paid) Search Console and Google Ads links, ecosystem, modeling Consent required in the EU, sampled or thresholded data in some reports
Matomo On-Premise Your server Free (open source), paid plugins Full control of the data, can be configured to run without consent in France under conditions Server and updates to manage
Matomo Cloud Matomo's infrastructure Subscription Same reports without a server Cost depends on volume
Plausible, Piwik PRO, Umami Depends on the plan Free to paid Lightweight or compliant, depending on the product Fewer reports, limited Google integrations

Selection rules:

Create and configure a GA4 property

  1. In Google Analytics, Admin > Create > Account, then Property: name, reporting time zone and currency. These last two settings determine how days are split and how amounts are shown.
  2. Admin > Data collection and modification > Data streams > Add stream > Web: main URL, stream name, enhanced measurement turned on.
  3. Copy the “Measurement ID” (G-XXXXXXXXXX) from the stream details.

Settings to make right away:

Setting Path Recommended value
Data retention Admin > Data settings > Data retention 14 months (the maximum for a standard property). This setting affects only explorations, not standard reports
Enhanced measurement Web stream details On; check “Page views” and URL changes on a single-page site
Internal traffic Stream details, Configure tag settings > Define internal traffic, then Data filters See exclude internal traffic if relevant (opens in a new tab)
Unwanted referrals Stream details, Configure tag settings Payment domains (PayPal, bank) so they do not steal attribution
Search Console link Admin > Product links > Search Console links One web stream linked to one Search Console property
Access Admin > Account access management At least two internal administrators

Warning: data retention does not apply retroactively. A property left at 2 months has already lost the detail of previous months for explorations. Set it to 14 months as soon as the property is created.

Create and configure a site in Matomo

Versions Matomo 5 (On-Premise and Cloud).

  1. Matomo Cloud: create the account on Matomo's website. On-Premise: install Matomo on a subdomain (matomo.example.com) following the official installation guide, with PHP, MySQL or MariaDB and HTTPS.
  2. Administration (gear icon) > Websites > Manage > Add a new website: name, URL, time zone, currency, and the ecommerce option for a store.
  3. In the website settings: excluded IP addresses (office, contractors) and URL parameters to exclude (session IDs).
  4. Administration > Privacy > Anonymize data: anonymize at least two bytes of the IP address, and regularly delete old raw data.
  5. The code is in Administration > Websites > Tracking Code, JavaScript section.

To run without consent in France, Matomo must be configured according to the conditions set by the CNIL (the French data protection authority): purpose limited to audience measurement, anonymous statistics, no cross-referencing and no tracking across sites. Matomo publishes a dedicated configuration guide; see also handle applicable consent requirements (opens in a new tab).

Code to install

Google tag for GA4, right after <head>, on every page:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>

Matomo code, in the <head> or right after <body>:

<!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u = "https://matomo.example.com/";
    _paq.push(['setTrackerUrl', u + 'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
    g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s);
  })();
</script>

Preferably copy the code shown in your own interface: it already contains your IDs. If a consent banner must block the tool, connect it before going live.

WordPress

Versions WordPress 6.4 and later; Site Kit by Google, Matomo Analytics and Connect Matomo, November 2026 versions.

  • GA4 with Site Kit by Google: Site Kit > Settings > Connect More Services > Analytics. The plugin creates or selects the property and inserts the tag. Site Kit also offers a Consent Mode setting, which relies on the WP Consent API plugin and on a compatible banner plugin.
  • Matomo inside WordPress: the Matomo Analytics plugin installs Matomo inside WordPress, with data stored in the site's database. Convenient for a small site; avoid it on a high-traffic site, where it would load the database.
  • Existing Matomo (Cloud or dedicated server): use the Connect Matomo plugin, not the Matomo Analytics plugin.
  • Through Tag Manager: if GTM is already in place, do not also install a GA4 plugin.

Shopify

Versions Shopify admin, all plans, November 2026.

  • GA4: install the Google & YouTube sales channel, connect the Google account and choose the GA4 property. Standard ecommerce events (product views, add to cart, purchases) are then sent automatically. The store must no longer be password-protected.
  • Matomo or another tool: Settings > Customer events > Add custom pixel. The pixel runs in a sandbox: you must subscribe to Shopify events (page_viewed, checkout_completed…) to pass them on to the tool.

Do not also add a GA4 tag in theme.liquid: page views would be counted twice.

PrestaShop

Versions PrestaShop 8 and 9.

PrestaShop provides a Google Analytics module (ps_googleanalytics) in Modules > Module Manager: update it, enter the G-… Measurement ID and enable ecommerce tracking. For Matomo, use a module from the PrestaShop Addons marketplace, or paste the code into your theme's head template. Check the module's compatibility with your version before installing it.

Drupal

Versions Drupal 10 and 11.

  • GA4: the Google Tag module, then Configuration > Web services > Google Tag: add the G-… ID (the same module also handles a GTM container).
  • Matomo: the Matomo Analytics module, then enter your instance URL and the site ID.

Wix

Versions Wix dashboard, Premium plans with a connected domain, November 2026.

Marketing & SEO > Marketing Integrations > Google Analytics, then “Connect” and paste the Measurement ID. For another tool, use Settings > Custom Code and load the code in the head of every page.

Squarespace

Versions Squarespace 7.1, November 2026.

Paste the Measurement ID into the site settings' native Google Analytics field, not into Code Injection, and turn on Squarespace's cookie banner. Other tools go through Code Injection, depending on the plan.

Webflow

Versions Webflow, all site plans, November 2026.

Site settings > Apps & integrations, Google Analytics section: paste the Measurement ID, then publish. For Matomo or another tool: Site settings > Custom code, Head code area.

Laravel

Versions Laravel 11 to 13.

Declare the ID in the configuration, then load the tag only in production:

// config/services.php
'google_analytics' => [
    'measurement_id' => env('GOOGLE_ANALYTICS_ID'),
],
{{-- resources/views/partials/analytics.blade.php --}}
@production
    @if(config('services.google_analytics.measurement_id'))
        <script async src="https://www.googletagmanager.com/gtag/js?id={{ config('services.google_analytics.measurement_id') }}"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', @json(config('services.google_analytics.measurement_id')));
        </script>
    @endif
@endproduction

Include the partial at the top of the layout's <head>: @include('partials.analytics'). For Matomo, the same principle applies with the Matomo code and a setSiteId read from the configuration.

Next.js

Versions Next.js 15 and 16 (App Router).

The @next/third-parties package (experimental according to its documentation) loads GA4 after hydration:

npm install @next/third-parties@latest
// app/layout.tsx
import { GoogleAnalytics } from '@next/third-parties/google';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="fr">
      <body>{children}</body>
      <GoogleAnalytics gaId="G-XXXXXXXXXX" />
    </html>
  );
}

Client-side navigations are counted if the enhanced measurement option “Page changes based on browser history events” is turned on.

For Matomo, load the code with next/script and send a page view on every route change:

// app/matomo.tsx
'use client';

import Script from 'next/script';
import { usePathname } from 'next/navigation';
import { useEffect, useRef } from 'react';

declare global {
  interface Window {
    _paq?: unknown[][];
  }
}

export function Matomo() {
  const pathname = usePathname();
  const isFirstLoad = useRef(true);

  useEffect(() => {
    if (isFirstLoad.current) {
      isFirstLoad.current = false;
      return;
    }

    window._paq = window._paq || [];
    window._paq.push(['setCustomUrl', window.location.href]);
    window._paq.push(['setDocumentTitle', document.title]);
    window._paq.push(['trackPageView']);
  }, [pathname]);

  return (
    <Script id="matomo" strategy="afterInteractive">
      {`var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
  var u = "https://matomo.example.com/";
  _paq.push(['setTrackerUrl', u + 'matomo.php']);
  _paq.push(['setSiteId', '1']);
  var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
  g.async = true; g.src = u + 'matomo.js'; s.parentNode.insertBefore(g, s);
})();`}
    </Script>
  );
}

Add <Matomo /> to app/layout.tsx.

Common mistakes

  • Installing the same tag twice (plugin and theme, or hard-coded and through GTM): doubled page views, an artificially low bounce rate.
  • Leaving retention at 2 months in GA4: year-long explorations become impossible.
  • Default time zone or currency: shifted days, revenue in the wrong currency.
  • Property created with a contractor's account: the company loses control when the contract ends.
  • Not declaring payment domains as unwanted referrals: sales are attributed to the bank or to PayPal instead of the original channel.
  • Loading the tool on staging: tests pollute the statistics.
  • Installing Matomo for WordPress on a large site: the database becomes saturated.
  • Believing the tool measures every visit: consent refusals, blockers and private browsing let some visits escape, hence the value of documenting the limits of attribution (opens in a new tab).

Frequently asked questions

GA4 or Matomo: which should I choose for a French site?

GA4 is free and integrates with Search Console and Google Ads, but it sets cookies and sends data to Google: in the EU, it requires visitors' consent. Matomo, self-hosted or in the Cloud, keeps the data under your control and, configured according to the CNIL's conditions, can measure audience without consent. Many sites choose Matomo as their main tool and GA4 for advertising.

Does Google Analytics affect SEO?

No. Google does not use Google Analytics data to rank pages, and a site without GA4 is not at a disadvantage. The tool helps you understand what visitors from search engines do: landing pages, engagement, conversions. It can even slow loading slightly: install a single tag, loaded asynchronously, to limit that cost.

How long does GA4 keep data?

A standard GA4 property keeps user-level and event-level data for 2 or 14 months, depending on the setting chosen in Admin, Data settings, Data retention. This setting only concerns explorations; aggregated standard reports are not affected. Set it to 14 months as soon as the property is created, because it does not apply retroactively.

Can I install GA4 and Matomo at the same time?

Technically yes, but it doubles the script weight and the consent work, and the two tools will give different figures, because they do not count visits in the same way. Keep one reference tool for reporting. A second tool is justified for a transition period or for a specific need, such as Google Ads advertising.

Updated on

Topic checklist (PDF)

And now?

In the “Tracking and analytics setup” topic

  1. Set up Google Search Console
  2. Verify the domain property via DNS
  3. Set up Bing Webmaster Tools
  4. Set up GA4, Matomo or an equivalent
  5. Set up Google Tag Manager if needed
  6. Check data collection
  7. Handle applicable consent requirements
  8. Track conversions, forms and quote requests
  9. Track phone and email clicks
  10. Track downloads and sign-ups
  11. Track purchases
  12. Set up cross-domain tracking if needed
  13. Fix duplicate conversions
  14. Exclude internal traffic if relevant
  15. Identify organic and AI landing pages
  16. Create a dedicated channel for AI traffic
  17. Identify ChatGPT, Perplexity, Gemini, Copilot and Claude referrers
  18. Use available UTM parameters
  19. Connect analytics to the CRM if relevant
  20. Measure lead quality and revenue
  21. Document the limits of attribution
  22. Set up Consent Mode v2 if you use Google tags