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

@grainql/analytics-web

v3.4.2

Published

Lightweight TypeScript SDK for sending analytics events and managing remote configurations via Grain's REST API

Readme


For browser analytics with heatmaps, snapshots, and consent management, use @grainql/tag instead. This SDK is the right choice when you need remote configuration or need to send events from servers and non-browser environments.

Installation

npm install @grainql/analytics-web

Quick Start

Server-Side / Node.js

import { createGrainAnalytics } from '@grainql/analytics-web';

const grain = createGrainAnalytics({
  tenantId: 'your-tenant-id',
  authStrategy: 'SERVER_SIDE',
  secretKey: 'your-secret-key',
});

// Track server-side events
grain.track('order_completed', {
  order_id: 'ORD-123',
  total: 149.99,
  currency: 'USD',
});

// Track with an explicit user ID
grain.trackForUser('user-456', 'subscription_renewed', {
  plan: 'pro',
  period: 'annual',
});

// Flush before process exit
await grain.flush();

Remote Configuration

import { createGrainAnalytics } from '@grainql/analytics-web';

const grain = createGrainAnalytics({ tenantId: 'your-tenant-id' });

// Fetch remote config from Grain dashboard
await grain.fetchConfig();

// Read values
const heroText = grain.getConfig('hero_text');
const featureEnabled = grain.getConfig('new_feature') === 'true';

// Get all configs with fallback defaults
const allConfigs = grain.getAllConfigs();

// Listen for config changes
grain.onConfigChange((configs) => {
  console.log('Config updated:', configs);
});

React (Remote Config Hooks)

import { GrainProvider, useConfig, useTrack } from '@grainql/analytics-web/react';

function App() {
  return (
    <GrainProvider config={{ tenantId: 'your-tenant-id' }}>
      <HomePage />
    </GrainProvider>
  );
}

function HomePage() {
  const { value: heroText } = useConfig('hero_text');
  const track = useTrack();

  return (
    <div>
      <h1>{heroText || 'Welcome!'}</h1>
      <button onClick={() => track('cta_clicked')}>Get Started</button>
    </div>
  );
}

Configuration

createGrainAnalytics({
  tenantId: 'your-tenant-id',             // Required
  apiUrl: 'https://clientapis.grainql.com', // Default
  debug: false,                            // Enable debug logging
  // Authentication
  authStrategy: 'NONE',                   // 'NONE' | 'SERVER_SIDE' | 'JWT'
  secretKey: undefined,                    // For SERVER_SIDE auth
  authProvider: undefined,                 // For JWT auth
  // Batching
  batchSize: 50,                           // Events per batch
  flushInterval: 5000,                     // Flush interval in ms
  retryAttempts: 3,                        // Retry attempts on failure
  // Remote Config
  defaultConfigurations: {},               // Fallback values
  configRefreshInterval: 300000,           // Auto-refresh (5 min default)
  enableConfigCache: true,                 // Cache configs locally
  // Privacy
  consentMode: 'cookieless',              // 'cookieless' | 'gdpr-strict' | 'gdpr-opt-out'
});

API Reference

Event Tracking

grain.track(eventName, properties?)                // Track with current user
grain.trackForUser(userId, eventName, properties?) // Track with explicit user
grain.flush()                                      // Flush pending events

Identity

grain.setUserId(userId)              // Set user identity
grain.getUserId()                    // Get current user ID
grain.getDeviceId()                  // Get device ID
grain.getSessionId()                 // Get session ID

Remote Configuration

grain.fetchConfig(options?)          // Fetch configs from API
grain.getConfig(key)                 // Get a single config value
grain.getAllConfigs()                 // Get all configs with defaults
grain.onConfigChange(callback)       // Listen for config changes

Consent

grain.grantConsent(categories?)      // Grant consent
grain.revokeConsent()                // Revoke consent
grain.hasConsent()                   // Check consent status

Lifecycle

grain.destroy()                      // Flush and cleanup

When to Use Which SDK

| Use Case | SDK | |----------|-----| | Browser analytics, heatmaps, snapshots | @grainql/tag | | Script tag delivery (Cloudflare Workers) | @grainql/tag | | Remote configuration | @grainql/analytics-web | | Server-side event tracking (Node.js) | @grainql/analytics-web | | React config hooks (useConfig) | @grainql/analytics-web/react | | Non-browser runtimes | @grainql/analytics-web |

License

MIT