In one paragraph
The ad platforms are closed. Their buying interfaces, auction data and attribution windows are not something you can self-host, and any guide claiming otherwise is selling a scraper. What you can own is everything around them: the landing pages, the click and call tracking, the spend and conversion warehouse, the alerting, and the creative testing loop. That is where most of the waste actually is.
What you end up with
- Click and conversion tracking that is not blocked by the ad platform’s own script policy
- A spend + conversion warehouse you query yourself, with the platform’s numbers reconciled to yours
- Call tracking with real call records, duration and source attribution
- Alerting when spend runs without conversions, or when a landing page stops converting
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.
| Layer | Open-source project | Licence | What it does for you |
|---|---|---|---|
| Web + campaign analytics | Matomo | GPL-3.0 | Self-hosted analytics with campaign parameters, goals, funnels and the raw visit log you can export. |
| Event tracking (product-level) | PostHog | MIT (core) | Event-level tracking, session replay and experiments when you need per-user behaviour rather than pageviews. |
| Spend ingestion | Google Ads API client (official) | Apache-2.0 | Pull cost, clicks and conversions daily into your own store instead of reading a UI. |
| Meta / other platforms | Meta Marketing API SDK | varies (Meta SDK licence) | Same pattern: daily cost rows into the same warehouse, keyed by campaign id and date. |
| Warehouse | PostgreSQL or DuckDB + dbt-core | PostgreSQL / MIT / Apache-2.0 | One table per source, then models that reconcile platform-reported conversions against your own events. |
| Call tracking | Asterisk + FusionPBX (or FreeSWITCH) | GPL-2.0 / MPL-1.1 | Dynamic number insertion with real CDRs; you own the recordings and the numbers. |
| Landing page delivery | Your own static or WordPress stack | GPL-2.0 | Own the page the ad points at, so a test does not wait on a platform's editor. |
| Alerting | Grafana + Loki/Prometheus | AGPL-3.0 / Apache-2.0 | Threshold and anomaly alerts on spend-per-conversion, zero-conversion spend, and landing-page error rates. |
Build it
1. Own the destination before optimising the source
Every ad points at a page you control, with your own analytics tag and your own click identifier in the query string. If the platform is the only system that knows who clicked, you cannot reconcile anything and you cannot leave the platform.
2. Track the identifier end to end
Capture the click id (gclid/fbclid/ttclid) and any campaign parameters on landing, store them with the visit, and carry them through to the conversion record. That one field is what makes offline conversion upload and reconciliation possible.
# landing page query -> first-party cookie, 90 days, same-site=Lax
?utm_source=google&utm_medium=cpc&utm_campaign=brand-exact&gclid=CIj...
-> matomo: pk_campaign, pk_kwd, plus a custom dimension for gclid
3. Pull spend daily into your own table
One job per platform, one table per platform, one row per (date, campaign, ad group, keyword). Store the pulled-at timestamp and the API version. Do not transform at ingest — reconciliation needs the untouched numbers.
4. Reconcile platform conversions to yours
For each campaign and day, compare platform-reported conversions with the conversions your own analytics recorded. A persistent gap is either a tracking defect, a modelled-conversion effect, or a genuine double count. Publishing that gap monthly is more valuable than any optimisation score.
5. Instrument calls properly
Dynamic number insertion per source, call records with duration and disposition, and a rule for what counts as a qualified call. A call with 40 seconds of hold music is not a lead; if your definition is loose, the campaign looks better than it is.
6. Alert on the failures that cost money
Zero-conversion spend above a threshold, conversion rate down more than 40% week over week, landing page returning 5xx, and a tracking gap (sessions without the click id). Those four cover most real losses.
7. Run creative tests on your own pages
Test the landing page and the offer with your own split test (see the CRO guide) rather than trusting the ad platform’s creative rotation to decide. The platform optimises for its own delivery, not for your margin.
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 check | How to verify it |
|---|---|
| Every paid session carries a click id | Share of paid sessions with a non-empty click id; investigate any drop below 95%. |
| Spend rows exist for every active day and platform | Gap query on the date dimension; a missing day is a failed pull, not zero spend. |
| Reconciliation gap is published | Platform conversions vs own conversions per campaign per month, with the delta written down. |
| Calls have duration, source and a qualification rule | Query CDRs joined to the session that produced the number. |
| The four alerts fire in a test | Force each condition in staging and confirm delivery to the on-call channel. |
| Landing pages are monitored for status and LCP | Uptime probe per landing page plus Lighthouse CI on the template. |
Effort and cost
| Estimate | |
|---|---|
| Skill needed | Intermediate to advanced: API credentials, SQL, one scripting language, telephony if you do calls |
| Build time | 2–3 days for analytics + click id, 2 days per platform for spend ingestion, 3–5 days for call tracking |
| Running cost | Roughly 1 hour of maintenance a month plus the VPS; telephony is the only real recurring cost (carrier minutes) |
| What you must host | One 4 GB VPS for analytics + warehouse + Grafana. Telephony needs its own host if you take volume. |
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.
- You cannot self-host the auction. Bid, quality score components and competitor data stay inside the platform; any tool promising this is scraping and will break.
- Platform-reported conversions are modelled and include view-through and cross-device credit. Your own tracking will always show fewer, and both numbers are ‘right’ under different definitions.
- Cookieless browsers and consent walls reduce click-id capture below 100%. Expect a 5–20% loss depending on market and consent mode.
- Attribution across devices without a login is inference, not measurement. Any multi-touch model you build is a model, and should be labelled as one.
- Call tracking requires numbers in the markets you advertise in, which is a regulatory and carrier task, not a software one.
What the service adds
Scope only, stated so you can compare it with the build above.
- Account structure and bidding decisions, which require the margin data and the sales conversation
- The reconciliation read: which gaps are tracking defects and which are platform modelling
- Creative and landing-page testing sequenced against the campaign calendar
Sources and further reading
- Google Ads API — getting started
- Matomo campaign tracking
- Meta Marketing API
- Asterisk documentation
- dbt-core — models and tests
Related guides
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
Build a paid-media measurement layer 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.