Skip to content

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 ​

  1. Make a client with a secret key of your server source. Keep the key in your secret store:

    ts
    import { createClient } from '@quickpipeaiab/lead-scoring';
    
    const lg = createClient({ key: process.env.LEAD_SCORING_KEY! });
  2. Give the person with as, then send the event:

    ts
    lg.as({ email: '[email protected]' }).track('invoice.paid', { amount: 1200 });
  3. To send the IP address of the visitor, add it as the second argument:

    ts
    lg.as({ userId: 'u_1842' }, { ip: request.ip }).track('trial.started');
  4. Before the process stops, send the last batch:

    ts
    await 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- or lg-sec-test-.
  • Never put a secret key in a browser. The client does not start in a browser with a secret key.