Generating Session Tokens
Create session tokens to track user activity across your products using ductape.sessions.start().
Quick Example
const result = await ductape.sessions.start({
product: 'my-app',
env: 'prd',
tag: 'user-session',
data: {
userId: 'user_123',
details: {
username: 'johndoe',
email: 'john@example.com'
}
}
});
console.log(result.token); // Session token
console.log(result.refreshToken); // Refresh token
How It Works
- product - Your product's unique identifier
- env - Which environment (
dev,staging,prd) - tag - A label for this session type (e.g.,
checkout-flow) - data - User information and identifier
Examples
Basic session
const session = await ductape.sessions.start({
product: 'ecommerce',
env: 'prd',
tag: 'checkout-session',
data: {
userId: 'user_456',
details: {
email: 'jane@example.com'
}
}
});
Session with rich user data
const session = await ductape.sessions.start({
product: 'dashboard',
env: 'prd',
tag: 'user-session',
data: {
userId: 'user_789',
details: {
username: 'jsmith',
email: 'jsmith@company.com',
role: 'admin',
plan: 'enterprise'
}
}
});
Different sessions for different flows
// Checkout flow session
const checkoutSession = await ductape.sessions.start({
product: 'marketplace',
env: 'prd',
tag: 'checkout-flow',
data: { userId: 'user_123', details: { cartId: 'cart_456' } }
});
// Support chat session
const supportSession = await ductape.sessions.start({
product: 'marketplace',
env: 'prd',
tag: 'support-chat',
data: { userId: 'user_123', details: { ticketId: 'ticket_789' } }
});
Response
{
"token": "ejyui11919102393:abc123xyz456...",
"refreshToken": "eueywuwjwmwmw:zyx456cba321..."
}
| Field | Description |
|---|---|
token | Short-lived token for the current session |
refreshToken | Long-lived token to refresh or resume sessions |
Best Practices
- Store tokens securely - Avoid exposing in logs or unencrypted storage
- Use different tags - Create separate sessions for different flows
- Include identifiers - Always provide a stable userId
Reference
Parameters
interface CreateSessionInput {
product: string;
env: string;
tag: string;
data: {
userId: string;
details: Record<string, unknown>;
};
}