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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@datablit/datablit-js

v1.2.1

Published

Datablit JavaScript SDK for analytics, rules, and experiments

Readme

@datablit/datablit-js

A comprehensive JavaScript SDK for Datablit analytics, rules, and experiments.

Installation

npm install @datablit/datablit-js

Quick Start

import datablit from "@datablit/datablit-js";

// Initialize the SDK
await datablit.init({
  apiKey: "your-api-key-here",
});

// Track events
datablit.track("Button Clicked", { buttonId: "signup-button" });

// Identify users
datablit.identify("user123", { email: "[email protected]", plan: "premium" });

// Evaluate rules
const ruleResult = await datablit.rule.evalRule("fer", "1", {
  os_name: "android",
});

console.log("Rule result:", ruleResult); // true or false

// Get experiment variant
const variant = await datablit.experiment.getVariant(
  "01K2JKVXR0J0ZWPX40XY8CAWBS",
  "1"
);

console.log("Variant:", variant); // "control", "variant_a", etc.

Features

Analytics

  • Event Tracking: Track user interactions and custom events
  • User Identification: Associate events with specific users
  • Automatic Page Tracking: Automatically track page views
  • Batch Processing: Efficient event batching and retry logic
  • Offline Support: Events are queued locally when offline

Rules

  • Rule Evaluation: Evaluate rules against user context in real-time
  • Context-based Decisions: Make dynamic decisions based on user attributes

Experiments

  • A/B Testing: Get experiment variants for users
  • Context-aware Assignment: Assign variants based on user context
  • Statistical Analysis: Built-in support for experiment analysis

API Reference

Initialization

await datablit.init({
  apiKey: string,                    // Required: Your Datablit API key
  endpoint?: string,                 // Optional: Custom event endpoint
  batchSize?: number,               // Optional: Events per batch (default: 20)
  flushInterval?: number,           // Optional: Flush interval in ms (default: 30000)
  enablePageTracking?: boolean,     // Optional: Auto-track page views (default: false)
  apiBaseURL?: string              // Optional: Custom API base URL for rules/experiments
});

Analytics Methods

datablit.track(eventName, properties)

Track a custom event.

datablit.track("Purchase Completed", {
  productId: "prod_123",
  amount: 99.99,
  currency: "USD",
});

datablit.identify(userId, traits)

Identify a user with traits.

datablit.identify("user123", {
  email: "[email protected]",
  name: "John Doe",
  plan: "premium",
});

Rules API

Access rules functionality through datablit.rule:

datablit.rule.evalRule(key, userId, params?)

Evaluate a rule for a given user and context. Returns a boolean indicating the evaluation result.

const ruleResult = await datablit.rule.evalRule("fer", "1", {
  os_name: "android",
});

if (ruleResult) {
  console.log("Rule evaluated to true");
} else {
  console.log("Rule evaluated to false");
}

Experiments API

Access experiments functionality through datablit.experiment:

datablit.experiment.getVariant(expId, entityId)

Get experiment variant for a user. Returns the variant string assigned to the entity.

const variant = await datablit.experiment.getVariant(
  "01K2JKVXR0J0ZWPX40XY8CAWBS",
  "1"
);

console.log("User is in variant:", variant); // "control", "variant_a", etc.

Advanced Usage

Error Handling

The SDK provides comprehensive error handling:

try {
  const ruleResult = await datablit.rule.evalRule("fer", "1");
} catch (error) {
  console.error("Failed to evaluate rules:", error.message);
}

try {
  const variant = await datablit.experiment.getVariant(
    "01K2JKVXR0J0ZWPX40XY8CAWBS",
    "1"
  );
} catch (error) {
  console.error("Failed to get variant:", error.message);
}

try {
  datablit.track("Event", { data: "value" });
} catch (error) {
  console.error("Failed to track event:", error.message);
}

Architecture

The SDK is built with a modular architecture:

src/
├── index.ts          # Main entry point and exports
├── types.ts          # TypeScript type definitions
├── base-api.ts       # Base API class for HTTP requests
├── datablit.ts       # Main Datablit analytics class
├── rule.ts           # Rule evaluation functionality
└── experiment.ts     # Experiment variant assignment

Configuration

Endpoints

  • Analytics Events: https://event.datablit.com/v1/batch
  • Rules & Experiments: https://console.datablit.com/api/1.0/* (default)
    • Can be customized via apiBaseURL configuration

API Key Authentication

The API key is sent in the request headers:

  • Analytics: apiKey header
  • Rules/Experiments: apiKey header

Browser Support

The SDK supports all modern browsers and includes:

  • ES6+ features
  • Fetch API
  • LocalStorage
  • User Agent Data API (when available)

Development

Building

npm run build

Testing

npm test

License

MIT License - see LICENSE file for details.

Support

For support and questions, please contact [email protected] or visit our documentation at https://datablit.com/docs