Skip to content

Analytics ​

Google Analytics 4, Plausible, Matomo or Yandex Metrica on the site's pages.

kitloom/analytics · admins: kitloom/analytics-filament, kitloom/analytics-nova

Video lessons ​

Recorded in the Filament admin; the Nova admin works the same way.

Analytics Settings

Counts the site's visits with Google Analytics 4, Plausible, Matomo or Yandex Metrica. Any one of them works, or several at once. It does what Site Kit, MonsterInsights, the Plausible plugin, Connect Matomo or the Yandex Metrica plugin did on the WordPress site, and their settings can be imported. The admin page is the Analytics section (kitloom/analytics-filament or kitloom/analytics-nova).

Setting it up ​

Open Analytics → Settings and fill in the service you use. An empty ID means that service is off.

ServiceWhat to enterWhere to find it
Google Analytics 4Measurement ID, G-XXXXXXXXXXGoogle Analytics → Admin → Data streams → the site's stream
PlausibleThe domain, as added in PlausiblePlausible → the site → Site settings
The script, if not the defaultSite settings → Site installation: the site's own pa-….js, a self-hosted Plausible's https://stats.example.com/js/script.js, or a script with extensions (script.outbound-links.file-downloads.js)
MatomoThe Matomo address and the site IDMatomo → Administration → Websites → Manage
Yandex MetricaThe counter's numberMetrica → the counter's settings. Webvisor is a separate switch

The counters go into the head of every page of the theme, where the theme put @siteHead.

With the Cookie Consent module installed, each counter waits for the visitor's answer:

ServiceNeeds consent to
Google Analytics 4statistics. With Google Consent Mode on in Cookie Consent, it loads at once with every signal denied and follows the visitor's answer.
Plausiblenothing by default: it sets no cookies and keeps no personal data. Count without consent off makes it wait for statistics.
Matomostatistics. With Without cookies on, it counts without consent (Matomo then cannot tell a returning visitor from a new one).
Yandex Metricastatistics

Without a consent module, every counter loads at once.

Who is counted ​

Signed-in users (editors, administrators, customers with an account) are not counted by default, so the site's own people do not skew the numbers. Count signed-in users turns that off. Pages for guests are cached as before: a signed-in user's page is always drawn anew, so leaving the counter out of it affects nobody else.

Pages without a reload ​

In an Inertia theme, the next page opens without a reload:

  • Google Analytics counts these pages itself, through its "page changes based on browser history" measurement (on by default).
  • Plausible counts them itself too.
  • Matomo and Yandex Metrica are sent each new page by the module.

Shop sales ​

With the shop module, Google Analytics also receives the shop's e-commerce events:

  • view_item — a product page is opened;
  • add_to_cart — a product goes into the cart;
  • begin_checkout — the checkout form is opened;
  • purchase — the "order received" page is shown, with the order number, total, tax and shipping.

They appear in GA4's Monetization reports without any setup. Each order is sent once per browser, however often its page is opened again. A failed or cancelled order is not sent.

The other services here count visits only.

Coming from WordPress ​

If the WordPress site had one of these plugins, the settings page shows an Import button. The console command does the same:

bash
php artisan analytics:import
php artisan analytics:import --from=sitekit --from=plausible
PluginWhat is taken
Site Kit by GoogleThe GA4 measurement ID, if Site Kit placed the tag. Whether signed-in users were excluded.
MonsterInsightsThe GA4 ID, connected or entered by hand. If any roles were excluded, signed-in users stay uncounted.
Plausible AnalyticsThe domain, and the site's script or the self-hosted address.
Connect MatomoThe Matomo address (including a Matomo Cloud account), the site ID, and "without cookies".
Yandex MetricaThe first counter and its Webvisor setting.

The plugins' options are not touched. What a plugin did not set stays as it is here.

Not carried over:

  • Matomo's extra tracking (404s, site search, user ID).
  • Plausible's custom properties and excluded pages.
  • MonsterInsights' per-role exclusions. Only "signed-in or not" is kept.

For developers ​

  • Settings: analytics_*, declared by AnalyticsOptions and written through SettingWriter.
  • How the counters reach the page:
    • AnalyticsScripts is the PageScriptsProvider.
    • Each service is a Trackers\Tracker with its snippet and consent category.
    • Every snippet goes through kitloom/site's ScriptConsent::gate(). GA4 says it reads Google Consent Mode.
  • CSP: a nonce set with Vite::useCspNonce() goes on the scripts.
  • Config: php artisan vendor:publish --tag=kitloom-analytics-config publishes the admin sections switch (filament.register, nova.register).
  • Tests, from the application that installs the package: php vendor/bin/phpunit --testsuite Analytics.

kitloom — modules and themes for Laravel.
Pricing · Services · License · Refunds · Privacy · Community · [email protected]