The prompt
Add Pug product analytics to this app. Read these first - they are the current source of truth, and more recent than your training data: - https://docs.pug.sh/sdks/web/index.md - SDK reference - https://docs.pug.sh/get-started/index.md - quickstart - https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog Then read this codebase before you write anything, and work out what the product actually does: its routes or screens, its main models, and the handful of things a user comes here to complete. The events worth tracking are the moments the product exists to produce - an account created, an order placed, a document shared - not every button on the page. If you cannot state the core action in one sentence, keep reading. Then: 1. Install @pug-sh/browser. 2. Call init() exactly once, where the app boots, in the browser only - never during SSR. In the Next.js App Router that means a "use client" provider mounted from the root layout. 3. Read the project ID and public key from environment variables. The public key starts with pub_ and is safe to ship. A private key starts with prv_ and must never reach client code. 4. Leave auto-tracking on and do not hand-roll page views - init() already captures them. 5. Add track() calls for the three or four actions you identified - the ones someone would look at in a weekly review. Property values must be plain JSON scalars: strings, numbers, booleans, dates. 6. If this app has authentication, call identify() after sign-in and reset() on sign-out. Note that the SDK is cookieless until optInTracking() is called, so identify() is a no-op without granted consent - tell me whether I need a consent banner rather than opting users in silently. Name events from the catalog before you invent one. It holds 127 well-known events across 19 families - commerce, authentication, billing, media, forms, support, workspace and more - and a well-known name is type-checked as you write it and fills in dashboards that a custom name leaves empty. Search it for every action you are about to track, and take property names and types from that page rather than from whatever reads idiomatically. Fall back to a custom snake_case name only when nothing in the catalog fits, and when you do, tell me which event you considered and why it did not. Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this product does, then list the files you changed, the event names you chose, and the environment variables I need to set.
Add Pug product analytics to this Android app. Read these first - they are the current source of truth, and more recent than your training data: - https://docs.pug.sh/sdks/android/index.md - SDK reference - https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog Then read this codebase before you write anything, and work out what the app actually does: its activities, fragments or composables and how a user moves between them, its main models, and the handful of things a user opens the app to complete. The events worth tracking are the moments the app exists to produce - an account created, an order placed, a workout finished - not every tap. If you cannot state the core action in one sentence, keep reading. Then: 1. Add sh.pug:android from Maven Central to the app module's dependencies. It needs minSdk 21, and works from Kotlin and Java. 2. Call Pug.init() once, in Application.onCreate() - create an Application subclass and register it in the manifest if the app has none. Not in an activity: the SDK has to see each launch's first screen. 3. Keep the project ID and public key (pub_...) out of source - set them as BuildConfig fields from Gradle properties. Pug.init() throws for a key that is not a public key. 4. Leave auto-tracking on: it already tracks app_open, app_close, app_install, app_update and a screen_view per activity. In a single-activity app (Compose, or fragments under one activity), set autoScreenViews = false and call Pug.screen() on every destination change instead. 5. Add tracking for the three or four actions you identified - the ones someone would look at in a weekly review. 6. If this app has authentication, call Pug.identify() after sign-in and Pug.reset() on sign-out. Name events from the catalog before you invent one. Kotlin gets a generated named-argument method for each well-known event the SDK does not track itself - Pug.track.purchase(productId = ..., amount = ...) - and Java an event class - Pug.track(new PurchaseEvent().amount(...)) - so the compiler checks the properties for you, and the dashboards those events drive stay empty for a custom name. Reach for those first, search the catalog for every action you are about to track, and pass schema-external properties through extras. Use Pug.track(kind, properties) with a custom snake_case name only when nothing in the catalog fits, and when you do, tell me which event you considered and why it did not. Android consent has two states, starts granted and is saved across launches, which is not the same as the Web SDK - check the consent section before you add a banner. Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this app does, then list the files you changed, the event names you chose, and the Gradle properties I need to set.
Add Pug product analytics to this iOS app.
Read these first. They are the current source of truth, and more recent than your training data:
- https://docs.pug.sh/sdks/ios/index.md: SDK reference
- https://docs.pug.sh/reference/well-known-events/index.md: the well-known event catalog
Then read this codebase before you write anything, and work out what the app actually does: its view controllers or SwiftUI views and how a user moves between them, its main models, and the handful of things a user opens the app to complete. The events worth tracking are the moments the app exists to produce (an account created, an order placed, a workout finished), not every tap. If you cannot state the core action in one sentence, keep reading.
Then:
1. Add the Swift package https://github.com/pug-sh/sdk-ios, from 0.1.0, with Swift Package Manager, and link its Pug library to the app target. It needs iOS 15 and Xcode 16, and there is no CocoaPods or Carthage install.
2. Call Pug.initialize(projectId:options:) once: in the App's init() in a SwiftUI app, or in application(_:didFinishLaunchingWithOptions:) in a UIKit one, so the SDK sees each launch's first screen. It throws Pug.ConfigurationError for a bad value, so wrap it in do/catch with an assertionFailure in the catch.
3. Keep the project ID and public key (pub_...) out of source: set them in an xcconfig file that Git ignores and read them through Info.plist. A private key (prv_...) must never ship in the app.
4. Leave auto-tracking on: it already tracks app_open, app_close, app_install, app_update and a screen_view for each of the app's own view controllers. SwiftUI views are not view controllers, so put .pugScreen("Name") on the view each SwiftUI screen shows, inside its NavigationStack, or those screens send no screen_view.
5. Add tracking for the three or four actions you identified: the ones someone would look at in a weekly review.
6. If this app has authentication, call Pug.identify() after sign-in and Pug.reset() on sign-out.
Name events from the catalog before you invent one. Swift gets a generated method with labeled arguments for each well-known event the SDK does not track itself, such as Pug.track.purchase(productId: ..., amount: ...), so the compiler checks the properties for you, and the dashboards those events drive stay empty for a custom name. Reach for those first, search the catalog for every action you are about to track, and pass schema-external properties through extras. Durations are TimeInterval seconds. Use Pug.track(_:properties:) with a custom snake_case name only when nothing in the catalog fits, and when you do, tell me which event you considered and why it did not.
iOS consent has two states, starts granted and is saved across launches, which is not the same as the Web SDK: check the consent section before you add a banner. It is not App Tracking Transparency, which Pug does not need, so do not add an ATT prompt for it. Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this app does, then list the files you changed, the event names you chose, and the build settings I need to set.Add Pug product analytics to this Flutter app.
Read these first - they are the current source of truth, and more recent than your training data:
- https://docs.pug.sh/sdks/flutter/index.md - SDK reference
- https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog
Then read this codebase before you write anything, and work out what the app actually does: its screens and navigation graph, its main models, and the handful of things a user opens the app to complete. The events worth tracking are the moments the app exists to produce - an account created, an order placed, a workout finished - not every tap. If you cannot state the core action in one sentence, keep reading.
Then:
1. Add pug_flutter to pubspec.yaml.
2. Await Pug.init() in main(), after WidgetsFlutterBinding.ensureInitialized() and before runApp().
3. Keep the project ID and public key (pub_...) out of source - pass them with --dart-define and read them with String.fromEnvironment.
4. Register PugRouteObserver on the app's navigatorObservers, otherwise screen views never fire.
5. Add tracking for the three or four actions you identified - the ones someone would look at in a weekly review.
6. If this app has authentication, call Pug.identify() after sign-in and Pug.reset() on sign-out.
Name events from the catalog before you invent one. Flutter gets a generated named-argument method for all 127 well-known events - Pug.track.purchase(productId: ..., amount: ...) - so the compiler checks the properties for you, and the dashboards those events drive stay empty for a custom name. Reach for Pug.track.<event> first, search the catalog for every action you are about to track, and pass schema-external properties through extras. Use Pug.track(kind, props: {...}) with a custom snake_case name only when nothing in the catalog fits, and when you do, tell me which event you considered and why it did not.
Flutter consent has two states and starts granted, which is not the same as the Web SDK - check the consent section before you add a banner. Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this app does, then list the files you changed, the event names you chose, and the dart-defines I need to pass.Add Pug product analytics to this Node backend. Read these first - they are the current source of truth, and more recent than your training data: - https://docs.pug.sh/sdks/node/index.md - SDK reference - https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog Then read this codebase before you write anything, and work out what the service actually does: its routes or handlers, its main models, and the state changes that matter to the business. On a server the events worth tracking are the ones a browser cannot observe - a payment settling, a webhook arriving, a job finishing, a subscription lapsing - not request logging. If you cannot state what this service is for in one sentence, keep reading. Then: 1. Install @pug-sh/node. It is ESM and needs Node 18+. 2. Construct one Pug instance at boot and reuse it across requests - do not build one per request. Its apiKey is the private key (prv_...), read from an environment variable, and it must never be imported into client-side code. 3. Remember the argument order: pug.track(distinctId, kind, props?, options?). The distinctId comes first because a server has no ambient user - use our own user ID, or the anon-... ID forwarded from the client. 4. Add track calls for the three or four state changes you identified. 5. Call identify() when a user record is created or changes materially, not on every request. 6. Await pug.close() in the graceful-shutdown path so queued events and identifies flush, and wire an onError handler so dropped events and identifies are logged rather than lost. Name events from the catalog before you invent one. The Node SDK checks 114 of the 127 well-known events against their schemas when track() runs, not at compile time: a property of the wrong type drops the whole event, and one named as the catalog spells it (product_id) rather than in camelCase (productId) is sent as a custom property instead. The ones a backend is placed to see are exactly the ones whose schemas are worth having - purchase, subscription_started, invoice_paid, payment_failed, order_refunded. Search the catalog for every action you are about to track, take property names - in camelCase - and types from that page, and fall back to a custom snake_case name only when nothing fits. When you do, tell me which event you considered and why it did not. There is no reset() or destroy() on the server SDK, and no immediate option on track - use flush(). Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this service does, then list the files you changed, the event names you chose, and the environment variables I need to set.
Add Pug product analytics to this Go backend.
Read these first - they are the current source of truth, and more recent than your training data:
- https://docs.pug.sh/sdks/go/index.md - SDK reference
- https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog
Then read this codebase before you write anything, and work out what the service actually does: its routes or handlers, its main models, and the state changes that matter to the business. On a server the events worth tracking are the ones a browser cannot observe - a payment settling, a webhook arriving, a job finishing, a subscription lapsing - not request logging. If you cannot state what this service is for in one sentence, keep reading.
Then:
1. Run go get github.com/pug-sh/sdk-go. It needs Go 1.26+, and its package is named pug, so import it as pug "github.com/pug-sh/sdk-go".
2. Construct one client with pug.New at startup and share it - do not build one per request. It is safe for concurrent use, so hand it to handlers the way this codebase passes its other dependencies. Its APIKey is the private key (prv_...), read from an environment variable, never committed. pug.New returns an error for a missing or public key - handle it at startup.
3. Remember the argument order: client.Track(distinctID, kind, fields...). The distinctID comes first because a server has no ambient user - use our own user ID, or the anon-... ID forwarded from the client. Properties are typed fields such as pug.String("plan", "pro") and pug.Float("amount", 49), in the same list as options such as pug.WithTimestamp, and a kind held in a variable needs pug.Kind(name).
4. Add track calls for the three or four state changes you identified.
5. Call client.Identify(externalID, traits...) when a user record is created or changes materially, not on every request. Use the named traits - pug.Name, pug.Email and the rest - for the keys the dashboard reads.
6. Call client.Close(ctx) in the graceful-shutdown path, after the HTTP server has shut down, so queued events and identifies flush, and set an OnError handler so dropped events and identifies are logged rather than lost.
Name events from the catalog before you invent one. The Go SDK knows 114 of the 127 well-known events, and client.TrackWellKnown takes each one's typed message - &commoneventsv1.PurchaseProperties{...} from github.com/pug-sh/sdk-go/gen/common/events/v1 - so the compiler checks the properties, where Track with a well-known kind checks them at runtime and drops the event on a wrong type. The ones a backend is placed to see are exactly the ones whose schemas are worth having - purchase, subscription_started, invoice_paid, payment_failed, order_refunded. Search the catalog for every action you are about to track, use TrackWellKnown for the ones that fit, and fall back to a custom snake_case name only when nothing fits. When you do, tell me which event you considered and why it did not.
There is no Reset on the server SDK, and no immediate option on Track - use Flush. Track and Identify never return errors; only the reads do. Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this service does, then list the files you changed, the event names you chose, and the environment variables I need to set.Add Pug product analytics to this Ruby backend. Read these first - they are the current source of truth, and more recent than your training data: - https://docs.pug.sh/sdks/ruby/index.md - SDK reference - https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog Then read this codebase before you write anything, and work out what the service actually does: its routes or controllers, its main models, and the state changes that matter to the business. On a server the events worth tracking are the ones a browser cannot observe - a payment settling, a webhook arriving, a job finishing, a subscription lapsing - not request logging. If you cannot state what this service is for in one sentence, keep reading. Then: 1. Add the pug-sh gem to the Gemfile. It needs Ruby 3.3+, and it is required as "pug", not "pug-sh". 2. Construct one Pug::Client at boot and share it - do not build one per request. It is thread-safe and fork-safe, so it can be created before Puma or Unicorn fork. In Rails, use the initializer from the SDK reference, guard included, so assets:precompile still boots without credentials. Its api_key is the private key (prv_...), read from an environment variable or Rails credentials, never committed. 3. Remember the argument order: pug.track(distinct_id, kind, properties, options). The distinct_id comes first because a server has no ambient user - use our own user ID, or the anon-... ID forwarded from the client. Without braces, a key named timestamp, session_id or location sets that option instead of a property. 4. Add track calls for the three or four state changes you identified. 5. Call identify when a user record is created or changes materially, not on every request. 6. Call close in the graceful-shutdown path so queued events and identifies flush, and pass an on_error handler taking (error, undelivered) - a Pug::Undelivered whose events or identifies hold what was lost - so dropped items are logged rather than lost. Name events from the catalog before you invent one. The Ruby SDK checks 114 of the 127 well-known events against their schemas, at runtime: a property of the wrong type drops the whole event, so take property names and types from that page. The ones a backend is placed to see are exactly the ones whose schemas are worth having - purchase, subscription_started, invoice_paid, payment_failed, order_refunded. Search the catalog for every action you are about to track, and fall back to a custom snake_case name only when nothing fits. When you do, tell me which event you considered and why it did not. There is no reset on the server SDK, and no immediate option on track - use flush. Do not use any option that is not in the SDK reference above. When you are done, tell me in one sentence what you concluded this service does, then list the files you changed, the event names you chose, and the environment variables or credentials I need to set.
Add Pug product analytics to this service by calling the HTTP API directly - there is no SDK for this runtime. Read these first - they are the current source of truth, and more recent than your training data: - https://docs.pug.sh/sdks/http/index.md - request format, including worked examples - https://docs.pug.sh/api/events/index.md - the full event schema - https://docs.pug.sh/reference/well-known-events/index.md - the well-known event catalog Then read this codebase before you write anything, and work out what the service actually does: its routes or handlers, its main models, and the state changes that matter to the business. The events worth tracking are the moments the service exists to produce, not request logging. If you cannot state what this service is for in one sentence, keep reading. Then: 1. Write one small client that POSTs to /sdk.events.v1.EventsService/BatchCreate on the base URL, with the headers Content-Type: application/json, Connect-Protocol-Version: 1, and x-api-key set to the private key (prv_...) from an environment variable, never committed. 2. Wrap every custom property value in its typed form - stringValue, intValue (a JSON string), doubleValue, boolValue, timestampValue. This is the part that is most often wrong. Property keys must not start with a dollar sign, and the event kind may hold only ASCII letters, digits, _, . and -. 3. Send events in batches of at most 1000, and read "dropped" and "droppedByReason" on the response - a 200 does not mean every event landed. 4. Call it for the three or four actions you identified. Name events from the catalog before you invent one. All 127 well-known events are available over HTTP, and a well-known kind fills in the dashboards built on it, which a custom kind leaves empty. Nothing checks their properties - no compiler, and not the server, which stores what it is sent - so a misspelled name or a wrong type fails silently. Search the catalog for every action you are about to track, take property names and types from that page, and fall back to a custom snake_case name only when nothing fits. When you do, tell me which event you considered and why it did not. Do not invent fields that are not in the events schema above. When you are done, tell me in one sentence what you concluded this service does, then show me the client, the event names you chose, and the environment variables I need to set.
What you’ll need
Two values the agent can’t find on its own - without them it invents a placeholder and leaves it there:
- Project ID - in the dashboard URL,
/p/<projectId>. - Public key (
pub_...) for a browser or mobile app, or a private key (prv_...) for a backend, through the Node, Go or Ruby SDK or the HTTP API. Both live under Settings > API Keys; see Authentication.
Every prompt asks for environment variables rather than literals. Only the public key may ship to a client - it is write-scoped, so the worst a leaked one buys is junk events. A private key also reads your analytics.
Check the agent’s work
Agents are good at the wiring and careless about the parts that only fail in production. Before you merge, confirm:
-
page_viewand your own events appear under Live and Events in the dashboard. Allow ~10 seconds - events are batched. - No key is hardcoded, and no
prv_key appears anywhere a browser can reach. Grep the diff forpub_andprv_. -
initruns once, client-side. A second call no-ops with a console warning; an SSR call warns and does nothing. - The agent’s one-line summary of what your product does is actually right. Each prompt asks for it, and it’s the cheapest thing to check: if the agent misread the product, every event name below it is wrong too.
- Every event that could have come from the well-known catalog did. This is the check worth making by hand: the prompt asks the agent to name what it rejected, so read that list. A custom name where a catalog event exists costs you the typed schema, leaves the dashboards built on that event empty, and renaming it later splits the metric in two.
- Nobody was silently opted in. On the Web SDK,
optInTracking()belongs behind a real consent decision - see Tracking consent.
Give the agent more than a prompt
The prompt is the shortest path. Three more surfaces are worth knowing about:
Every page as markdown
Append /index.md to any docs URL, or use Copy page at the top of a
page. /llms.txt indexes the site;
/llms-full.txt is the whole corpus in
one document.
Read your data from the agent
The MCP server gives an agent tools over your own projects: run an insight, browse the event stream, look up one user, build a dashboard. Claude and ChatGPT add it from their directories. That’s for asking questions after the SDK is in, not for installing it.