Basic Usage
Common usage patterns for the Conviso Node SDK.
User Signup Flow
Complete signup flow with identification and welcome email:
import { CDPClient } from '@codematic.io/cdp-node';
const client = new CDPClient({
cdpApiKey: process.env.CDP_API_KEY
});
async function handleUserSignup(email: string, name: string) {
try {
// 1. Create user in your database
const user = await db.users.create({
email,
name,
createdAt: new Date()
});
// 2. Identify in CDP
await client.identify(user.id, {
email: user.email,
name: user.name,
created_at: user.createdAt.toISOString(),
source: 'web_signup'
});
// 3. Track signup event
await client.track(user.id, 'user_signed_up', {
source: 'web',
plan: 'free'
});
// 4. Send welcome email
await client.sendEmail({
to: user.email,
identifiers: { id: user.id },
transactional_message_id: 'WELCOME_EMAIL',
message_data: {
name: user.name,
activation_link: `https://app.example.com/activate/${user.activationToken}`
}
});
return { success: true, userId: user.id };
} catch (error) {
console.error('Signup error:', error);
throw error;
}
}