### Install @policystack/core Source: https://www.policystack.dev/docs/consent/core Install the core consent package using bun. ```sh bun add @policystack/core ``` -------------------------------- ### Install @policystack/core and @policystack/react Source: https://www.policystack.dev/docs/consent/react Install the core consent library and the React adapter using bun. ```sh bun add @policystack/core @policystack/react ``` -------------------------------- ### Install @policystack/core and @policystack/svelte Source: https://www.policystack.dev/docs/consent/svelte Install the necessary core and Svelte packages using bun. ```sh bun add @policystack/core @policystack/svelte ``` -------------------------------- ### Install @policystack/svelte and @policystack/sdk Source: https://www.policystack.dev/docs/policy/svelte Install the necessary packages for the Svelte adapter and SDK using Bun. ```sh bun add @policystack/svelte @policystack/sdk ``` -------------------------------- ### Install Policystack CLI Source: https://www.policystack.dev/docs/policy/configuration Use the Policystack CLI to initialize your project, which installs the SDK and scaffolds a starter config. ```sh bunx @policystack/cli init ``` -------------------------------- ### Install @policystack/scripts Source: https://www.policystack.dev/docs/consent/scripts Install the core and scripts packages using npm. ```sh npm install @policystack/core @policystack/scripts ``` -------------------------------- ### Install @policystack/cli Source: https://www.policystack.dev/docs/consent/cli Install the @policystack/cli package as a development dependency using Bun. ```sh bun add -D @policystack/cli ``` -------------------------------- ### Install @policystack/core and @policystack/solid Source: https://www.policystack.dev/docs/consent/solid Install the necessary packages for the Solid adapter and core consent functionality. ```sh bun add @policystack/core @policystack/solid ``` -------------------------------- ### Install @policystack/core and @policystack/angular Source: https://www.policystack.dev/docs/consent/angular Install the core consent package and the Angular adapter using pnpm. ```sh pnpm add @policystack/core @policystack/angular ``` -------------------------------- ### Install Cookie Policy Component with shadcn Source: https://www.policystack.dev/docs/policy/policies/quick-start Use this command to install the ready-to-use Cookie Policy component from the Policy shadcn registry. This command also installs a base renderer and starter config. ```sh bunx shadcn@latest add @policystack/cookie-policy ``` -------------------------------- ### Install @policystack/vite Source: https://www.policystack.dev/docs/consent/vite Install the @policystack/vite package as a development dependency. ```sh bun add -D @policystack/vite ``` -------------------------------- ### Install Policystack Core and Framework Packages Source: https://www.policystack.dev/docs/consent Install the core package along with the framework-specific package for React, Vue, Solid, Svelte, or Angular. ```sh # React npm install @policystack/core @policystack/react # Vue npm install @policystack/core @policystack/vue # Solid npm install @policystack/core @policystack/solid # Svelte npm install @policystack/core @policystack/svelte # Angular npm install @policystack/core @policystack/angular ``` -------------------------------- ### Install @policystack/react and @policystack/sdk Source: https://www.policystack.dev/docs/policy/react Install the necessary packages for the React adapter and SDK. Ensure you have React version 18 or higher as a peer dependency. ```sh bun add @policystack/react @policystack/sdk ``` -------------------------------- ### Wrap App with PolicyStack Provider Source: https://www.policystack.dev/docs/policy/policies/quick-start Wrap your application with the PolicyStack provider, passing the starter config. This setup is required after installing policy components using shadcn. ```tsx import { PolicyStack } from "@policystack/react/provider"; import policy from "@/policy"; export default function RootLayout({ children }) { return {children}; } ``` -------------------------------- ### Initialize Policy CLI Source: https://www.policystack.dev/docs/policy/cli Run the Policy CLI initialization command from your project root. This command installs dependencies, scaffolds configuration, and generates an agent prompt. ```sh bunx @policystack/cli init ``` ```sh npx @policystack/cli init ``` ```sh pnpm dlx @policystack/cli init ``` -------------------------------- ### Install Policystack SDK Manually Source: https://www.policystack.dev/docs/policy/configuration Alternatively, install the `@policystack/sdk` package manually using your package manager. ```sh bun add @policystack/sdk ``` -------------------------------- ### Setup (Svelte 5 runes) Source: https://www.policystack.dev/docs/consent/svelte Call `setPolicyStackConsentContext` once in a root component to initialize the consent context. You can pass configuration directly or a pre-created store. ```APIDOC ## Setup (Svelte 5 runes) Call `setPolicyStackConsentContext` once in a root component (e.g., `+layout.svelte` for SvelteKit): ```svelte {@render children?.()} ``` You can pass a pre-created store with `setPolicyStackConsentContext({ store })` instead. ``` -------------------------------- ### Install @policystack/core and @policystack/vue Source: https://www.policystack.dev/docs/consent/vue Install the core consent library and the Vue 3 adapter. Peer dependency: vue >= 3.4. ```sh bun add @policystack/core @policystack/vue ``` -------------------------------- ### Install @policystack/vue and @policystack/sdk Source: https://www.policystack.dev/docs/policy/vue Install the necessary packages for the Vue adapter and SDK. Ensure Vue version 3 or higher is used as a peer dependency. ```sh bun add @policystack/vue @policystack/sdk ``` -------------------------------- ### Install Privacy Policy Component with shadcn Source: https://www.policystack.dev/docs/policy/policies/quick-start Use this command to install the ready-to-use Privacy Policy component from the Policy shadcn registry. This command also installs a base renderer and starter config. ```sh bunx shadcn@latest add @policystack/privacy-policy ``` -------------------------------- ### useConsent() Source: https://www.policystack.dev/docs/consent/vue Returns reactive refs for the current consent state plus action methods. Use it inside `setup()` or any ` ``` ### Returns - `route` (string): The current consent route. - `decisions` (object): An object containing consent decisions. - `acceptAll` (function): Function to accept all consent categories. - `acceptNecessary` (function): Function to accept only necessary consent categories. - `setRoute` (function): Function to set the current consent route. ``` -------------------------------- ### SvelteKit SSR Consent Setup Source: https://www.policystack.dev/docs/consent/svelte Initialize the consent context in your root SvelteKit layout file using setPolicyStackConsentContext. This ensures safe hydration. ```svelte {@render children()} ``` -------------------------------- ### Setup PolicyStack Provider in Solid App Source: https://www.policystack.dev/docs/consent/solid Wrap your Solid application with the PolicyStack provider, passing your policystack.ts configuration. ```tsx import { PolicyStack } from "@policystack/solid/consent"; import { render } from "solid-js/web"; import config from "./policystack"; render( () => ( ), document.getElementById("root")!, ); ``` -------------------------------- ### Install Policy Skill Pack in Claude Code Source: https://www.policystack.dev/docs/policy/agent-skills Use these commands to add and install the Policy skill pack from the marketplace within Claude Code. The skills activate automatically when a matching task is encountered. ```bash /plugin marketplace add jamiedavenport/policystack /plugin install policystack ``` -------------------------------- ### Use useConsent composable in Vue Source: https://www.policystack.dev/docs/consent/vue Access reactive consent state and action methods like acceptAll, acceptNecessary, and setRoute. Use within setup() or ``` -------------------------------- ### Setup PolicyStack Vite Plugin Source: https://www.policystack.dev/docs/policy/policies/auto-collect Add the `policyStack()` plugin to your Vite configuration to enable auto-collection during the build process. ```ts import { defineConfig } from "vite"; import { policyStack } from "@policystack/vite"; export default defineConfig({ plugins: [policyStack()], }); ``` -------------------------------- ### Setup PolicyStack Provider in RootLayout Source: https://www.policystack.dev/docs/policy/react Wrap your application with the PolicyStack provider to supply policy context and consent store. Pass your entire policystack.ts config to the provider. ```tsx import { PolicyStack } from "@policystack/react/provider"; import policy from "@/policystack"; export default function RootLayout({ children }: { children: React.ReactNode }) { return {children}; } ``` -------------------------------- ### Setup PolicyStack Provider in SolidStart App (SSR) Source: https://www.policystack.dev/docs/consent/solid Integrate the PolicyStack provider into the root of your SolidStart application for server-side rendering. ```tsx // src/app.tsx import { PolicyStack } from "@policystack/solid/consent"; import { Router } from "@solidjs/router"; import { FileRoutes } from "@solidjs/start/router"; import config from "./policystack"; export default function App() { return ( ); } ``` -------------------------------- ### Provide PolicyStack Consent at Root Source: https://www.policystack.dev/docs/consent/angular Register the providePolicyStackConsent provider once at the root of your standalone Angular application. This setup configures consent categories and specifies the storage adapter. ```ts import { bootstrapApplication } from "@angular/platform-browser"; import { providePolicyStackConsent } from "@policystack/angular/consent"; import { localStorageAdapter } from "@policystack/core/consent/storage/local-storage"; import { AppComponent } from "./app.component"; bootstrapApplication(AppComponent, { providers: [ providePolicyStackConsent({ config: { categories: [ { key: "essential", label: "Essential", locked: true }, { key: "analytics", label: "Analytics" }, { key: "marketing", label: "Marketing" }, ], adapter: localStorageAdapter(), }, }), ], }); ``` -------------------------------- ### Setup PolicyStack Provider in Vue App Source: https://www.policystack.dev/docs/consent/vue Wrap your Vue app with the PolicyStack provider, passing your policystack.ts configuration. This supplies both policy context and the consent store. ```vue ``` -------------------------------- ### Next.js Root Layout Setup Source: https://www.policystack.dev/docs/consent/react Integrate the PolicyStack provider into your Next.js application's root layout for SSR compatibility. Ensure the provider is a client component. ```tsx // app/providers.tsx "use client"; import { PolicyStack } from "@policystack/react/provider"; import config from "../policystack"; export function Providers({ children }: { children: React.ReactNode }) { return {children}; } ``` ```tsx // app/layout.tsx import { Providers } from "./providers"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( {children} ); } ``` -------------------------------- ### Setup Consent Context in Svelte 5 Runes Source: https://www.policystack.dev/docs/consent/svelte Call setPolicyStackConsentContext once in a root component to initialize the consent context with categories. This is typically done in a SvelteKit layout file. ```svelte {@render children?.()} ``` -------------------------------- ### Configure Re-consent Triggers Source: https://www.policystack.dev/docs/consent/core Set up triggers to re-prompt users for consent when policy changes, categories are added, jurisdiction differs, or the record expires. This example shows how to configure these triggers within the `createConsentStore` function. ```typescript const store = createConsentStore({ categories, policyVersion: "v2", adapter: cookieAdapter(), triggers: { policyVersionChanged: true, // config.policyVersion !== record.policyVersion categoriesAdded: true, // a category in config is missing from the record expiresAfter: "13 months", // older than the duration → re-prompt jurisdictionChanged: true, // current jurisdiction differs from the recorded one }, }); ``` -------------------------------- ### Nuxt 3 App Setup with PolicyStack Provider Source: https://www.policystack.dev/docs/consent/vue Integrate the PolicyStack provider in Nuxt 3 by wrapping the app, typically in app.vue, to provide consent management across the application. ```vue ``` -------------------------------- ### Setup PolicyStack Provider in Svelte App Source: https://www.policystack.dev/docs/policy/svelte Wrap your Svelte application with the PolicyStack provider to manage policy context and consent store. Ensure your policystack.ts config is imported correctly. ```svelte {@render children()} ``` -------------------------------- ### Get Granular Category Consent in Svelte Source: https://www.policystack.dev/docs/consent/svelte Use getCategory(key) for per-category consent management. This allows direct access to a category's granted status and toggle functionality. ```svelte ``` -------------------------------- ### Manual Integration with PolicyStack Provider and Components Source: https://www.policystack.dev/docs/policy/policies/quick-start Manually integrate Policy Stack by wrapping your app with the PolicyStack provider and rendering policy components. This example shows rendering both PrivacyPolicy and CookiePolicy. ```tsx import { PolicyStack } from "@policystack/react/provider"; import { PrivacyPolicy, CookiePolicy } from "@policystack/react/policy"; import policy from "@/policy"; export function PrivacyPolicyPage() { return ( ); } ``` -------------------------------- ### Basic Usage with Meta Pixel Source: https://www.policystack.dev/docs/consent/scripts Import `gateScript` and a vendor integration like `metaPixel`. Configure the vendor with necessary options and then use `gateScript` to manage its lifecycle. ```ts import { gateScript } from "@policystack/core/consent"; import { metaPixel } from "@policystack/scripts/meta-pixel"; const pixel = metaPixel({ pixelId: "1234567890" }); const dispose = gateScript(store, pixel); ``` -------------------------------- ### SvelteKit (SSR + hydration) Source: https://www.policystack.dev/docs/consent/svelte Demonstrates how to set up the consent context in a root SvelteKit layout to ensure proper SSR and hydration. ```APIDOC ## SvelteKit (SSR + hydration) Call `setPolicyStackConsentContext` from your root layout. It uses Svelte's `setContext`, so it hydrates safely: ```svelte {@render children()} ``` ``` -------------------------------- ### Creating and Interacting with Consent Store Source: https://www.policystack.dev/docs/consent/core Demonstrates how to create a consent store, make a decision (accept all), and retrieve the current consent record. The `source` parameter can override the inferred source. ```typescript const store = createConsentStore({ categories, locale: "en-GB", // optional; falls back to navigator.language, then "en" adapter: cookieAdapter(), }); store.acceptAll(); store.getConsentRecord(); // { // schemaVersion: 1, // decisions: { essential: true, analytics: true, marketing: true }, // policyVersion: "", // decidedAt: "2026-04-29T12:34:56.000Z", // jurisdiction: "EEA", // locale: "en-GB", // source: "banner", // } ``` -------------------------------- ### PostHog Integration Source: https://www.policystack.dev/docs/consent/scripts Configure PostHog with your API key and host. Defaults to requiring 'analytics' consent and queues common `posthog.*` methods. Calls `posthog.init(apiKey, { api_host, ...options })` on load. ```ts import { posthog } from "@policystack/scripts/posthog"; posthog({ apiKey: "phc_xxx", apiHost: "https://eu.i.posthog.com" }); ``` -------------------------------- ### Display policystack CLI Help Source: https://www.policystack.dev/docs/consent/cli Run the policystack command with the --help flag to view available commands and options. ```sh policystack --help ``` -------------------------------- ### Initialize Consent Store with Default GPC Handling Source: https://www.policystack.dev/docs/consent/core Use this to enable GPC handling by default. The store will automatically apply opt-outs when the GPC signal is detected. ```typescript import { createConsentStore } from "@policystack/core/consent"; const store = createConsentStore({ categories }); // Brave (and any browser asserting GPC) starts with all opt-outs denied. ``` -------------------------------- ### Create and use consent store Source: https://www.policystack.dev/docs/consent/core Initialize a consent store with categories and a localStorage adapter. Subscribe to state changes and accept all consents. ```ts import { createConsentStore } from "@policystack/core/consent"; import { localStorageAdapter } from "@policystack/core/consent/storage/local-storage"; const store = createConsentStore({ categories: [ { key: "essential", label: "Essential", locked: true }, { key: "analytics", label: "Analytics" }, { key: "marketing", label: "Marketing" }, ], adapter: localStorageAdapter(), }); store.subscribe((state) => render(state)); store.acceptAll(); ``` -------------------------------- ### Render Privacy Policy Page Component Source: https://www.policystack.dev/docs/policy/policies/quick-start Render the PrivacyPolicy component on the relevant page after setting up the PolicyStack provider. This assumes you have used the shadcn installation method. ```tsx import { PrivacyPolicy } from "@/components/ui/policy/privacy-policy"; export default function PrivacyPolicyPage() { return ; } ``` -------------------------------- ### Meta Pixel Integration Source: https://www.policystack.dev/docs/consent/scripts Configure Meta Pixel with your pixel ID. Defaults to requiring 'marketing' consent and queues `fbq`. Fires `fbq("init", pixelId)` and `fbq("track", "PageView")` on load. ```ts import { metaPixel } from "@policystack/scripts/meta-pixel"; metaPixel({ pixelId: "1234567890" }); ``` -------------------------------- ### Importing Multiple Integrations Source: https://www.policystack.dev/docs/consent/scripts If tree-shaking the entry barrel is acceptable for your build, you can import multiple integrations directly from the package root. ```ts import { ga4, metaPixel, posthog } from "@policystack/scripts"; ``` -------------------------------- ### Provide PolicyStack Consent with Existing Store Source: https://www.policystack.dev/docs/consent/angular Alternatively, you can pass a pre-created consent store to providePolicyStackConsent instead of the configuration object. ```ts import { createConsentStore } from "@policystack/core/consent"; const store = createConsentStore({ categories }); providePolicyStackConsent({ store }); ``` -------------------------------- ### Use useCategory composable in Vue Source: https://www.policystack.dev/docs/consent/vue Get granular access to a specific category's granted state and toggle its consent status. Requires the category key. ```vue