Send server events
Send events from your server, for example when a payment succeeds. On a server, the client has no visitor, so you give the person of each event.
Procedure
Make a client with a secret key of your server source. Keep the key in your secret store:
tsimport { createClient } from '@quickpipeaiab/lead-scoring'; const lg = createClient({ key: process.env.LEAD_SCORING_KEY! });Give the person with
as, then send the event:tslg.as({ email: '[email protected]' }).track('invoice.paid', { amount: 1200 });To send the IP address of the visitor, add it as the second argument:
tslg.as({ userId: 'u_1842' }, { ip: request.ip }).track('trial.started');Before the process stops, send the last batch:
tsawait lg.flush();
Result
QuickPipe adds the event to the person. as also has identify, account and set.
Short tasks
In a short task, for example an edge function, use await using. The client sends the last batch at the end of the block:
ts
await using lg = createClient({ key: process.env.LEAD_SCORING_KEY! });
lg.as({ email: '[email protected]' }).track('invoice.paid', { amount: 1200 });Rules for secret keys
- A secret key starts with
lg-sec-live-orlg-sec-test-. - Never put a secret key in a browser. The client does not start in a browser with a secret key.