Cross-Platform Telemetry Contract
1. Overview
This telemetry contract defines a standardized specification for collecting and transmitting telemetry data from cross-platform applications (Web, iOS, Android, Desktop). It ensures consistency, privacy compliance (GDPR/CCPA), scalability, and reliability.
-
Goals:
- Track user journeys, engagement, and errors.
- Minimize PII exposure.
- Use JSON schemas for validation.
- Support batching and real-time streaming (e.g., via Kafka, Segment, or custom endpoints).
-
Key Principles:
- All events are opt-in (user consent required).
- Use UUIDv4 for anonymized IDs.
- Batch events (max 100 per batch, 1MB payload).
- Retry failed sends (exponential backoff, max 5 attempts).
- Endpoint:
https://telemetry.trailblazerlabs.com/v1/events (POST, auth via API key).
-
Common Fields (required in all events):
{
"event_id": "uuidv4-string",
"event_type": "string (enum: see events section)",
"timestamp": "ISO8601 (UTC)",
"platform": "string (enum: 'web', 'ios', 'android', 'windows', 'macos', 'linux')",
"app_version": "semver-string",
"session_id": "uuidv4-string",
"user_id": "hashed-uuidv4-string (SHA256(user-provided-id + salt))",
"device_id": "hashed-device-uuid-string (platform-specific, hashed)",
"environment": "string (enum: 'prod', 'staging', 'dev')"
}
2. Events
Events are categorized for clarity. Each event extends the common fields.
2.1 User Lifecycle
| Event Type | Description | Triggers |
|---|
user_signup | User creates account | Signup form submit |
user_login | User logs in (any method) | Login success |
user_logout | User logs out | Logout button |
user_profile_update | Profile edited | Save profile |
2.2 Engagement
| Event Type | Description | Triggers |
|---|
app_start | App/session starts | On launch/open |
page_view | Page/screen navigated to | Route change |
button_click | Interactive button pressed | Any CTA click |
search | Search performed | Search submit |
2.3 Performance/Errors
| Event Type | Description | Triggers |
|---|
performance | Page load/performance metrics | On load complete |
error | JS crash or HTTP 5xx | Unhandled error |
api_request | Outgoing API call | Request complete |
2.4 Business
| Event Type | Description | Triggers |
|---|
purchase | Successful purchase | Checkout complete |
subscription | Subscription started/cancelled | Billing event |
3. PII Handling
Strict No-Send Policy: Never transmit raw PII. Always hash or pseudonymize.
| Field | PII Type | Handling Rule | Example |
|---|
user_id | High (direct identifier) | SHA256(user_email + app_salt) → hex | "a1b2c3..." |
email | High | DO NOT SEND. Use hashed user_id. | N/A |
name | Medium | DO NOT SEND. | N/A |
ip_address | Medium | Last octet masked (e.g., 192.168.1.X) | "192.168.1.0" |
device_id | Medium | SHA256(platform_device_id + salt) | "d4e5f6..." |
location | Low | City/region only (no lat/long) | "San Francisco, CA" |
custom_props | Variable | Client-side scan/filter before send | N/A |
- Hashing: Use client-side crypto (Web Crypto API, iOS CommonCrypto, Android MessageDigest). Salt =
TRAILBLAZER_TELEMETRY_SALT (env var).
- Audit: Log PII filters server-side. Alert on raw PII detection.
- Retention: 90 days max for raw events; anonymized aggregates indefinite.
4. Schemas
All events use JSON Schema (draft-07) for validation. Core schema + event-specific extensions.
4.1 Core Schema (telemetry-core.json)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"event_id": { "type": "string", "format": "uuid" },
"event_type": { "type": "string", "enum": ["user_signup", "user_login", /* full list */] },
"timestamp": { "type": "string", "format": "date-time" },
"platform": { "type": "string", "enum": ["web", "ios", "android", "windows", "macos", "linux"] },
"app_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$" },
"session_id": { "type": "string", "format": "uuid" },
"user_id": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
"device_id": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
"environment": { "type": "string", "enum": ["prod", "staging", "dev"] }
},
"required": ["event_id", "event_type", "timestamp", "platform", "app_version", "session_id", "user_id"]
}
4.2 Example Event Schemas
user_signup
{
"allOf": [{ "$ref": "telemetry-core.json" }, {
"properties": {
"method": { "enum": ["email", "google", "apple"] },
"properties": { "type": "object" } // e.g., {"plan": "pro"}
},
"required": ["method"]
}]
}
page_view
{
"allOf": [{ "$ref": "telemetry-core.json" }, {
"properties": {
"page_path": { "type": "string" },
"page_title": { "type": "string" },
"referrer": { "type": "string" }
},
"required": ["page_path"]
}]
}
error
{
"allOf": [{ "$ref": "telemetry-core.json" }, {
"properties": {
"error_type": { "type": "string" },
"error_message": { "type": "string", "maxLength": 1000 },
"stack_trace": { "type": "string", "maxLength": 5000 },
"http_status": { "type": "integer" }
},
"required": ["error_type", "error_message"]
}]
}
Full Schemas Repo: Host at github.com/trailblazerlabs/telemetry-schemas (use ajv or jsonschema for validation).
5. QA (Quality Assurance)
5.1 Validation
- Client-Side: Use schema validators (e.g.,
ajv for Web, JSONSchema for Swift/Kotlin).
- Server-Side: Reject invalid payloads (HTTP 400). Use
great_expectations or Spectral.
- Tools: Postman/Newman for API tests;
json-schema-faker for mocks.
5.2 Testing Scenarios
| Test Case | Description | Expected Outcome |
|---|
| Schema Compliance | Send valid/invalid event | Valid: 200; Invalid: 400 + details |
| PII Detection | Inject raw email | Dropped + alert |
| High Volume | 10k events/sec | No loss >0.1% |
| Cross-Platform | Same event from iOS/Web | Identical core |
| Offline | Queue + retry on reconnect | 100% delivery |
| Privacy | Audit logs for PII | Zero raw PII |
5.3 Monitoring & Alerts
- Metrics: Event volume, drop rate, latency (Prometheus/Grafana).
- Alerts: PII leak (>0), schema errors (>1%), delivery failure (>5%).
- E2E Tests: CI/CD with Playwright/Cypress (simulate events).
- Compliance Audit: Quarterly review with mock PII injection.
5.4 SDK Implementation Checklist
Deployment: Tag v1.0.0. Update via semantic versioning. Questions? Ping #telemetry on Slack.