Skip to content

Privacy-First Analytics & Realtime Telemetry

How Shaf tracks click metrics, geographic distribution, and device telemetry without cookies or privacy violations.

Privacy-First Analytics & Realtime Telemetry

Modern privacy regulations — GDPR, CCPA, and PECR — require systems to treat visitor tracking with strict boundaries. Many URL management platforms rely on persistent tracking cookies, canvas fingerprinting, or raw IP address logs.

Shaf implements a zero-PII, privacy-first telemetry architecture: rich click velocity and attribution analytics without storing personal data or tracking visitors across the web.


Architectural Principles: Zero-PII Enforcement

No Persistent Cookies

Shaf short links never set client-side cookies, local storage tokens, or session identifiers on visitor devices. HTTP redirects return with zero Set-Cookie response headers.

No Canvas or Device Fingerprinting

Shaf executes redirects via server-side HTTP 308 headers without injecting intermediate JavaScript tracking pixels, WebGL probes, or font enumeration scripts.

Ephemeral Daily Rotating Salt Hashing

Raw IP addresses are never written to disk or database tables. To compute daily unique visitors, the edge Worker hashes IP + DailyRotatingSalt into a one-way ephemeral digest that resets every 24 hours.

Coarse GeoIP Extraction

Geographic dimensions are extracted ephemerally from Cloudflare edge network headers at the country, region, and metro city level. Exact coordinates (latitude/longitude) are immediately discarded.


Daily Rotating Salt Hashing Pipeline

To measure “unique clicks” without retaining IP addresses, Shaf uses an ephemeral cryptographic hashing algorithm:

flowchart LR
    IP["Visitor IP Address\n(e.g. 198.51.100.42)"] --> HashEngine["SHA-256 One-Way Hash"]
    Salt["Daily Rotating Salt\n(Changed at 00:00 UTC)"] --> HashEngine
    Slug["Link Slug\n('summer-promo')"] --> HashEngine

    HashEngine --> DailyHash["Ephemeral Daily Visitor ID\n(Valid for 24 hours only)"]
    DailyHash --> HyperLogLog["HyperLogLog Unique Counter\n(ClickHouse Columnar Store)"]

    IP -.->|"Discarded Immediately"| Dump[(Never Written to Disk)]

Because the salt rotates every 24 hours, cross-day visitor tracking is cryptographically impossible. Even with full database access, historic visitor activity cannot be reconstructed or de-anonymized.


Double-Write Architecture: Analytics Engine + Asynchronous Queue

To reconcile high-frequency click bursts with transactional relational storage, Shaf employs a double-write pipeline executed completely outside the critical request path via ctx.waitUntil():

sequenceDiagram
    autonumber
    actor V as Visitor
    participant W as Edge Worker
    participant AE as Cloudflare Analytics Engine
    participant Q as Cloudflare Queue (CLICK_QUEUE)
    participant C as Queue Batch Consumer
    participant D1 as D1 Relational DB
    participant D as Realtime Dashboard

    V->>W: GET /summer-promo
    W-->>V: HTTP 308 (Instant Redirect to Destination)

    Note over W,Q: Asynchronous Double-Write via ctx.waitUntil()
    par Ephemeral Telemetry
        W-)AE: writeDataPoint({ blobs: [slug, country, device], doubles: [1] })
    and Durable Transactional Queue
        W-)Q: send({ type: 'link_click', linkId, timestamp })
    end

    Note over Q,D1: Compaction & Batch Ingestion
    Q-)C: Batch Dispatch (up to 100 messages)
    C->>C: Compact in-memory link counter deltas
    C->>D1: Single atomic transaction (UPDATE links / affiliateEnrollments)

    loop Polling Every 10 Seconds
        D->>W: GET /api/v1/analytics/realtime
        W->>AE: Time-series query (Last 60s events)
        AE-->>W: Aggregated metrics
        W-->>D: Batched click events
    end

The Two Parallel Telemetry Paths

Path 1: Cloudflare Analytics Engine

Optimized for instant, zero-latency aggregation:

  • Receives multi-dimensional data points (blobs: slug, country, region, city, device, browser, referer; doubles: coordinates).
  • Powers real-time dashboard visualizations, geographical choropleths, and device breakdowns.
  • Decoupled from relational database connection pools; handles tens of thousands of concurrent clicks per second without load spikes.

Path 2: Durable Click Queue & D1 Compaction

Optimized for transactional consistency and auditability:

  • Emits structured ClickQueueMessage events into CLICK_QUEUE.
  • Consumed in micro-batches by consumeClickBatch (click-consumer.ts), which collapses hundreds of individual click events into a single in-memory delta count.
  • Flushes compacted counters to D1 SQLite storage with single transactional updates, eliminating row-level lock contention.
  • Protected by a Dead-Letter Queue (DLQ) in dlq-worker.ts and automated spillover replay (replay-spillover.ts) for zero-loss recovery during maintenance windows.

Automated Bot & Crawler Filtering

Marketing analytics are frequently polluted by search engine crawlers, social media preview scrapers (TwitterBot, Slackbot, LinkedInBot), and automated uptime monitors.

Shaf filters non-human traffic at the edge before recording analytics:

Traffic Category Detection Method Handling
Human Browsers Valid browser UA + Client Hints Logged to Analytics Engine; Redirected
Social Scrapers User-Agent match (Twitterbot, facebookexternalhit) Served OpenGraph preview tags; Excluded from click metrics
Search Engine Bots Verified bot list (Googlebot, Bingbot) Redirected; Excluded from click metrics
Malicious Scrapers Cloudflare WAF Threat Score > 30 Challenged via Cloudflare Turnstile

Pseudo-Live Realtime Dashboard Replay

The Shaf analytics dashboard displays an active stream of incoming visitor clicks without requiring expensive continuous WebSocket connections:

  1. The client dashboard queries the analytics endpoint every 10 seconds for events recorded since the previous timestamp.
  2. The response returns the latest batch of anonymized clicks.
  3. A client-side queue smooths event delivery, dispatching one event per second to the dashboard map and UI counters.
  4. If the user minimizes the tab or clicks “Pause”, polling halts immediately to conserve battery and bandwidth.

Type to search…

↑↓ navigate↵ selectEsc close