Open source  /  Implementation guide

Open-source implementation · Analytics & Attribution

Own your analytics and attribution on open source

What this is. A build-it-yourself path to the same outcome, made from open-source parts you host. It does not publish 5 Kings’ internal method, client data, or any third party’s confidential information — and it says plainly where the open-source path is weaker than a specialist service.

In one paragraph

Analytics is the one system where renting is indefensible: the data is your customers’ behaviour, the retention is your history, and the cost scales with your own success. This guide builds a first-party stack that answers the same questions a commercial product does, and shows you exactly where it will answer them less well.

What you end up with

  • First-party web and event analytics on your own domain, with raw data you can export
  • A warehouse where ad spend, web behaviour and orders sit in the same tables
  • Consent-aware collection, with a documented record of what is collected and why
  • Dashboards your team can build without a vendor seat limit

The reference stack

Every project below is open source and self-hostable. Licences are the ones the project publishes today; check them against your own distribution model before you ship, because a licence can change and an AGPL project has obligations a MIT project does not.

LayerOpen-source projectLicenceWhat it does for you
Web analyticsMatomoGPL-3.0Full-featured self-hosted analytics: goals, funnels, campaigns, ecommerce, raw log and API access. Heavier than the alternatives, and the closest to a full product.
Lightweight alternativeUmami or PlausibleMIT / AGPL-3.0Small, fast, cookie-free page analytics when you only need traffic and referrers.
Product eventsPostHogMIT (core)Per-user event streams, funnels, cohorts, session replay. Use it for behaviour, not for marketing reporting.
Ingestion + modelsmeltano or Airbyte (self-hosted)Apache-2.0 / ELv2Pulls ad platforms, CRM and store data into one warehouse on a schedule.
Transformationdbt-coreApache-2.0Versioned SQL models for sessions, conversion paths and channel attribution, with tests.
WarehousePostgreSQL or ClickHousePostgreSQL / Apache-2.0ClickHouse when event volume passes a few million rows a month; Postgres below that.
BIMetabase or SupersetAGPL-3.0 / Apache-2.0Self-serve dashboards without per-seat pricing.
ConsentKlaro or your own consent managerBSD-3-ClauseRecords consent state and gates tags; the log of what was consented is itself evidence.

Build it

1. Write the measurement plan first

One page: the questions you need to answer, the events that answer them, the properties each event needs, and the retention rule. Every later argument about ‘the data is wrong’ traces back to a missing line here. This document is more valuable than the tool choice.

2. Put analytics on your own subdomain

Serve the script and the collector from a domain you control. First-party delivery survives more blocking than a third-party domain, and it means a vendor outage is your outage, which is a truthful relationship to have with your own data.

3. Collect the minimum, log the reason

Session, page, referrer, campaign parameters, click id and the conversion event. Do not collect what you cannot justify in a privacy notice. Store the consent decision with the event so a later question about a specific period is answerable.

docker run -d --name matomo -p 8080:80 
  -v matomo-data:/var/www/html 
  -e MATOMO_DATABASE_HOST=db matomo:latest

4. Land everything in one warehouse

Web analytics, platform spend, CRM and orders into one database with a date dimension. Attribution is a join; without the join you are comparing four dashboards and calling it analysis.

5. Model attribution and label the model

Implement last-click, first-click and linear in dbt. Each output column should carry its model name, so no report can accidentally present a linear-attributed number as if it were last-click. This is the single most common source of false confidence.

6. Test the data, not just the dashboard

dbt tests for uniqueness on event id, non-null on session id, referential integrity between orders and sessions, and a freshness check. A dashboard built on untested data is decoration.

7. Publish a data dictionary

Every event, property and model with its definition and owner. When two teams disagree about what a ‘lead’ is, the dictionary is where the argument gets settled.

Acceptance checks

If you cannot verify a claim, it is not a finding. These are the checks that close the work; each one can be run by somebody who did not build it.

Acceptance checkHow to verify it
Script is served first-party and loads under 60 msNetwork tab and a Lighthouse run on the template.
Event volume reconciles with server-side order countDaily comparison of purchase events to orders; a persistent gap is a bug.
dbt tests pass on every runCI exit code plus a freshness assertion on each source.
Every attribution column names its modelColumn naming convention enforced in the dbt project.
Consent state is recorded with the eventQuery events for a null consent field; must be zero for post-launch periods.
Export works end to endMonthly export to Parquet/CSV, opened and row-counted — the proof that you can leave.

Effort and cost

Estimate
Skill neededIntermediate for web analytics; advanced for the warehouse and dbt layer
Build time1 day for Matomo/Umami, 3–5 days for the warehouse + dbt models + dashboards
Running costAbout 2 hours a month for maintenance, plus VPS cost; ClickHouse wants more RAM
What you must host4 GB VPS for the light stack; 8–16 GB if you run ClickHouse and PostHog together.

What open source does not give you

The honest half of the comparison. Each of these is a reason somebody buys the service instead of building it, and pretending otherwise would make the rest of this page worthless.

  • Cross-device identity without a login is not solvable. You get a probabilistic stitch at best, and a wrong one at worst.
  • Ad-platform click data and your own session data never fully agree. The platform counts impressions and modelled conversions you cannot see; you count sessions and events it cannot see.
  • Matomo’s richest features (heatmaps, session recording, A/B) are paid add-ons even in the self-hosted edition. The core is genuinely free; the edges are not.
  • Self-hosting means you own the uptime, the upgrades and the disk. A failed collector is silent data loss — monitor it like a production service.
  • Consent law is jurisdiction-specific. This guide builds the mechanism; it does not give you legal cover.

Scope only, stated so you can compare it with the build above.

  • The measurement plan reviewed against the questions the business actually asks
  • Attribution models built and reconciled against platform-reported numbers
  • Dashboard and dictionary maintenance, including when the schema changes

Sources and further reading

What this page does not include. This guide documents an open-source implementation of the same outcome. It deliberately leaves out 5 Kings’ internal playbooks, client data, vendor terms and unpublished method: we publish what any competent team can reproduce, and we do not publish what belongs to a client or to a contract. Where a step depends on a decision only your business can make, the guide says so instead of guessing.

Take it with you

Own your analytics and attribution on open source

The full guide as an A4 PDF: the reference stack with licences, the build steps, the acceptance checks and the honest limits — in one file you can hand to an engineer or print for a planning session.

PDF · A4 · no email required · free to redistribute with attribution

Open-source Guides & PDFs