Firebase / GA4 Measurement Protocol

Send verified subscription events from SubHero to Firebase and GA4 through the Measurement Protocol.

Create an app stream in Firebase/GA4, enable Analytics in the app, and create a Measurement Protocol API secret. Obtain the Firebase app id for that stream. The app must send its actual FirebaseAnalytics.getAppInstanceId() value during verified purchase ingest; a user id cannot substitute for it.

An admin configures PUT /console/projects/{projectId}/integrations/ga4:

json code
{
  "enabled": true,
  "forwardSandbox": false,
  "revenueMode": "gross",
  "credentials": { "firebase_app_id": "YOUR_FIREBASE_APP_ID", "api_secret": "YOUR_MEASUREMENT_PROTOCOL_SECRET" }
}

Purchase, trial conversion, renewal, product change and one-time purchase money events map to purchase; refunds map to refund with a positive refund magnitude. transaction_id is the original store charge id, so distinct renewals do not collapse into one chain transaction and refunds refer to their purchase. Other events use lowercase taxonomy names, except CANCELLATION maps to subscription_cancelled. Trial start carries no value or currency. Each event includes its stable SubHero event id for downstream audit/deduplication.

The Firebase app id and API secret appear in the collection URL as required by Google; that full URL is never persisted or logged. The app instance id appears in the body, with the event's authoritative microsecond timestamp. We send one event per request. Google's current Measurement Protocol limit is 25 events per request and 25 parameters per event.

Revenue becomes a JSON number only when the vendor body is serialized. Upstream money remains exact decimal text/bigint, and no calculations are performed using floating-point revenue. proceeds mode requires a recorded estimate and explicitly skips when absent. Events with no Firebase app instance id are skipped_no_device; sandbox events are skipped until forwarding is explicitly enabled.

Read status through GET /console/projects/{projectId}/integrations/ga4/deliveries. Credentials are encrypted and write-only. Delivery attempts record only safe status/outcome fields, never vendor response bodies or secret-bearing URLs. Failures use 1 minute, 10 minutes, 1 hour and 6 hours of backoff before a dead-delivery alert. GA4 has a separate queue and cannot block the other destinations or store processing.

Measurement Protocol delivery is at least once. The stable charge transaction id supports purchase deduplication; arbitrary custom-event exactly-once processing is not guaranteed by Google. A 2xx response also does not prove that GA4 accepted every parameter. Owner verification should inspect DebugView/Realtime after a staging sandbox purchase/renewal/cancel cycle; credentials and an instrumented test app are required. No automated test fabricates dashboard screenshots.

Sources: sending app-stream events, Measurement Protocol reference, and purchase/refund event contracts.

Disabling pauses pending work and lease recovery. Re-enabling resumes those same deliveries; events created while disabled are not backfilled. Already running requests can finish. Event-time subscriber snapshots are immutable. Deleting the integration deletes its delivery history.

Missing gross prices are skipped_missing_price; missing estimates in proceeds mode are skipped_missing_proceeds. Invalid local payloads (invalid_payload) or unreadable credentials (invalid_config) immediately become dead and raise an alert. Single-event 400/413/422 responses are permanent; 401/403, 429, server errors and network failures use the retry schedule so corrected settings can recover. Logs store only fixed outcome codes and status numbers, never raw exception messages, request URLs or vendor bodies.

Events older than 72 hours or more than five minutes in the future are skipped_outside_vendor_window.