Analytics
Add analytics to your site by editing settings/analytics.md. Supports Google Analytics, Plausible, Fathom, Umami, Simple Analytics, PostHog, and Matomo out of the box — or paste any custom script.
Quick setup
Set the provider in settings/analytics.md and configure your tracking ID using the CLI:
# settings/analytics.md
---
provider: plausible
---
sitemd config set analytics.id yourdomain.com
Or use the interactive setup to configure everything at once:
sitemd config setup analytics
The build system injects the correct script tag into <head> on every page. Tracking IDs and pixels are stored in .sitemd/config.json (gitignored), not in your settings files. See CLI Config for details.
Supported providers
| Provider | provider value |
id value |
host needed? |
|---|---|---|---|
| Google Analytics 4 | google |
Measurement ID (G-XXXXXXXXXX) |
No |
| Plausible | plausible |
Your domain (example.com) |
No |
| Fathom | fathom |
Site ID | No |
| Umami | umami |
Website ID | Yes, if self-hosted |
| Simple Analytics | simpleanalytics |
Your domain | No |
| PostHog | posthog |
API key | Yes, if self-hosted |
| Matomo | matomo |
Site ID | Yes |
Self-hosted providers
For self-hosted instances of Umami, PostHog, or Matomo, also set the host:
sitemd config set analytics.id a1b2c3d4-5678-90ab-cdef-1234567890ab
sitemd config set analytics.host https://analytics.yourdomain.com
Ad tracking pixels
Add conversion tracking pixels for ad platforms using the CLI:
sitemd config set analytics.pixels '[{"meta":"1234567890"},{"google-ads":"AW-123456789"}]'
Each pixel injects the platform's official base code into <head> on every page. Supported platforms:
| Platform | Key | ID value |
|---|---|---|
| Meta (Facebook) Pixel | meta |
Pixel ID (numeric) |
| Google Ads | google-ads |
Conversion ID (AW-XXXXXXXXX) |
| LinkedIn Insight Tag | linkedin |
Partner ID (numeric) |
| TikTok Pixel | tiktok |
Pixel ID |
If you're using provider: google for analytics, the Google Ads pixel shares the same gtag.js loader — no duplicate scripts.
You can combine analytics, pixels, and GTM in the same file. Use as many or as few as you need.
Google Tag Manager
For teams that manage all tracking through GTM:
sitemd config set analytics.gtm GTM-XXXXXXX
This injects the GTM container script in <head> and the required <noscript> fallback in <body>. Once GTM is set up, you can manage all your analytics and ad pixels through GTM's web interface instead of adding them individually here.
Custom scripts
For any provider not listed above, use customHead to inject raw HTML into <head>:
sitemd config set analytics.customHead '<script src="https://example.com/tracker.js" defer></script>'
You can combine customHead with any other setting — all are injected together.
Related
- For search engine optimization, Open Graph tags, structured data, and search engine verification codes, see SEO.
- For transactional email templates using the same CLI-managed pattern, see Email Templates.
- For how credentials are stored and managed, see CLI Config.