Klaviyo Multi-Environment Setup
Overview
Configure Klaviyo across development, staging, and production with separate API
keys, environment detection, secret management, and production safeguards. Every
environment follows the same shape — detect the env, resolve its config, load
its secret, guard destructive/send operations. The lean workflow and first
skeleton live here; full step-by-step code lives in
references/implementation.md.
Prerequisites
- Separate Klaviyo accounts or API keys per environment
- Secret management solution (GCP Secret Manager, AWS Secrets Manager, Vault)
klaviyo-api SDK installed
Environment Strategy
| Environment |
Klaviyo Account |
API Key |
Use Case |
| Development |
Test account |
pk_test_dev_*** |
Local development, exploration |
| Staging |
Test account |
pk_test_staging_*** |
Pre-prod validation, integration tests |
| Production |
Production account |
pk_live_*** |
Real customer data, live sends |
Important: Klaviyo does not have a sandbox mode. Use a separate test account for dev/staging to avoid sending real emails.
Instructions
The pattern is the same across all three environments; only the API key and the
per-env flags change. Read the matching section in
references/implementation.md, then:
- Write the config module — use Write/Edit to create
src/config/klaviyo.ts
with a detectEnvironment() helper and a per-env ENV_CONFIGS map that flips
enableSending, cache, and rate-limit concurrency by environment.
- Store secrets per environment — create one secret per env in your platform's
secret store (
gcloud secrets create, aws secretsmanager create-secret, or
Vault). Never commit keys; local dev reads a git-ignored .env.local.
- Add environment guards — wrap sends and deletions so non-production simply
logs instead of touching real data (
guardCampaignSend, guardedProfileDeletion).
- Wire multi-env CI — a GitHub Actions matrix maps
staging→staging key and
main→prod key, verifies connectivity, then deploys.
- Validate on startup — connect once, log the resolved account name, and warn
loudly if a
pk_live_*** key is detected outside production.
Config skeleton (first example)
// src/config/klaviyo.ts — see reference for the full ENV_CONFIGS + getSession
type Environment = 'development' | 'staging' | 'production';
function detectEnvironment(): Environment {
const env = process.env.NODE_ENV || 'development';
if (['production', 'staging'].includes(env)) return env as Environment;
return 'development';
}
// development/staging force enableSending:false; only production sends.
The full config module, per-platform secret commands, guard functions, the CI
matrix, and the startup validator are in
references/implementation.md.
Output
src/config/klaviyo.ts resolving a typed config per environment
- Per-environment secrets stored in GCP / AWS / Vault (never committed)
- Send + deletion guards that no-op in dev/staging and act only in production
- A GitHub Actions matrix deploying staging and production with the right key
- Startup validation that logs the connected account and flags a leaked prod key
Error Handling
| Issue |
Cause |
Solution |
| Wrong key for environment |
Missing env-specific secret |
Verify secret per environment |
| Production key in dev |
Key leak risk |
Add startup validation warning |
| Sends in staging |
enableSending not checked |
Add campaign send guard |
| Config merge fails |
Invalid env value |
Validate NODE_ENV on startup |
Examples
Block a campaign send outside production. The guard reads the resolved config
and throws when sending is disabled, so a staging run can never email real
customers:
guardCampaignSend(); // throws in dev/staging (enableSending:false), passes in prod
Catch a leaked production key in staging. Startup validation warns when a
pk_live_*** key is present outside production:
[Klaviyo] Environment: staging
[Klaviyo] Sending enabled: false
[Klaviyo] WARNING: Production API key detected in non-production environment!
The full config module, secret-store commands for each platform, the guard
implementations, the CI matrix, and the startup validator are in
references/implementation.md.
Resources
Source: jeremylongshore/claude-code-plugins-plus-skills → plugins/saas-packs/klaviyo-pack/skills/klaviyo-multi-env-setup/SKILL.md
1---2name: klaviyo-multi-env-setup3description: "'Configure Klaviyo across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment API keys, or implementing environment-specific Klaviyo configurations. Trigger with phrases like \"klaviyo environments\", \"klaviyo staging\", \"klaviyo dev prod\", \"klaviyo environment setup\", \"klaviyo config by env\". '"4allowed-tools: "Read, Write, Edit, Bash(aws:*), Bash(gcloud:*), Bash(vault:*)"5category: backend-and-data6source_repo: jeremylongshore/claude-code-plugins-plus-skills7source_path: "plugins/saas-packs/klaviyo-pack/skills/klaviyo-multi-env-setup/SKILL.md"8source_url: https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/HEAD/plugins/saas-packs/klaviyo-pack/skills/klaviyo-multi-env-setup/SKILL.md9---1011# Klaviyo Multi-Environment Setup1213## Overview1415Configure Klaviyo across development, staging, and production with separate API16keys, environment detection, secret management, and production safeguards. Every17environment follows the same shape — detect the env, resolve its config, load18its secret, guard destructive/send operations. The lean workflow and first19skeleton live here; full step-by-step code lives in20[references/implementation.md](references/implementation.md).2122## Prerequisites2324- Separate Klaviyo accounts or API keys per environment25- Secret management solution (GCP Secret Manager, AWS Secrets Manager, Vault)26- `klaviyo-api` SDK installed2728## Environment Strategy2930| Environment | Klaviyo Account | API Key | Use Case |31|-------------|----------------|---------|----------|32| Development | Test account | `pk_test_dev_***` | Local development, exploration |33| Staging | Test account | `pk_test_staging_***` | Pre-prod validation, integration tests |34| Production | Production account | `pk_live_***` | Real customer data, live sends |3536> **Important:** Klaviyo does not have a sandbox mode. Use a separate test account for dev/staging to avoid sending real emails.3738## Instructions3940The pattern is the same across all three environments; only the API key and the41per-env flags change. Read the matching section in42[references/implementation.md](references/implementation.md), then:43441. **Write the config module** — use Write/Edit to create `src/config/klaviyo.ts`45 with a `detectEnvironment()` helper and a per-env `ENV_CONFIGS` map that flips46 `enableSending`, cache, and rate-limit concurrency by environment.472. **Store secrets per environment** — create one secret per env in your platform's48 secret store (`gcloud secrets create`, `aws secretsmanager create-secret`, or49 Vault). Never commit keys; local dev reads a git-ignored `.env.local`.503. **Add environment guards** — wrap sends and deletions so non-production simply51 logs instead of touching real data (`guardCampaignSend`, `guardedProfileDeletion`).524. **Wire multi-env CI** — a GitHub Actions matrix maps `staging`→staging key and53 `main`→prod key, verifies connectivity, then deploys.545. **Validate on startup** — connect once, log the resolved account name, and warn55 loudly if a `pk_live_***` key is detected outside production.5657### Config skeleton (first example)5859```typescript60// src/config/klaviyo.ts — see reference for the full ENV_CONFIGS + getSession61type Environment = 'development' | 'staging' | 'production';6263function detectEnvironment(): Environment {64 const env = process.env.NODE_ENV || 'development';65 if (['production', 'staging'].includes(env)) return env as Environment;66 return 'development';67}68// development/staging force enableSending:false; only production sends.69```7071The full config module, per-platform secret commands, guard functions, the CI72matrix, and the startup validator are in73[references/implementation.md](references/implementation.md).7475## Output7677- `src/config/klaviyo.ts` resolving a typed config per environment78- Per-environment secrets stored in GCP / AWS / Vault (never committed)79- Send + deletion guards that no-op in dev/staging and act only in production80- A GitHub Actions matrix deploying staging and production with the right key81- Startup validation that logs the connected account and flags a leaked prod key8283## Error Handling8485| Issue | Cause | Solution |86|-------|-------|----------|87| Wrong key for environment | Missing env-specific secret | Verify secret per environment |88| Production key in dev | Key leak risk | Add startup validation warning |89| Sends in staging | `enableSending` not checked | Add campaign send guard |90| Config merge fails | Invalid env value | Validate `NODE_ENV` on startup |9192## Examples9394**Block a campaign send outside production.** The guard reads the resolved config95and throws when sending is disabled, so a staging run can never email real96customers:9798```typescript99guardCampaignSend(); // throws in dev/staging (enableSending:false), passes in prod100```101102**Catch a leaked production key in staging.** Startup validation warns when a103`pk_live_***` key is present outside production:104105```106[Klaviyo] Environment: staging107[Klaviyo] Sending enabled: false108[Klaviyo] WARNING: Production API key detected in non-production environment!109```110111The full config module, secret-store commands for each platform, the guard112implementations, the CI matrix, and the startup validator are in113[references/implementation.md](references/implementation.md).114115## Resources116117- [Klaviyo Authentication](https://developers.klaviyo.com/en/docs/authenticate_)118- [GCP Secret Manager](https://cloud.google.com/secret-manager/docs)119- [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/)120- [12-Factor App Config](https://12factor.net/config)121- [Full implementation walkthrough](references/implementation.md) — verbatim config, secrets, guards, CI, and startup validation122- For observability setup, see the `klaviyo-observability` skill.123124---125126**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `plugins/saas-packs/klaviyo-pack/skills/klaviyo-multi-env-setup/SKILL.md`