Repository navigation
Count how many people run the template, and see who uses the demo - #112
Merged
Merged
Conversation
Send one unsampled event when an installation first reaches the runtime and one when its first agent run finishes with an answer, through the CopilotKit telemetry ingest. A random installation id is stored locally and both events respect DO_NOT_TRACK and COPILOTKIT_TELEMETRY_DISABLED. Also pass the same metadata to the runtime's own sampled telemetry through properties._copilotkit, so this template's runs can be told apart from other CopilotKit apps.
Load PostHog in the browser only when NEXT_PUBLIC_POSTHOG_KEY is set at build time, with session recording off because visitors type API keys into the app. Set OIUI_DISTRIBUTION=hosted_demo on Render so the demo is not counted as a self-hosted install, and document what is sent and how to turn it off.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
The 9 October launch brought more than a thousand unique cloners and roughly 2,800 stars, and we still cannot say how many people ran the template. The CopilotKit runtime inside it does report usage, but it sends about one event in twenty and nothing in those events says which app sent them, so this template's runs blend into every other CopilotKit app. The best available number was an estimate: runtimes on the pre-release version this template pins, which also includes the hosted demo.
The hosted demo was not measured at all. Nothing in the app loads analytics, so every visit to opengenerativeui.copilotkit.ai went unrecorded, and the launch dashboard has carried a "not tracked" row for it since day one.
The approach
Two events, once per installation. The frontend server sends
oss.runtime.setup_step_viewed(stepready) the first time the UI reaches the runtime, andoss.runtime.setup_activatedwhen the first agent run finishes with an assistant answer and no run error. Both go to the CopilotKit telemetry ingest unsampled. They sit under theoss.runtime.*namespace the ingest already accepts, so no sink change is needed and they reach PostHog alongside the existing runtime events. A random installation id is stored inapps/app/.open-intelligent-ui/telemetry.json(git-ignored), so counting distinct installation ids answers "how many people ran it", and the second event answers "how many got an answer".Activation reads the response, not the request. Counting sent prompts would also count people whose keys are missing or whose agent is down. For the first agent run only, the route tees the response stream and reads event types (
TEXT_MESSAGE_CONTENT,RUN_ERROR,RUN_FINISHED); no message text is kept. Once an installation has activated, the route stops inspecting requests. The cost is real and worth naming: the first run per installation parses its request body a second time and streams through a tee.The runtime's own telemetry is tagged too. The pinned runtime (
1.55.2-next.1) has notelemetryPropertiesoption, but its Next.js endpoint copiesproperties._copilotkitinto its telemetry properties. Passing the template name, distribution, version and installation id there tags the sampled runtime events without upgrading CopilotKit.Opt-out and failure behave like the runtime.
DO_NOT_TRACK,COPILOTKIT_TELEMETRY_DISABLEDor a sample rate of0send nothing and delete the stored id. Delivery runs after the response throughafter(), times out at 1.5 seconds, never throws into a request, and is retried on a later request if it fails. The telemetry object is created on first use, so builds never touch the filesystem. The template now reports usage by default;docs/telemetry.mdlists every field and is linked from the README.Hosted-demo page analytics only where we host it.
posthog-jsloads only whenNEXT_PUBLIC_POSTHOG_KEYis set at build time, so clones do not load it. Session recording is off because visitors type provider API keys into this app.render.yamlsetsOIUI_DISTRIBUTION=hosted_demo, which keeps the demo's own runs out of the self-hosted count, and declares the PostHog key as a Render secret.What is not covered
hosted_demoand are excluded from install counts.NEXT_PUBLIC_POSTHOG_KEYis set on the Render frontend service and the service is rebuilt.apptag.Verification
pnpm test: app 164 passed (140 onmainplus 24 new), design system 15, MCP 4.pnpm lint: no errors; the one warning (no-page-custom-font) is already onmain.pnpm build: passes, and creates no telemetry state.src/lib/__tests__/launch-telemetry.test.tsholds down once-per-installation delivery, concurrent calls, persistence across restarts, retry after failure, every opt-out (including deleting stored state),CPK_TELEMETRY_IDas identity, the closed metadata keys, an unwritable state path, and the stream reader across split chunks, text chunks, run errors and runs with no answer.src/app/__tests__/posthog-analytics.test.tsxholds down that nothing loads without a key, that a key starts PostHog with session recording off and theapptag, and that it never starts twice.development, which is excluded from counts. WithCOPILOTKIT_TELEMETRY_SAMPLE_RATE=1, taggedinstance_created,copilot_request_createdandagent_execution_stream_started/endedevents arrived too. A build with the PostHog key delivered an autocapture event taggedapp=open-intelligent-ui. The live run caught a bug the unit tests missed: the runtime streams text chunks rather than bytes, which the first version of the stream reader rejected; a test now covers it.