npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@clicsdev/sdk

v0.0.24

Published

TypeScript SDK for the Clics analytics API

Downloads

692

Readme

@clicsdev/sdk

TypeScript SDK for the Clics analytics API.

License: MIT

Summary

Clics privacy-first web analytics platform: Server-side REST API for Clics privacy-friendly web analytics: manage projects, goals, funnels, sessions, and query stats.

Table of Contents

SDK Installation

The SDK can be installed with either npm, pnpm, bun or yarn package managers.

NPM

npm add @clicsdev/sdk

PNPM

pnpm add @clicsdev/sdk

Bun

bun add @clicsdev/sdk

Yarn

yarn add @clicsdev/sdk

[!NOTE] This package is published as an ES Module (ESM) only. For applications using CommonJS, use await import("@clicsdev/sdk") to import and use this package.

Requirements

This SDK is intended to be used in JavaScript runtimes that support ECMAScript 2020 or newer. The SDK uses the following features:

Runtime environments that are explicitly supported are:

  • Evergreen browsers which include: Chrome, Safari, Edge, Firefox
  • Node.js active and maintenance LTS releases
    • Currently, this is v18 and v20
  • Bun v1 and above
  • Deno v1.39
    • Note that Deno does not currently have native support for streaming file uploads backed by the filesystem (issue link)

Recommended TypeScript compiler options

The following tsconfig.json options are recommended for projects using this SDK in order to get static type support for features like async iterables, streams and fetch-related APIs (for await...of, AbortSignal, Request, Response and so on):

{
  "compilerOptions": {
    "target": "es2020", // or higher
    "lib": ["es2020", "dom", "dom.iterable"]
  }
}

While target can be set to older ECMAScript versions, it may result in extra, unnecessary compatibility code being generated if you are not targeting old runtimes.

SDK Example Usage

Example

import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.stats.queryStats({
    projectId: "k17abc123",
    domain: "example.com",
    timezone: "Europe/London",
    metrics: [
      "visitors",
      "pageviews",
      "bounce_rate",
    ],
    dateRange: "last7days",
    dimensions: [
      "visit:country",
    ],
    filters: [
      [
        "is",
        "visit:country",
        [
          "US",
          "FR",
        ],
      ],
    ],
    orderBy: [
      [
        "visitors",
        "desc",
      ],
    ],
  });

  console.log(result);
}

run();

Authentication

To authenticate with the API the apiKey parameter must be set when initializing the SDK client instance. For example:

import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.stats.queryStats({
    projectId: "k17abc123",
    domain: "example.com",
    timezone: "Europe/London",
    metrics: [
      "visitors",
      "pageviews",
      "bounce_rate",
    ],
    dateRange: "last7days",
    dimensions: [
      "visit:country",
    ],
    filters: [
      [
        "is",
        "visit:country",
        [
          "US",
          "FR",
        ],
      ],
    ],
    orderBy: [
      [
        "visitors",
        "desc",
      ],
    ],
  });

  console.log(result);
}

run();

Available Resources and Operations

Funnels

Funnel analysis

listFunnels

List project conversion funnels.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.funnels.listFunnels({
    projectId: "k17abc123",
    cursor: "eyJwayI6InByb2pfMSJ9",
    limit: 20,
  });

  console.log(result);
}

run();

Optional: envId, cursor, limit

createFunnel

Create a multistep funnel.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.funnels.createFunnel({
    projectId: "k17abc123",
    body: {
      name: "Checkout",
      conversionWindow: {
        value: 7,
        unit: "days",
      },
      steps: [
        {
          name: "Cart",
          filters: [
            {
              filterType: "page",
              operator: "is",
              values: [
                "/cart",
              ],
            },
          ],
        },
        {
          name: "Purchase",
          filters: [
            {
              filterType: "page",
              operator: "is",
              values: [
                "/thanks",
              ],
            },
          ],
        },
      ],
    },
  });

  console.log(result);
}

run();

Optional: envId

getFunnel

Fetch one funnel by ID.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.funnels.getFunnel({
    funnelId: "funnel_1",
  });

  console.log(result);
}

run();

updateFunnel

Partially update an existing funnel. Unspecified fields are preserved.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.funnels.updateFunnel({
    funnelId: "funnel_1",
    body: {
      name: "Updated checkout",
    },
  });

  console.log(result);
}

run();

Optional: name, conversionWindow, steps

deleteFunnel

Delete an existing funnel.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.funnels.deleteFunnel({
    funnelId: "funnel_1",
  });

  console.log(result);
}

run();

getFunnelStats

Return the same step counts, conversion, drop-off, and timing metrics as the Funnel dashboard.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.funnels.getFunnelStats({
    funnelId: "funnel_1",
  });

  console.log(result);
}

run();

Optional: domain, dateRange, start, end, timezone, referrerAiProvider

Goals

Conversion goals

listGoals

List project conversion goals.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.goals.listGoals({
    projectId: "k17abc123",
  });

  console.log(result);
}

run();

Optional: envId

createGoal

Create a page, event, outbound-link, or scroll-depth goal.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.goals.createGoal({
    projectId: "k17abc123",
    body: {
      goalType: "page",
      rule: {
        pagePath: "/signup",
      },
      envId: "production",
      displayName: "Signup",
    },
  });

  console.log(result);
}

run();

getGoalStats

Return goal totals, previous-period comparison, and a time series. Supports all four goal types.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.goals.getGoalStats({
    goalId: "goal_1",
  });

  console.log(result);
}

run();

Optional: domain, dateRange, start, end, timezone, referrerAiProvider

getGoal

Fetch one Goal, including its type-specific rule.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.goals.getGoal({
    goalId: "goal_1",
  });

  console.log(result);
}

run();

updateGoal

Update an existing goal.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.goals.updateGoal({
    goalId: "goal_1",
    body: {
      rule: {
        pagePath: "/thank-you",
      },
    },
  });

  console.log(result);
}

run();

Optional: displayName, goalType, rule

deleteGoal

Delete an existing goal.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.goals.deleteGoal({
    goalId: "goal_1",
  });

  console.log(result);
}

run();

Projects

Project management

listProjects

List workspace projects.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.projects.listProjects({
    cursor: "eyJwayI6InByb2pfMSJ9",
    limit: 20,
  });

  console.log(result);
}

run();

Optional: cursor, limit

createProject

Create a tracked website project.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.projects.createProject({
    name: "Acme Marketing",
    websiteUrl: "example.com",
    allowLocalhost: false,
  });

  console.log(result);
}

run();

Optional: allowLocalhost

getProject

Fetch one project by ID.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.projects.getProject({
    projectId: "k17abc123",
  });

  console.log(result);
}

run();

updateProject

Update project name or domain.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.projects.updateProject({
    projectId: "k17abc123",
    body: {
      name: "Acme Marketing",
      websiteUrl: "example.com",
      allowLocalhost: true,
    },
  });

  console.log(result);
}

run();

Optional: name, websiteUrl, allowLocalhost

deleteProject

Permanently delete a project.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.projects.deleteProject({
    projectId: "k17abc123",
  });

  console.log(result);
}

run();

Sessions

Visitor session list, detail, and events

listSessions

List paginated visitor sessions. Supports the same period presets as /v1/query, optional domain scoping, and cursor pagination.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.sessions.listSessions({
    projectId: "k17abc123",
    domain: "example.com",
    dateRange: "last7days",
    start: "2026-07-01",
    end: "2026-07-24",
    timezone: "Europe/London",
    countryOp: "is",
    deviceOp: "is",
    browserOp: "is",
    osOp: "is",
    pageEntryOp: "is",
    pageExitOp: "is",
    referrerOp: "is",
    cursor: "eyJ2IjoxLCJza2lwIjoxMH0",
    limit: 20,
  });

  console.log(result);
}

run();

Optional: domain, dateRange, start, end, timezone, country, countryOp, device, deviceOp, browser, browserOp, os, osOp, pageEntry, pageEntryOp, pageExit, pageExitOp, referrer, referrerOp, cursor, limit

listSessionFilterValues

Return available values and their session/pageview counts in the same filtered session scope. The requested field's own filter is excluded so a client can populate its picker.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.sessions.listSessionFilterValues({
    projectId: "k17abc123",
    domain: "example.com",
    dateRange: "last7days",
    start: "2026-07-01",
    end: "2026-07-24",
    timezone: "Europe/London",
    field: "referrer",
    countryOp: "is",
    deviceOp: "is",
    browserOp: "is",
    osOp: "is",
    pageEntryOp: "is",
    pageExitOp: "is",
    referrerOp: "is",
    limit: 50,
  });

  console.log(result);
}

run();

Optional: domain, dateRange, start, end, timezone, country, countryOp, device, deviceOp, browser, browserOp, os, osOp, pageEntry, pageEntryOp, pageExit, pageExitOp, referrer, referrerOp, limit

getSession

Get a single visitor session with UTM metadata and visited pages.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.sessions.getSession({
    projectId: "k17abc123",
    sessionId: "sess_abc123",
    domain: "example.com",
    dateRange: "last7days",
    start: "2026-07-01",
    end: "2026-07-24",
    timezone: "Europe/London",
  });

  console.log(result);
}

run();

Optional: domain, dateRange, start, end, timezone

listSessionEvents

List the chronological event timeline for a session.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.sessions.listSessionEvents({
    projectId: "k17abc123",
    sessionId: "sess_abc123",
    domain: "example.com",
    dateRange: "last7days",
    start: "2026-07-01",
    end: "2026-07-24",
    timezone: "Europe/London",
  });

  console.log(result);
}

run();

Optional: domain, dateRange, start, end, timezone

Stats

Analytics query endpoints

queryStats

Query metrics and dimensions. For KPI queries with include.previous_period enabled, the response includes comparison with previous-period values and percentage changes.

Example Usage
import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.stats.queryStats({
    projectId: "k17abc123",
    domain: "example.com",
    timezone: "Europe/London",
    metrics: [
      "visitors",
      "pageviews",
      "bounce_rate",
    ],
    dateRange: "last7days",
    dimensions: [
      "visit:country",
    ],
    filters: [
      [
        "is",
        "visit:country",
        [
          "US",
          "FR",
        ],
      ],
    ],
    orderBy: [
      [
        "visitors",
        "desc",
      ],
    ],
  });

  console.log(result);
}

run();

Optional: domain, timezone, dimensions, filters, orderBy, include, pagination

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply provide a retryConfig object to the call:

import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.stats.queryStats({
    projectId: "k17abc123",
    domain: "example.com",
    timezone: "Europe/London",
    metrics: [
      "visitors",
      "pageviews",
      "bounce_rate",
    ],
    dateRange: "last7days",
    dimensions: [
      "visit:country",
    ],
    filters: [
      [
        "is",
        "visit:country",
        [
          "US",
          "FR",
        ],
      ],
    ],
    orderBy: [
      [
        "visitors",
        "desc",
      ],
    ],
  }, {
    retries: {
      strategy: "backoff",
      backoff: {
        initialInterval: 1,
        maxInterval: 50,
        exponent: 1.1,
        maxElapsedTime: 100,
      },
      retryConnectionErrors: false,
    },
  });

  console.log(result);
}

run();

If you'd like to override the default retry strategy for all operations that support retries, you can provide a retryConfig at SDK initialization:

import { Clics } from "@clicsdev/sdk";

const clics = new Clics({
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  const result = await clics.stats.queryStats({
    projectId: "k17abc123",
    domain: "example.com",
    timezone: "Europe/London",
    metrics: [
      "visitors",
      "pageviews",
      "bounce_rate",
    ],
    dateRange: "last7days",
    dimensions: [
      "visit:country",
    ],
    filters: [
      [
        "is",
        "visit:country",
        [
          "US",
          "FR",
        ],
      ],
    ],
    orderBy: [
      [
        "visitors",
        "desc",
      ],
    ],
  });

  console.log(result);
}

run();

Error Handling

ClicsError is the base class for all HTTP error responses. It has the following properties:

| Property | Type | Description | | ------------------- | ---------- | --------------------------------------------------------------------------------------- | | error.message | string | Error message | | error.statusCode | number | HTTP response status code eg 404 | | error.headers | Headers | HTTP response headers | | error.body | string | HTTP body. Can be empty string if no body is returned. | | error.rawResponse | Response | Raw HTTP response | | error.data$ | | Optional. Some errors may contain structured data. See Error Classes. |

Example

import { Clics } from "@clicsdev/sdk";
import * as errors from "@clicsdev/sdk/models/errors";

const clics = new Clics({
  apiKey: process.env["CLICS_API_KEY"] ?? "",
});

async function run() {
  try {
    const result = await clics.stats.queryStats({
      projectId: "k17abc123",
      domain: "example.com",
      timezone: "Europe/London",
      metrics: [
        "visitors",
        "pageviews",
        "bounce_rate",
      ],
      dateRange: "last7days",
      dimensions: [
        "visit:country",
      ],
      filters: [
        [
          "is",
          "visit:country",
          [
            "US",
            "FR",
          ],
        ],
      ],
      orderBy: [
        [
          "visitors",
          "desc",
        ],
      ],
    });

    console.log(result);
  } catch (error) {
    // The base class for HTTP error responses
    if (error instanceof errors.ClicsError) {
      console.log(error.message);
      console.log(error.statusCode);
      console.log(error.body);
      console.log(error.headers);

      // Depending on the method different errors may be thrown
      if (error instanceof errors.QueryStatsBadRequestError) {
        console.log(error.data$.error); // operations.QueryStatsError
      }
    }
  }
}

run();

Error Classes

Primary error:

  • ClicsError: The base class for HTTP error responses.

Network errors:

Inherit from ClicsError:

* Check the method documentation to see if the error is applicable.

Debugging

You can setup your SDK to emit debug logs for SDK requests and responses.

You can pass a logger that matches console's interface as an SDK option.

[!WARNING] Beware that debug logging will reveal secrets, like API tokens in headers, in log messages printed to a console or files. It's recommended to use this feature only during local development and not in production.

import { Clics } from "@clicsdev/sdk";

const sdk = new Clics({ debugLogger: console });

You can also enable a default debug logger by setting an environment variable CLICS_DEBUG to true.