Skip to content

Commit 9c8b8d9

Browse files
committed
docs: refresh public API examples
1 parent 8693011 commit 9c8b8d9

6 files changed

Lines changed: 50 additions & 37 deletions

File tree

docs/tracking/browser/astro.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,23 @@ import type { APIRoute } from 'astro'
339339
import { Outlit } from '@outlit/node'
340340

341341
const outlit = new Outlit({
342-
privateKey: import.meta.env.OUTLIT_PRIVATE_KEY
342+
publicKey: import.meta.env.OUTLIT_KEY
343343
})
344344

345345
export const POST: APIRoute = async ({ request }) => {
346346
const body = await request.json()
347347

348-
await outlit.track({
349-
visitorId: body.userId,
350-
event: 'checkout_completed',
348+
outlit.track({
349+
userId: body.userId,
350+
eventName: 'checkout_completed',
351351
properties: {
352352
amount: body.amount,
353353
plan: body.plan
354354
}
355355
})
356356

357+
await outlit.flush()
358+
357359
return new Response(JSON.stringify({ success: true }), {
358360
status: 200,
359361
headers: { 'Content-Type': 'application/json' }
@@ -518,12 +520,12 @@ Configure environment variables:
518520
# Public key (used in browser)
519521
PUBLIC_OUTLIT_KEY=pk_your_public_key_here
520522

521-
# Private key (used in API routes)
522-
OUTLIT_PRIVATE_KEY=sk_your_private_key_here
523+
# Server key (used in API routes)
524+
OUTLIT_KEY=pk_your_public_key_here
523525
```
524526

525527
<Warning>
526-
Never expose your private key in client-side code. Only use it in API routes.
528+
Keep server environment variables out of client-side code. Only use `OUTLIT_KEY` in API routes.
527529
</Warning>
528530

529531
## TypeScript Support

docs/tracking/browser/nextjs.mdx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,18 +363,20 @@ Track events from server actions:
363363
import { Outlit } from '@outlit/node'
364364
365365
const outlit = new Outlit({
366-
privateKey: process.env.OUTLIT_PRIVATE_KEY!
366+
publicKey: process.env.OUTLIT_KEY!
367367
})
368368
369369
export 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'
392394
import { Outlit } from '@outlit/node'
393395
394396
const outlit = new Outlit({
395-
privateKey: process.env.OUTLIT_PRIVATE_KEY!
397+
publicKey: process.env.OUTLIT_KEY!
396398
})
397399
398400
export 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)
438442
NEXT_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

docs/tracking/browser/nuxt.mdx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,23 @@ Track events from server API routes:
297297
import { Outlit } from '@outlit/node'
298298

299299
const outlit = new Outlit({
300-
privateKey: process.env.OUTLIT_PRIVATE_KEY!
300+
publicKey: process.env.OUTLIT_KEY!
301301
})
302302

303303
export default defineEventHandler(async (event) => {
304304
const body = await readBody(event)
305305

306-
await outlit.track({
307-
visitorId: body.userId,
308-
event: 'checkout_completed',
306+
outlit.track({
307+
userId: body.userId,
308+
eventName: 'checkout_completed',
309309
properties: {
310310
amount: body.amount,
311311
plan: body.plan
312312
}
313313
})
314314

315+
await outlit.flush()
316+
315317
return { success: true }
316318
})
317319
```
@@ -405,12 +407,12 @@ Configure environment variables:
405407
# Public key (used in browser)
406408
NUXT_PUBLIC_OUTLIT_KEY=pk_your_public_key_here
407409

408-
# Private key (used in server API routes)
409-
OUTLIT_PRIVATE_KEY=sk_your_private_key_here
410+
# Server key (used in server API routes)
411+
OUTLIT_KEY=pk_your_public_key_here
410412
```
411413

412414
<Warning>
413-
Never expose your private key in client-side code. Only use it in server API routes.
415+
Keep server environment variables out of client-side code. Only use `OUTLIT_KEY` in server API routes.
414416
</Warning>
415417

416418
## TypeScript Support

docs/tracking/browser/react.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ function MyComponent() {
493493
</ParamField>
494494

495495
<ParamField path="customer" type="object">
496-
Customer billing methods namespace. Requires `customerId` or `stripeCustomerId`; public calls should use `customerId`:
496+
Customer billing methods namespace. Use `customerId` for public billing calls:
497497
- `customer.trialing(options)` - Mark account as trialing
498498
- `customer.paid(options)` - Mark account as paid
499499
- `customer.churned(options)` - Mark account as churned

docs/tracking/browser/sveltekit.mdx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ export const load: PageLoad = async ({ params, fetch }) => {
190190
method: 'POST',
191191
headers: { 'Content-Type': 'application/json' },
192192
body: JSON.stringify({
193-
event: 'product_viewed',
193+
eventName: 'product_viewed',
194+
userId: 'usr_123',
194195
properties: { productId: params.id }
195196
})
196197
})
@@ -208,21 +209,25 @@ Track events from API routes:
208209
import { json } from '@sveltejs/kit'
209210
import type { RequestHandler } from './$types'
210211
import { Outlit } from '@outlit/node'
211-
import { OUTLIT_PRIVATE_KEY } from '$env/static/private'
212+
import { OUTLIT_KEY } from '$env/static/private'
212213

213214
const outlit = new Outlit({
214-
privateKey: OUTLIT_PRIVATE_KEY
215+
publicKey: OUTLIT_KEY
215216
})
216217

217218
export const POST: RequestHandler = async ({ request }) => {
218-
const { event, properties, visitorId } = await request.json()
219+
const { eventName, properties, userId, email, customerId } = await request.json()
219220

220-
await outlit.track({
221-
visitorId,
222-
event,
221+
outlit.track({
222+
eventName,
223+
userId,
224+
email,
225+
customerId,
223226
properties
224227
})
225228

229+
await outlit.flush()
230+
226231
return json({ success: true })
227232
}
228233
```
@@ -412,12 +417,12 @@ Configure environment variables:
412417
# Public key (used in browser)
413418
PUBLIC_OUTLIT_KEY=pk_your_public_key_here
414419

415-
# Private key (used in server API routes)
416-
OUTLIT_PRIVATE_KEY=sk_your_private_key_here
420+
# Server key (used in server API routes)
421+
OUTLIT_KEY=pk_your_public_key_here
417422
```
418423

419424
<Warning>
420-
Never expose your private key in client-side code. Only use it in server-side API routes.
425+
Keep server environment variables out of client-side code. Only use `OUTLIT_KEY` in server-side API routes.
421426
</Warning>
422427

423428
## TypeScript Support

docs/tracking/browser/vue.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ const visitorId = getVisitorId()
325325
</ParamField>
326326

327327
<ParamField path="customer" type="object">
328-
Customer billing methods namespace. Requires `customerId` or `stripeCustomerId`; public calls should use `customerId`:
328+
Customer billing methods namespace. Use `customerId` for public billing calls:
329329
- `customer.trialing(options)` - Mark account as trialing
330330
- `customer.paid(options)` - Mark account as paid
331331
- `customer.churned(options)` - Mark account as churned

0 commit comments

Comments
 (0)