Skip to content

Matomo (Self-Hosted)

Matomo is the closest feature-equivalent to GA4 in the analytics space that prioritizes data ownership. It’s open-source (GPL), self-hostable, and formerly known as Piwik. If you need GA4-level features without sending data to Google, Matomo is the answer.

Matomo comes in two flavors. Choose based on your infrastructure capacity, not feature needs — both are functionally identical.

  • Cost: Free (you pay for server)
  • Data ownership: 100% — your server, your data
  • Infrastructure: PHP 7.2+ and MySQL 5.7+ (or MariaDB)
  • Maintenance: You handle updates, backups, scaling
  • Latency: Depends on your server
  • Best for: Teams with DevOps capacity, strict data residency requirements, enterprises

Self-hosting requires ongoing work. You need to patch security updates, monitor disk space, handle backups, and scale the database as traffic grows. If this sounds like a burden, use Cloud.

Matomo integrates with GTM in two ways. The direct JavaScript approach is simpler.

Matomo has a community-contributed template in GTM’s template gallery.

  1. In GTM, go TemplatesTag Templates → click the search icon
  2. Search for “Matomo” — look for the community template
  3. Add to your workspace
  4. Create a new Tag using the Matomo template
  5. Enter your Matomo site URL and Site ID
  6. Add an All Pages trigger
  7. Test with Preview/Debug

Pros: Abstraction layer, variables for Site ID, built-in error handling Cons: Depends on community maintenance, one extra abstraction

Skip the template. Load Matomo directly via GTM Custom HTML.

<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://your-matomo-domain.com/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']); // Replace with your Site ID
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 this via TagsNewCustom HTML, trigger on All Pages.

Pros: Simple, no template dependency, full control Cons: Raw JavaScript, no GTM variable abstraction

FeatureGA4Matomo
Custom dimensionsYesYes (called “Custom Dimensions”)
Custom eventsYesYes (called “Goals” or custom events)
Ecommerce trackingYesYes (full product/order tracking)
FunnelsYesYes
SegmentsYesYes
CohortsLimitedYes (called “Segments”)
User journeysLimitedYes (User Flow)
Session recordingsVia GA4 + ClarityVia plugins (heatmaps.com integration)
API accessYes (Reporting API)Yes (API for raw data)

Both are feature-complete for ecommerce and content analytics. Matomo’s reporting is more flexible because you own the database.

  1. No data sampling: Matomo never samples. 100% of hits counted, always. GA4 samples at high traffic volumes (>10M events/month).

  2. Full data ownership: Your data lives on your server or Matomo’s. Not Google’s servers, no data sharing with other Google products.

  3. Raw data access without BigQuery: Direct database queries or API calls. No need for BigQuery export and learning SQL.

  4. Cookieless tracking without consent: Matomo can use fingerprint-free tracking. Analytics works without a consent banner (though GDPR still applies to the tracking itself).

  5. Visitor log: Individual visit details. You can browse someone’s session including every page, click, and event. GA4 removed this (you need an add-on like Clarity).

  6. No data deletion: By default, Matomo keeps all historical data. GA4 has a 14-month rolling window then deletes.

  7. Custom reports from raw data: Write ad-hoc queries. No UI limitations.

  1. No native Google Ads integration: Can’t send Matomo audiences to Google Ads, can’t import Google Ads conversion data back into Matomo automatically.

  2. No audience sharing: Can’t sync audiences to Facebook, LinkedIn, DV360, etc. You’d need a CDP in front.

  3. No BigQuery export shortcut: You can export via API/MySQL, but it’s not a one-click like GA4 → BigQuery.

  4. No predictive metrics: GA4 has predictive churn, purchase probability, etc. Matomo doesn’t (you’d add a CDP for this).

  5. No machine learning features: No automatic anomaly detection, no AI-driven insights like GA4 has.

  6. Smaller community: Fewer tutorials, plugins, and integrations compared to GA4. Stack Overflow answers are sparse.

  7. Self-hosted maintenance: If you self-host, you own the operational burden.

Matomo supports server-to-server tracking via the HTTP Tracking API. This is useful for tracking conversions from your backend, offline orders, or server-side CRM events.

Terminal window
curl -X POST "https://your-matomo-domain.com/matomo.php" \
-d "module=API" \
-d "method=Tracking.trackAction" \
-d "idsite=1" \
-d "rec=1" \
-d "token_auth=YOUR_TOKEN" \
-d "url=https://yoursite.com/order-confirmed" \
-d "action_name=Purchase" \
-d "e_c=Ecommerce" \
-d "e_a=Order" \
-d "e_v=99.99"

Full docs: Matomo Tracking API

This is how you track:

  • Completed transactions from your backend
  • Offline orders synced from your CRM
  • Server-side conversions that don’t happen in the browser

Matomo’s ecommerce module tracks the full customer journey: product views → cart → purchase.

// Product view
_paq.push(['setEcommerceView', '12345', 'Blue Shoe', 'Footwear', 49.99]);
_paq.push(['trackPageView']);
// Add to cart
_paq.push(['addEcommerceItem',
'12345', // Product SKU
'Blue Shoe', // Product name
'Footwear', // Category
49.99, // Price
2 // Quantity
]);
_paq.push(['trackEvent', 'Ecommerce', 'Add to Cart']);
// Purchase
_paq.push(['addEcommerceItem', '12345', 'Blue Shoe', 'Footwear', 49.99, 2]);
_paq.push(['trackEcommerceOrder',
'ORDER-123', // Order ID
99.98, // Grand total (with discount applied)
49.99, // Subtotal (before tax/shipping)
0, // Tax
20.00, // Shipping
'US' // Country
]);
_paq.push(['trackPageView']);

GA4 uses event-based ecommerce (no dedicated ecommerce tracking API). You fire events like:

gtag('event', 'view_item', {
items: [{
item_id: '12345',
item_name: 'Blue Shoe',
price: 49.99
}]
});

Matomo’s approach: Purpose-built ecommerce tracking with a clear API. GA4’s approach: Generic events with ecommerce parameters.

Both work. Matomo feels more ecommerce-native; GA4 is more flexible but requires more mental mapping.

Matomo can run analytics without cookies using fingerprinting. The privacy trade-off:

  • Pros: No cookie consent needed, GDPR-compliant, lighter on users
  • Cons: Less accurate session detection, no cross-device tracking, fingerprints can be spoofed

Enable in SettingsWebsitesDisable Cookies. Matomo switches to IP + User-Agent fingerprinting.

This is useful if you:

  • Want analytics without a consent banner
  • Target EU users with strict privacy policies
  • Prefer simplicity over precision

Choose Matomo if:

  • Data residency is mandatory: Your data must stay in your country/region (EU GDPR, Japan, etc.)
  • You want GA4-level features without Google: Full custom dimensions, ecommerce, funnels, all owned by you
  • You have DevOps capacity: Self-hosting is fine because you can maintain it
  • You don’t need Google Ads integration: Your conversions don’t feed Google Ads campaigns
  • You want to avoid consent complexity: Cookieless mode works for you
  • Historical data access matters: You want 5+ years of data without UI limitations

Don’t choose Matomo if:

  • Google Ads is core to your marketing: You need conversion imports and audience sharing
  • You have no DevOps team: Cloud option exists, but costs add up
  • You need predictive audiences: GA4’s churn/purchase prediction adds value for you
  • BigQuery is part of your workflow: Matomo’s raw data access is good, but not as integrated