# generate_tracking_code

Generate server-only examples using the downloaded local package.

## Purpose

Generate server-only examples using the downloaded local package.

## Access and effects

Owner workspace credential only. Member, partner and app-bound affiliate credentials cannot use this tool. Use the owned app UUID from [list_apps](/docs/mcp/list-apps). Only register_events writes; the other instrumentation tools read or generate code.

## Example request

Identifiers are fictional. Use the actual owned app and returned plan; do not fabricate production receipts.

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "generate_tracking_code",
    "arguments": {
      "appId": "11111111-1111-4111-8111-111111111111",
      "framework": "react-router"
    }
  }
}
```

POST to `https://heycrust.com/api/mcp` with `Content-Type: application/json` and `Authorization: Bearer <YOUR_CREDENTIAL>`. Check JSON-RPC errors and `result.isError`, then parse JSON text in `result.content`.

## Result and interpretation

Returns Node, Remix or React Router server code for the owned app. Framework defaults to node. Use events from the reviewed plan to generate edited names. The package is a download, not an npm publication. Set server-only environment variables; use a persistent local volume and verified Shopify session/Admin shop data or identify evidence. Prepare once with prepareSetupCompleted using the operation’s durable ID and original occurredAt; persist its entire normalized event with the actual business write. After commit call recordSetupCompleted(savedEvent), and reuse that exact saved event after completion or restart. Caller-supplied SDK IDs without occurredAt reject locally. Completed queue records are removed; Crust’s immutable receiver hash remains authoritative for changed-content conflicts. Extract the download to crust-tracking/. The generated example reports the final setup observation; instrument the remaining reviewed milestones at their actual successful business operations.

## Delivery boundaries

[Download the Node ESM package](/api/tracking/package). The SQLite spool requires Node 22.13+ or 24+ and a persistent local disk. Ephemeral Render/serverless disk does not retain queued work across replacements or deployments. Existing durable PostgreSQL/Prisma outboxes should use the package's guarded delivery seam and preserve their shared lifecycle fences, redaction cancellation and retained reinstall epochs.

Clear an optional analyticsHandle to null (or omit it) for Crust-only tracking. Generated Shopify maps exclude those events; existing registered handles and pinned definitions are preserved.

Shopify mirroring is opt-in per explicit `crust.analytics.*` monitoring handle. Keep handles absent from pricing meters; no `value`, billing, contact or identity attributes are permitted. Shopify uses client credentials and the 2026-10 App Events endpoint. Exact 202 plus success=true confirms transport acceptance, not Analytics processing. Shopify custom-event deduplication lasts 24 hours; never claim permanent exactly-once delivery. Analytics developer preview access and accepted declarations are separate. No generic App Events read/backfill API is assumed. The SDK defaults to32 bounded attempts with5-second polling and exponential backoff capped at1hour; a repeated1hour outage remains queued and recovery is retried automatically. The next retry may take up to the backoff cap; custom lower attempt limits can exhaust earlier. [Shopify reference](https://shopify.dev/docs/api/app-events).

Recognized PostgreSQL timeouts return `status: unavailable` with `reasons: [query_timeout]`; do not interpret missing totals as zero.
