@@ -363,18 +363,20 @@ Track events from server actions:
363363import { Outlit } from '@outlit/node'
364364
365365const outlit = new Outlit({
366- privateKey : process.env.OUTLIT_PRIVATE_KEY !
366+ publicKey : process.env.OUTLIT_KEY !
367367})
368368
369369export async function trackServerEvent(userId: string) {
370- await outlit.track({
371- visitorId: userId,
372- event : 'server_action_completed',
370+ outlit.track({
371+ userId,
372+ eventName : 'server_action_completed',
373373 properties: {
374374 action: 'data_export',
375375 timestamp: new Date().toISOString()
376376 }
377377 })
378+
379+ await outlit.flush()
378380}
379381` ` `
380382
@@ -392,18 +394,20 @@ import { NextResponse } from 'next/server'
392394import { Outlit } from '@outlit/node'
393395
394396const outlit = new Outlit({
395- privateKey : process.env.OUTLIT_PRIVATE_KEY !
397+ publicKey : process.env.OUTLIT_KEY !
396398})
397399
398400export async function POST(request: Request) {
399401 const { userId, amount } = await request.json()
400402
401- await outlit.track({
402- visitorId: userId,
403- event : 'checkout_completed',
403+ outlit.track({
404+ userId,
405+ eventName : 'checkout_completed',
404406 properties: { amount }
405407 })
406408
409+ await outlit.flush()
410+
407411 return NextResponse.json({ success: true })
408412}
409413` ` `
@@ -437,12 +441,12 @@ Set up your environment variables:
437441# Public key (used in browser)
438442NEXT_PUBLIC_OUTLIT_KEY=pk_your_public_key_here
439443
440- # Private key (used in server actions/API routes)
441- OUTLIT_PRIVATE_KEY=sk_your_private_key_here
444+ # Server key (used in server actions/API routes)
445+ OUTLIT_KEY=pk_your_public_key_here
442446` ` `
443447
444448<Warning >
445- Never expose your private key in client - side code . Only use it in server components , API routes , or server actions .
449+ Keep server environment variables out of client - side code . Only use ` OUTLIT_KEY ` in server components , API routes , or server actions .
446450< / Warning >
447451
448452## TypeScript Support
0 commit comments