| name | customerio-multi-env-setup |
| description | Configure Customer.io multi-environment setup.
Use when setting up development, staging, and production
environments with proper isolation.
Trigger with phrases like "customer.io environments", "customer.io staging",
"customer.io dev prod", "customer.io workspace".
|
| allowed-tools | Read, Write, Edit, Bash(kubectl:*), Bash(curl:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Customer.io Multi-Environment Setup
Overview
Configure isolated Customer.io environments for development, staging, and production with proper data separation and configuration management.
Prerequisites
- Customer.io account with multiple workspaces
- Environment variable management system
- CI/CD pipeline configured
Environment Strategy
| Environment | Customer.io Workspace | Purpose |
|---|
| Development | dev-workspace | Local development, testing |
| Staging | staging-workspace | Pre-production testing |
| Production | prod-workspace | Live users, real messaging |
Instructions
Step 1: Workspace Setup
Create separate workspaces in Customer.io for each environment:
- Go to Customer.io Dashboard > Settings > Workspaces
- Create workspaces:
[app-name]-dev, [app-name]-staging, [app-name]-prod
- Generate API keys for each workspace
- Store credentials securely
Step 2: Environment Configuration
export interface CustomerIOEnvironmentConfig {
siteId: string;
apiKey: string;
appApiKey: string;
webhookSecret: string;
region: 'us' | 'eu';
options: {
dryRun: boolean;
logLevel: 'debug' | 'info' | 'warn' | 'error';
eventPrefix: string;
};
}
type Environment = 'development' | 'staging' | 'production';
const configs: Record<Environment, CustomerIOEnvironmentConfig> = {
development: {
siteId: process.env.CIO_DEV_SITE_ID!,
apiKey: process.env.CIO_DEV_API_KEY!,
appApiKey: process.env.CIO_DEV_APP_API_KEY!,
webhookSecret: process.env.CIO_DEV_WEBHOOK_SECRET!,
region: 'us',
options: {
dryRun: process.. === ,
: ,
:
}
},
: {
: process..!,
: process..!,
: process..!,
: process..!,
: ,
: {
: ,
: ,
:
}
},
: {
: process..!,
: process..!,
: process..!,
: process..!,
: ,
: {
: ,
: ,
:
}
}
};
(): {
env = (process.. || ) ;
config = configs[env];
(!config) {
();
}
(config, env);
config;
}
(): {
required = [, , ];
missing = required.( !config[key keyof ]);
(missing. > ) {
();
}
}
Step 3: Environment-Aware Client
import { TrackClient, APIClient, RegionUS, RegionEU } from '@customerio/track';
import { getConfig, CustomerIOEnvironmentConfig } from '../config/customerio';
export class EnvironmentAwareClient {
private trackClient: TrackClient;
private apiClient: APIClient;
private config: CustomerIOEnvironmentConfig;
constructor() {
this.config = getConfig();
const region = this.config.region === 'eu' ? RegionEU : RegionUS;
this.trackClient = new TrackClient(
this.config.siteId,
this.config.apiKey,
{ region }
);
this.apiClient = new APIClient(.., { region });
}
(: , : <, >): <> {
(...) {
.(, , { userId, attributes });
;
}
..(userId, {
...attributes,
: process..
});
}
(: , : , ?: <, >): <> {
eventName = ;
(...) {
.(, , { userId, eventName, data });
;
}
..(userId, {
: eventName,
: {
...data,
: process..
}
});
}
(: , : , ?: ): {
levels = [, , , ];
configLevel = levels.(...);
messageLevel = levels.(level);
(messageLevel >= configLevel) {
[level ](, data);
}
}
}
Step 4: Kubernetes Configuration
apiVersion: v1
kind: ConfigMap
metadata:
name: customerio-config
data:
CUSTOMERIO_REGION: "us"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: customerio-config
data:
CUSTOMERIO_REGION: "us"
CIO_DRY_RUN: "true"
CIO_LOG_LEVEL: "debug"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: customerio-config
data:
CUSTOMERIO_REGION: "us"
CIO_DRY_RUN: "false"
CIO_LOG_LEVEL: "info"
---
apiVersion: v1
kind: ConfigMap
metadata:
name: customerio-config
data:
CUSTOMERIO_REGION: "us"
Step 5: Secrets Management
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: customerio-secrets
spec:
refreshInterval: 1h
secretStoreRef:
name: gcp-secret-store
kind: ClusterSecretStore
target:
name: customerio-secrets
creationPolicy: Owner
data:
- secretKey: CUSTOMERIO_SITE_ID
remoteRef:
key: customerio-site-id-${ENVIRONMENT}
- secretKey: CUSTOMERIO_API_KEY
remoteRef:
key: customerio-api-key-${ENVIRONMENT}
- secretKey: CUSTOMERIO_APP_API_KEY
remoteRef:
key: customerio-app-api-key-${ENVIRONMENT}
- secretKey: CUSTOMERIO_WEBHOOK_SECRET
remoteRef:
key: customerio-webhook-secret-${ENVIRONMENT}
Step 6: CI/CD Environment Promotion
name: Promote to Environment
on:
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
type: choice
options:
- staging
- production
jobs:
promote:
runs-on: ubuntu-latest
environment: ${{ github.event.inputs.environment }}
steps:
- uses: actions/checkout@v4
- name: Verify Customer.io credentials
run: |
curl -s -o /dev/null -w "%{http_code}" \
-X GET "https://track.customer.io/api/v1/accounts" \
-u "${{ secrets.CUSTOMERIO_SITE_ID }}:${{ secrets.CUSTOMERIO_API_KEY }}" \
| grep -q "200" || exit 1
- name: Deploy to ${{ github.event.inputs.environment }}
run: |
kubectl apply -k k8s/overlays/${{ github.event.inputs.environment }}
- name:
Step 7: Data Isolation Verification
import { TrackClient, RegionUS } from '@customerio/track';
async function verifyEnvironmentIsolation(): Promise<void> {
const environments = ['development', 'staging', 'production'];
const testUserId = `isolation-test-${Date.now()}`;
for (const env of environments) {
const config = loadConfig(env);
const client = new TrackClient(config.siteId, config.apiKey, { region: RegionUS });
await client.identify(testUserId, {
email: `${testUserId}@${env}.test`,
_isolation_test: true,
_environment: env
});
console.log(`Created test user in ${env}`);
}
console.log();
( env environments) {
config = (env);
.();
}
( env environments) {
config = (env);
client = (config., config., { : });
client.(testUserId);
.();
}
.();
}
Environment Checklist
Development
Staging
Production
Error Handling
| Issue | Solution |
|---|
| Wrong environment data | Verify workspace credentials |
| Cross-env pollution | Use distinct user ID prefixes |
| Missing secrets | Check secret manager configuration |
Resources
Next Steps
After multi-env setup, proceed to customerio-observability for monitoring.