--- name: croct-integrate-sdk description: >- Use when installing or using a Croct SDK in application code: rendering slot content, evaluating CQL queries, server or client fetching, prerendering, identifying users, app ID / API key env vars, testing, or debugging. Covers JavaScript (`@croct/plug`, `croct.fetch`, `croct.evaluate`), React (`@croct/plug-react`, ``, `useContent`, ``, `useEvaluation`, `useCroct`), Next.js (`@croct/plug-next`, `fetchContent`, `cql`, middleware/proxy, `NEXT_PUBLIC_CROCT_APP_ID`, `CROCT_API_KEY`), Vue (`@croct/plug-vue`), Nuxt (`@croct/plug-nuxt`), Shopify Hydrogen (`@croct/plug-hydrogen`), PHP (`croct/plug-php`), Laravel, Symfony, and Drupal. Triggers: slot IDs like `home-hero@1`, `SlotContent`, "Croct is not plugged in", "initial content is required for server-side rendering", "Did you forget to configure Croct's middleware?", CORS errors. --- # Integrate a Croct SDK Wire a Croct SDK into an app so it renders slot content, evaluates CQL, and identifies users. Content and audiences live in the Croct dashboard; the code only references **slots** by ID and version and supplies a fallback. ## Workflow ``` - [ ] 1. Detect the stack and pick the SDK (table below) - [ ] 2. Install with the CLI (`croct init`, run by the user), manual only if asked or the CLI cannot run - [ ] 3. Add the slot with the CLI (`npx croct@latest add slot home-hero@1 --example`) for types + fallback - [ ] 4. Render it: server-side when the framework allows, client-side otherwise - [ ] 5. Identify/anonymize users at login/logout (or pass the user ID at init) - [ ] 6. Verify: Integration page shows "Received traffic in the past 24 hours"; else debug mode ``` ### 1. Pick the SDK Read `package.json` / `composer.json` first. Pick the most specific SDK for the framework; never use the plain JavaScript SDK inside React, Next.js, Vue, Nuxt, or Hydrogen. | Stack | Package | Initialize with | Server rendering | Reference | | --- | --- | --- | --- | --- | | Plain JS, any bundler, or `