Klaviyo for Vercel Shop
This skill connects a Vercel Shop storefront to Klaviyo, so browsing and cart activity, email signups and back-in-stock requests reach Klaviyo, and the flows Klaviyo already runs for Shopify stores (welcome, browse abandonment, abandoned cart, back in stock) work on the headless storefront too.
npx skills add https://developers.klaviyo.com/ --skill klaviyo-vercel-shopFiles
assets/components/analytics/klaviyo-client.tsx.mdassets/components/klaviyo/email-capture-form.tsx.mdassets/components/klaviyo/identify.tsx.mdassets/lib/klaviyo/client.ts.mdassets/lib/klaviyo/index.ts.mdreferences/account-setup.mdreferences/code-changes.mdreferences/csp.mdreferences/troubleshooting.md
This skill connects a Vercel Shop storefront to Klaviyo, so browsing and cart activity, email signups and back-in-stock requests reach Klaviyo, and the flows Klaviyo already runs for Shopify stores (welcome, browse abandonment, abandoned cart, back in stock) work on the headless storefront too. Shopify still owns the catalog, orders and checkout, and Klaviyo's Shopify integration still syncs them. The storefront only adds what a headless site would otherwise lose: onsite activity, which used to come from the Shopify theme.
The integration is a destination on the Hydrogen analytics bus that Vercel Shop already uses. It never publishes events itself, it loads klaviyo.js only after the shopper's consent allows tracking, and it uses only the public API key (the six-character site ID) and Klaviyo's client APIs. No Klaviyo private API key ever goes into the storefront, its Vercel environment, or a commit.
Work through the steps in order. Ask before every write to the user's Klaviyo account or Vercel project.
Step 0 — Check the project
- Confirm this is Vercel Shop:
package.jsonhas"name": "vercel-shop", andlib/analytics/client.tsexportsaddAnalyticsDestination. Read theversion. This skill was written against2026.10.2; on a later version, read each file before editing it rather than trusting the anchors inreferences/code-changes.md. - Check whether Klaviyo is already there. If
lib/klaviyo/index.tsexists, don't copy anything over it: compare it with assets/lib/klaviyo/index.ts, report the differences, and ask before replacing it. Every edit inreferences/code-changes.mdsays how to tell it's already applied. - Check whether the Vercel project is linked (
.vercel/project.jsonexists). If not, and the user wants environment variables set from the terminal, ask them to runvercel link.
Step 1 — Ask what the user has and wants
Ask these together and wait for every answer:
- How is Klaviyo connected? Through the Klaviyo integration on the Vercel Marketplace (the public key is already in the project's environment), through the Klaviyo MCP server in this agent, or neither (they'll paste the public key).
- Which features? Onsite tracking is always on. The footer signup form needs a list. Back-in-stock alerts need Back in Stock turned on in Klaviyo and the Shopify catalog synced. Signed-in customers are identified automatically when Vercel Shop's customer accounts are on (
auth.isEnabled); there's nothing to choose. - Is Klaviyo's Shopify integration connected to the same Klaviyo account? Product-matched flows, back in stock and order events depend on it. The storefront doesn't replace it.
- Does the public key have a domain allowlist? If it does, every storefront host has to be on it, or client calls return
403.
references/account-setup.md explains each answer and what to do about it.
Step 2 — Set up the Klaviyo side
Follow references/account-setup.md:
- with the Marketplace integration, pull the existing variables;
- with the MCP server, read the account, pick or create the signup list, and offer a welcome flow;
- otherwise, have the user paste the public key and list ID.
Confirm the account name with the user before writing anything to it. Never pick a list for them, and never set a flow live without asking: a live flow emails every new list member.
Step 3 — Add the code
- Copy these files into the project at the same paths, unchanged:
- assets/lib/klaviyo/index.ts: event names, payload mapping, the client API call
- assets/lib/klaviyo/client.ts: the consent-gated call queue and the one
klaviyo.jsloader - assets/components/analytics/klaviyo-client.tsx: registers the
klaviyodestination on the bus - assets/components/klaviyo/email-capture-form.tsx: signup and back-in-stock forms
- assets/components/klaviyo/identify.tsx: identifies a signed-in customer
- Apply every edit in
references/code-changes.md: the config flags, the destination slot in the Shopify scripts tracker, the product image on Viewed Product, the footer form, the back-in-stock form, account identification,.env.exampleandturbo.json. Turn off the config flags for features the user didn't choose rather than skipping their edits. Tell the user that turning Klaviyo on also loads Shopify's analytics scripts and, in consent regions, its consent banner (edit 2 explains why). - If the storefront sets a Content Security Policy, add Klaviyo's hosts from
references/csp.md. Stock Vercel Shop sets none. - Run
pnpm typecheckandpnpm lint, and fix what they report before going on.
Step 4 — Set the environment and deploy
The public key goes in NEXT_PUBLIC_KLAVIYO_COMPANY_ID, and the signup list in NEXT_PUBLIC_KLAVIYO_LIST_ID, in all three Vercel environments. vercel env add reads the value from stdin:
for env in development preview production; do
printf %s "$COMPANY_ID" | vercel env add NEXT_PUBLIC_KLAVIYO_COMPANY_ID "$env" --force
printf %s "$LIST_ID" | vercel env add NEXT_PUBLIC_KLAVIYO_LIST_ID "$env" --force
done
vercel env pull .env.development.local --yesnext dev gives .env.development.local priority over .env.local. NEXT_PUBLIC_ values are compiled into the bundle, so if the project is already deployed, ask before redeploying (vercel deploy --prod): the live site only picks them up after a new build.
Step 5 — Hand over what only the user can do
Tell the user, in one list, what's left in Klaviyo that has no API:
- connect Klaviyo's Shopify integration (Integrations, then Shopify), if it isn't;
- add every storefront host to the public key's allowlist, if it has one;
- turn on Back in Stock, if they chose it.
Step 6 — Verify
Run pnpm dev with NEXT_PUBLIC_KLAVIYO_DEBUG="1" and watch the browser console:
- Load the home page:
[klaviyo] klaviyo.js loaded after consent, once (after accepting the consent banner, in a consent region). - Open a product:
Viewed Product, with a numericProductID. - Add it to the cart: one
Added to Cart, after the cart confirms. - Go to another page:
page change. - Submit the footer form with a new test address on a domain the user controls. In Klaviyo, that profile shows the list subscription and the events from steps 2 and 3.
- If a welcome flow is live, the profile shows Received Email within a few minutes. A profile enters a list-triggered flow only the first time it joins, so use a new address for each test.
Debug mode logs every call even without a public key, so the code can be checked before the account is connected. When something doesn't arrive, read references/troubleshooting.md.
Next
- Shop Agent:
klaviyo-vercel-shop-agentlets the storefront's AI shopping assistant sign shoppers up for back-in-stock alerts and records that it did. - Popups and embedded forms:
klaviyo-onsite-formsbuilds them, scoped to this storefront. - Reporting:
klaviyo-store-analyticsanswers questions about the storefront's signups, events and flows.
Pitfalls
- A private key in the storefront. Everything here runs in the shopper's browser or a shopper-facing agent. A private key there can read and change the whole Klaviyo account. Refuse, even for a "quick test".
- A second
klaviyo.js. A manual<script>, a tag manager, or a Shopify app embed on the same domain double-counts events and breaks form state. Load it only throughlib/klaviyo/client.ts. - Registering the destination twice. Removing and re-adding a destination replays the bus buffer and duplicates every event.
klaviyo-client.tsxregisters once per page lifetime; keep it that way. - Calling
klaviyo.jsfrom the destination'ssetup().setup()isn't consent-gated. Only the subscribed event handlers are. - Recomputing prices or IDs. They come from the bus payloads, which come from Shopify. Klaviyo's Shopify catalog keys products by numeric ID, which
toShopifyNumericIdderives from the Storefront API GID. - Repointing a live store's emails. Changing the Shopify catalog's product URL base in Klaviyo repoints every existing email at the new storefront. Leave it alone if the Shopify store already has a live storefront.
no-bannerconsent mode. Visitors in consent regions never grant consent, so Klaviyo never loads for them. Keepdefault-bannerunless the storefront supplies its own consent UI.
Reference files
references/account-setup.md: the four questions, the MCP setup, the welcome flow definition, and the manual pathreferences/code-changes.md: every edit to existing Vercel Shop files, with anchors and an already-applied checkreferences/csp.md: Klaviyo's hosts for a Content Security Policyreferences/troubleshooting.md: symptoms, causes and fixesassets/: the five new files, at the paths they belong in the project