> ## Documentation Index
> Fetch the complete documentation index at: https://docs.saytics.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Install the Saytics JavaScript or Node.js SDK

> Install and configure the Saytics JavaScript SDK or server-side library. Covers npm, CDN, and Node.js setup with initialization options.

This page covers how to install Saytics in two environments: as a browser JavaScript library for client-side tracking, and as a Node.js library for server-side event collection. Choose the tab that matches your setup — many teams use both.

<Tabs>
  <Tab title="Browser">
    Install the Saytics JavaScript SDK with npm:

    ```bash theme={null}
    npm install @saytics/js
    ```

    Alternatively, load Saytics from the CDN by adding this script tag to your HTML `<head>`. The `async` attribute prevents the script from blocking page rendering.

    ```html theme={null}
    <script
      async
      src="https://cdn.saytics.com/saytics.min.js"
      data-key="YOUR_WRITE_KEY"
    ></script>
    ```

    Once installed, initialize the SDK with your write key. Pass an optional configuration object as the second argument to customize behavior.

    ```js theme={null}
    import Saytics from '@saytics/js';

    Saytics.init('YOUR_WRITE_KEY', {
      debug: false,
      batchSize: 10,
    });
    ```
  </Tab>

  <Tab title="Node.js">
    Install the Saytics Node.js library with npm:

    ```bash theme={null}
    npm install @saytics/node
    ```

    Import or require the library, then create a client instance with your write key. Use the instance to send events from your server.

    ```js theme={null}
    // ES module
    import Saytics from '@saytics/node';

    // CommonJS
    const Saytics = require('@saytics/node');

    const saytics = new Saytics('YOUR_WRITE_KEY');
    ```

    You can then call `saytics.track()` from any server-side handler or background job.
  </Tab>
</Tabs>

## Configuration options

Pass these options as the second argument to `Saytics.init()` (browser) or the constructor options object (Node.js).

<ParamField path="writeKey" type="string" required>
  Your project's write key from **Settings → API Keys**. Required to authenticate all events.
</ParamField>

<ParamField path="debug" type="boolean" default="false">
  Enable console logging for every event sent and any SDK errors. Useful during development. Disable in production.
</ParamField>

<ParamField path="apiHost" type="string">
  Override the default API endpoint. Use this if you're proxying Saytics traffic through your own domain.
</ParamField>

<ParamField path="batchSize" type="number" default="10">
  Number of events to accumulate before flushing to the API in a single request. Reducing this value sends events more frequently; increasing it reduces network requests.
</ParamField>

<Info>
  Use your write key (not secret key) for client-side code. The write key is safe to expose in browser environments.
</Info>

## Next steps

* [Quick start guide](/quickstart) — send your first event end-to-end
* [JavaScript SDK reference](/tracking/javascript) — all available methods and advanced options
