Node.js product analytics installation

  1. Install

    Required

    Install the PostHog Node.js library using your package manager:

    npm install posthog-node
  2. Configure

    Required

    Initialize the PostHog client with your project API key:

    Node.js
    import { PostHog } from 'posthog-node'
    const client = new PostHog(
    '<ph_project_api_key>',
    {
    host: 'https://us.i.posthog.com'
    }
    )
  3. Send an event

    Capture events with properties:

    Node.js
    client.capture({
    distinctId: 'distinct_id_of_the_user',
    event: 'event_name',
    properties: {
    property1: 'value',
    property2: 'value',
    },
    })

    By default, for backwards compatibility reasons, events are sent with person profile processing enabled. This means a person profile will be created for each user who triggers an event.

    If you want to disable person profile processing for certain events, send the event with the following property:

    Node.js
    "$process_person_profile": false

Community questions

Was this page useful?

Questions about this page? or post a community question.