Skip to main content

stapel-analytics

The backend half of the Stapel analytics standard. Your frontend already declares its events and fires them through @stapel/analytics — typed track(), a consent gate, an offline queue, provider fan-out. This is what it talks to, and what the rest of your fleet talks to.

browser (@stapel/analytics)                 server modules
   │ track / page / identify                    │ analytics.track
   ▼                                            ▼
POST /analytics/api/v1/events  ──►  registry check + PII guard
                                            │
   your comm Actions ──► COMM_BRIDGE ────────┤
   (payment.completed, …)                    │
                                             ▼
                                  stapel_core.eventstore  ("analytics" stream)
                                             │
                    ┌────────────────────────┼────────────────────┐
                    ▼                        ▼                    ▼
              funnels / reports      analytics.events.recorded   erasure
              (conversion by step)   ──► adapter fan-out         (GDPR Art. 17)

Part of the Stapel framework.

Install

pip install stapel-analytics
INSTALLED_APPS = [
    ...,
    "stapel_core.django.eventstore",   # the event rows live here
    "stapel_analytics",
]

path("analytics/", include("stapel_analytics.urls"))   # -> /analytics/api/v1/...

That is the whole install. Point your frontend's collector at it and events start landing — the shipped stapelCollectorProvider needs no changes.

Declare your events once

The registry is the same analytics/events.json your frontend's gen:events already produces:

STAPEL_ANALYTICS = {"EVENTS_FILE": BASE_DIR / "analytics" / "events.json"}

One vocabulary, two runtimes. An event nobody declared is still stored — and marked unregistered, so you find the typo instead of losing the data.

Ask where people stop

STAPEL_ANALYTICS = {
    "FUNNELS": {
        "checkout": {
            "title": "Checkout",
            "steps": ["flow.checkout.started", "checkout.address",
                      "payment_completed"],
            "window_seconds": 86400,
        }
    }
}
GET /analytics/api/v1/funnels/checkout/report?compare=true
{"entered": 1204, "completed": 331, "conversion": 0.274917,
 "steps": [
   {"name": "flow.checkout.started", "count": 1204, "rate_from_first": 1.0},
   {"name": "checkout.address",      "count": 502,  "rate_from_previous": 0.416944,
    "dropoff": 702, "delta": -48},
   {"name": "payment_completed",     "count": 331,  "rate_from_previous": 0.659363,
    "dropoff": 171, "delta": 12}
 ]}

Notice the last step: payment_completed happens on a server. One line of settings makes it a step of the same funnel as the clicks before it:

STAPEL_ANALYTICS = {"COMM_BRIDGE": {"payment.completed": "payment_completed"}}

The user id is hashed exactly the way the browser hashes it, so the server step and the clicks belong to the same person.

Mirror the stream anywhere

STAPEL_ANALYTICS = {
    "ADAPTERS": {
        "webhook": {"enabled": True, "config": {"url": "https://collect…"}},
        "posthog": {"handler": "app.analytics.posthog", "enabled": True},
    }
}

Delivery rides the comm outbox, never the ingest request thread. A vendor's outage costs you nothing: the event store is the record and manage.py analytics_fanout --since … replays the mirror.

Close the loop back to the ad platform

Measuring the click is half of it. The deal it led to closes on the phone a week later, and until that outcome goes back to Google Ads the bidding is optimizing for form submissions instead of for revenue.

pip install "stapel-analytics[google-ads]"
call("analytics.upload_click_conversion", {
    "click_id": "Cj0KCQ…",             # gclid | gbraid | wbraid
    "conversion_action": "customers/1234567890/conversionActions/42",
    "conversion_at": "2026-09-04T11:02:00Z",
    "clicked_at": "2026-08-30T09:14:00Z",    # optional, and load-bearing
    "value": 4900, "currency": "EUR",
})
# -> {"status": "uploaded"}

Durable before it is delivered, and idempotent on (click_id, conversion_action, conversion_at) — the same conversion reported twice is one row and at most one upload. An upload that could not be attempted comes back pending, not rejected: the row waits and manage.py analytics_upload_conversions retries it on a capped backoff. --dry-run lists what would go out and writes nothing at all.

The upload goes through the Google Ads API, whose offline-import path is being migrated to the Data Manager API (support.google.com/google-ads/answer/14274408). The scheduled file import below is a Data manager source and is not affected.

clicked_at is optional because most callers do not have it, and load-bearing because Google's 90-day window is measured from the click. With it, that rule is enforced locally. Without it the module falls back to the conversion's own age — a strictly weaker test, and it says so instead of advertising a guarantee the input cannot support.

…or let the platform read the outbox itself

The upload above needs an OAuth client, a refresh token and a developer token that is granted per account and can be refused. When yours cannot get one, the same outbox is servable as a file the platform's data manager fetches on its own schedule — a URL, a token, no credentials of ours:

curl -u "google:$CONVERSION_FEED_TOKEN" \
     https://example.com/analytics/api/v1/conversions/google-ads.csv
Google Click ID,GBRAID,WBRAID,Conversion Name,Conversion Time,Conversion Value,Conversion Currency,Order ID,Ad User Data,Ad Personalization

In Google Ads Data Manager (HTTPS → Conversions → offline import):

  1. URL — https://example.com/analytics/api/v1/conversions/google-ads.csv
  2. Username — anything (ignored unless CONVERSION_FEED_USERNAME pins it)
  3. Password — the CONVERSION_FEED_TOKEN

Do not put the token in the URL when the fetcher can send a password. Authorization: Bearer and ?token= remain for fetchers that cannot.

Each conversion action gets its own Conversion Name through CONVERSION_FEED_CONVERSION_NAMES = {"customers/…/conversionActions/42": "Purchase (offline import)", …}, and the feed fails closed: a row whose action is not in the map is not served (an ERROR on every fetch), two actions with one display name serve nothing, and CONVERSION_FEED_CONVERSION_NAME names only rows without an action. Order ID, Ad User Data and Ad Personalization (Granted / Denied) come from enqueue(..., order_id=, ad_user_data=, ad_personalization=).

It ships off — an empty CONVERSION_FEED_TOKEN is a 404, because the file carries click identifiers and payment values. Serving it never consumes a row (a re-read answers the same file; the platform deduplicates) and it writes down that it was read, so manage.py analytics_conversion_feed_status can answer the one question a pull cannot: has the first load actually landed.

Privacy is the default, not a setting you remember

  • prop values that look like an email or a phone number are refused, and the receipt names the offending prop;
  • user ids are stored as a hash, never raw;
  • the erasure provider ships in this same first release — analytics rows are personal data, including the anonymous session someone had before they logged in:
STAPEL_GDPR = {"DATA_OWNERS": [..., "analytics"]}
  • and there is a retention horizon out of the box (400 days), with a system check if you turn it off.

Documentation

  • MODULE.md — the integration contract: wire format, settings, checks, comm surface, erasure policy.
  • CONFIG.MD — every setting, and the four decisions a host actually has to make.
  • CHANGELOG.md — what changed, and what breaks.

License

MIT

Metadata

Release files for stapel-analytics 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stapel-analytics 0.8.0
File Size Uploaded Provenance Actions
stapel_analytics-0.8.0.tar.gz 217.0 kB With provenance Details for stapel_analytics-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stapel-analytics 0.8.0
File Interpreter ABI Platform Actions
stapel_analytics-0.8.0-py3-none-any.whl Python 3 none any Details for stapel_analytics-0.8.0-py3-none-any.whl

Total release size: 395.8 kB

Release files / stapel_analytics-0.8.0.tar.gz

Download URL stapel_analytics-0.8.0.tar.gz
Size 217.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f54bdd9a6b0614b291d3bb36fce18f3239eb3f750927d23b763b24d4d57b691e
BLAKE2b-256 checksum
How to use checksums
10fa9f1db9b7c155c23d21d8efba776ae41cd2ab3e0bffeab98aa9ff5debc228
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / stapel_analytics-0.8.0-py3-none-any.whl

Download URL stapel_analytics-0.8.0-py3-none-any.whl
Size 178.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2fa3ebd953a9f885cb934fb2ae9d7cff20e2833beab1bdf822ad03ce03b1e469
BLAKE2b-256 checksum
How to use checksums
830014dc18f22d984040e0a8974d6d057bcbbe1cd42bf500426a163f0314b20a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for stapel-analytics 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for stapel_analytics-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page