Learn how to use Oppla’s Node.js client for server-side tracking
npm install @oppla/node # or yarn add @oppla/node
const Oppla = require('@oppla/node'); const oppla = new Oppla({ projectId: 'YOUR_PROJECT_ID', apiKey: 'YOUR_API_KEY' });
// Track a simple event await oppla.track({ event: 'Order Completed', userId: 'user_123', properties: { orderId: 'order_123', amount: 99.99 } }); // Track with additional context await oppla.track({ event: 'Payment Processed', userId: 'user_123', timestamp: new Date(), context: { ip: '192.168.1.1', userAgent: 'Mozilla/5.0...' }, properties: { paymentId: 'pay_123', amount: 99.99, currency: 'USD' } });
await oppla.identify({ userId: 'user_123', traits: { name: 'John Doe', email: 'john@example.com', plan: 'premium', signupDate: new Date() } });
await oppla.identify({ userId: 'user_123', traits: { lastLogin: new Date(), loginCount: 5 } });
await oppla.batch([ { event: 'Page Viewed', userId: 'user_123', properties: { path: '/products' } }, { event: 'Product Viewed', userId: 'user_123', properties: { productId: 'prod_123' } } ]);
await oppla.batch([ { identify: { userId: 'user_123', traits: { name: 'John Doe' } } }, { identify: { userId: 'user_456', traits: { name: 'Jane Smith' } } } ]);
try { await oppla.track({ event: 'Order Completed', userId: 'user_123' }); } catch (error) { console.error('Failed to track event:', error); // Handle specific error types if (error.code === 'RATE_LIMIT') { // Implement retry logic } }
Was this page helpful?