# Integration and operations ## Existing PostHog projects Copy `traction.config.example.json` to the ignored `traction.config.json`. Twyne and Keating can be observed using their existing instrumentation. The server needs a PostHog personal API key with query access to the configured projects, injected as `POSTHOG_READ_KEY`. Do not place this key in a browser bundle or paste it into telemetry events. Project IDs and public ingestion tokens do not grant read access. Following the [PostHog query API](https://posthog.com/docs/api/queries), the service requests `force_blocking` aggregate queries for the previous 28 complete UTC days. Surface resolution uses `$surface`, then the existing `app_surface`, then `unknown`. It reports event counts and approximate distinct `person_id` counts per surface; it does not add distinct users across surfaces. A successful empty result establishes zero recorded events, not working client instrumentation. Counts alone cannot establish adoption, retention, or cause. The current query was executed read-only against both connected PostHog projects on 2026-09-05. Both responses passed through the production parser and triage. Keating returned web and unknown surfaces; Twyne returned unknown surfaces. This verifies query compatibility with current data. The connector session's credentials were not extracted, and this local service has not yet been provisioned with its own read key. For more meaningful counts, add an `events` list to a source, for example `["document_exported"]` using names that actually exist in that application. Invalid/incomplete provider responses fail coverage. Zero-filled days are only created for successful complete PostHog aggregates. Cached query errors cannot become an all-clear. Add a surface label at the existing application's typed capture boundary when useful. Traction does not change application code or consent automatically. The SDK is optional when a working capture client already exists. ## PostHog layers, signals and freshness Each PostHog source runs three aggregate HogQL queries per poll: the surface breakdown above, one daily query for built-in layers and configured signals, and a 7-day freshness check. Built-in layers are pageviews, pageview visitors, sessions (`$session_id`), `$exception` counts (operational), `$ai_generation` counts and `$ai_total_cost_usd` (AI usage). A built-in layer is omitted when its event never occurred in the window; configured signals always appear, including recorded zeros. Set `"builtins": false` on a source to keep only the surface query. Signals name one event each: `{"id":"messages","label":"Messages sent","event":"message_sent","measure":"events"|"users","kind":"product"|"operational"}` (at most 24 per source). Product signals counted in events, users or sessions use the statistical thresholds; operational and AI usage layers are context only. Every layer links to the matching PostHog trend. Freshness reports the last event time and counts for the last 24 hours and 7 days. If a project recorded at least 140 events in the previous week and none in the last 24 hours, the briefing gets a degraded `collection` finding and no all-clear. That pattern usually means broken capture, but counts cannot prove it. ## Managing signals from the dashboard The authenticated dashboard edits projects, sources and signals through `PUT /api/config` (see [SIGNALS-API.md](SIGNALS-API.md)). The first boot seeds projects from the configuration file or `TRACTION_CONFIG_JSON`; after the first save, the SQLite copy wins until it is edited again. Server-owned settings (`notorganic`, `notifications`, poll intervals) always come from the file or environment. Dashboard edits may only use PostHog hosts that are built in or already configured, and credential names matching `POSTHOG_*` or `GITHUB_*`, so an edit cannot send another server secret to a different origin. Discovery endpoints list PostHog projects and the 50 most frequent events in the last 28 days (cached for 10 minutes). Once a dashboard save exists, later edits to the file's or `TRACTION_CONFIG_JSON`'s `projects` are ignored (`GET /api/config` reports `origin: "database"`); edit in the dashboard instead. Changing a source's configuration (project, host, events or signals) discards that source's earlier evidence rather than presenting it as history. Each PostHog credential is used only for PostHog sources and each GitHub credential only for GitHub sources. Jev receives a compact summary (14 recent days per metric plus totals). Around ten projects with many signals can exceed the 90 KB review bound, in which case interpretation fails closed and the statistical briefing is unchanged. ## Configuration ```json { "pollIntervalMinutes": 60, "staleAfterMinutes": 180, "projects": [{ "id": "example", "name": "Example", "sources": [ {"type": "posthog", "host": "https://us.posthog.com", "projectId": 123, "apiKeyEnv": "POSTHOG_READ_KEY"}, {"type": "github", "repository": "owner/repository", "apiKeyEnv": "GITHUB_READ_KEY"}, {"type": "npm", "package": "package-name"} ] }], "notifications": {"host": "https://ntfy.example.com", "topicEnv": "NTFY_TOPIC", "tokenEnv": "NTFY_TOKEN"} } ``` This is an illustrative configuration; substitute real owned resources. Omit unused sources and `notifications`. [GitHub traffic](https://docs.github.com/en/rest/metrics/traffic) requires repository access with the permission to read traffic (administration read for fine-grained tokens); it supplies a shorter history than PostHog. npm download totals are activity proxies and require no token. These two provider protocols are fixture-tested; live account-specific permission checks remain deployment work. Remote origins must use HTTPS and cannot contain credentials, paths, queries, or fragments. Plain HTTP loopback sources are only permitted with `TRACTION_ALLOW_HTTP_LOCALHOST=1` for local fixtures. The service accepts at most 30 projects and one source per type per project. Source requests have a 15-second deadline and a 2 MB response limit; at most three sources run together. Shutdown aborts active requests and does not launch subsequent batches. The statistical rule needs at least eight consecutive complete days. It uses up to 28 baseline points and matching weekdays when at least three are available. A candidate must exceed 20 absolute counts, 50 percent relative change, and three times the larger of the standard deviation, square root of the baseline mean, and one. Large significant declines of at least 75 percent from a baseline of at least 50 are urgent. Evidence records the calculation; the rule does not determine whether a change is a bug, bot, mirror, campaign, or instrumentation gap. ## Private hosting Set server environment variables using the deployment's secret store: - `TRACTION_BIND=0.0.0.0` - `TRACTION_PUBLIC_ORIGIN=https://your-traction-host.example` - `TRACTION_DASHBOARD_TOKEN`: a random value with at least 32 characters - `TRACTION_DB=/data/traction.sqlite` on a persistent volume - Source credential variables named in the configuration - `TRACTION_CONFIG`: absolute path to the configuration if not in the working directory, or `TRACTION_CONFIG_JSON` with the same JSON when no file is mounted (used by the Railway deployment) The login posts the access key to the same origin and creates a 12-hour HttpOnly, Secure, SameSite=Strict session. API clients can supply `Authorization: Bearer ...`; browser mutations also require a matching Origin. The landing page and process/storage health endpoint are public; project data is authenticated. Use one trusted operator per service; shared-key access is not tenant isolation. Reverse proxies must preserve the configured public origin and HTTPS. Use one replica and local persistent SQLite storage, not a shared network filesystem. The database holds aggregate source snapshots, the latest briefing for each of 90 UTC days, and notification reservations. The API exposes the latest 30 briefings. It does not retain every intraday revision. Protect and back up the volume; losing it also loses the day's notification reservation. The 30-minute poll lease prevents overlapping instances using the same database; it is not a distributed deployment architecture. `/health` establishes that the process can read SQLite. It intentionally stays healthy when a provider is down. Monitor that endpoint externally, and inspect authenticated source freshness separately. A stopped service cannot deliver a notification explaining that it has stopped. ## Notification budget Notifications are optional. The service reserves a single attempt for the actual UTC delivery date before sending to ntfy. Severity determines priority; urgent evidence retains urgent priority even with incomplete coverage. The same one-attempt limit applies to all severities, so a later urgent change after today's attempt appears on the dashboard but does not generate a second push. The first successful scheduled poll of the day supplies that day's message; there is no configurable local-time delivery schedule yet. A network failure can occur after delivery, so the service records uncertainty and does not retry that day. `pending` after a crash is also uncertain. ntfy topics and tokens remain server-held. Real push delivery has not been performed as part of this change. ## SDK adoption and verification See [the SDK guide](../packages/sdk/README.md) and [telemetry inventory](TELEMETRY.md). Build and install both local archives using `bun run pack:local`. The archive includes compiled JavaScript/declarations and pins the companion spec package version. No package was published. Automated integration tests connect browser/Node capture, offline Node restart, an actual local HTTP batch receiver, provider-shaped aggregates, production parsing/triage, SQLite, and authenticated API access. Browser and plain Node imports are checked separately. This is controlled integration evidence, not proof of cloud PostHog ingestion, an application's rendered consent UI, mobile support, or deployed notification delivery. The 16-case benchmark is synthetic and must not be reported as measured production accuracy. No external actions, application migrations, or deployment are performed by these tests. ## Install local archives Run `bun run pack:local` in Traction. Copy both `dist/packages/*.tgz` archives into the consuming application's `vendor` directory. Merge these entries into its existing `package.json`, preserving its other dependencies and overrides: ```json { "dependencies": { "@traction/spec": "file:./vendor/traction-spec-0.1.0.tgz", "@traction/sdk": "file:./vendor/traction-sdk-0.1.0.tgz" }, "overrides": { "@traction/spec": "file:./vendor/traction-spec-0.1.0.tgz" } } ``` Then run `bun install`. Keep the archives and updated lockfile with the consuming application's intended dependency changes. The override keeps the SDK's companion dependency on the local archive; Bun 1.3.13 otherwise tries the unpublished npm version even when both archives are explicitly added. Relative paths make the same artifacts available in CI and deployment. This setup passed installation in a fresh directory, plain Node 24 execution, and a frozen-lockfile install after removing that consumer's `node_modules`. The lockfile contains relative archive paths. A separate real Chromium check of the installed archive exercised visible notice acknowledgment, opt-in refusal, a permitted enum event, a sink acknowledgment, and opt-out refusal with no Node globals. The integrating application's own build, consent UI, and provider delivery still need verification. In an npm-managed application, installing both archive paths together with `npm install /path/to/traction-spec-0.1.0.tgz /path/to/traction-sdk-0.1.0.tgz` also resolves the dependency. Do not introduce another package manager's lockfile into an existing Bun application.