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.0.4

Published

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

Downloads

1,111

Readme

Grain Analytics Web SDK

A lightweight, dependency-free TypeScript SDK for privacy-first analytics and remote configuration management.

npm version Bundle Size

🆕 What's New in v3.0

🔒 Privacy-First by Default:

  • Cookieless - No tracking cookies, daily rotating IDs
  • GDPR Compliant - Cookieless mode requires no consent
  • No IP Storage - GeoIP data only (country, region, city)
  • Query Params Stripped - Privacy-first URL tracking
  • Three Consent Modes - Choose your privacy level

🚨 Breaking Changes: This is a major version with breaking changes. See BREAKING_CHANGES.md and MIGRATION_GUIDE_V2.md.

Features

  • 🔒 Privacy-First - Cookieless by default, GDPR compliant
  • 🚀 Zero dependencies - ~7KB gzipped
  • 📦 Automatic batching - Efficient event delivery
  • 🔄 Retry logic - Reliable with exponential backoff
  • 🎯 TypeScript first - Full type safety
  • ⚙️ Remote Config - Dynamic app control without deployments
  • ⚛️ React Hooks - Seamless React integration
  • 📱 Cross-platform - Browser, Node.js, React Native

Installation

NPM

npm install @grainql/analytics-web

CDN (IIFE)

<!-- Load from CDN -->
<script src="https://cdn.jsdelivr.net/npm/@grainql/analytics-web@latest/dist/index.global.js"></script>

<script>
  // Available as window.Grain
  const grain = window.Grain.createGrainAnalytics({
    tenantId: 'your-tenant-id'
  });
  
  grain.track('page_view', { page: window.location.pathname });
</script>

Quick Start

Vanilla JavaScript/TypeScript

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

// Cookieless by default (no consent needed)
const grain = createGrainAnalytics({
  tenantId: 'your-tenant-id',
  consentMode: 'cookieless', // Default: daily rotating IDs
});

// Track events
grain.track('page_viewed', { page: '/home' });

// Get remote config
const heroText = grain.getConfig('hero_text');

For GDPR Strict (with consent management):

const grain = createGrainAnalytics({
  tenantId: 'your-tenant-id',
  consentMode: 'gdpr-strict', // Requires consent for permanent IDs
  waitForConsent: true, // Queue events until consent granted
});

// Show consent banner
if (!grain.hasConsent()) {
  // Show your consent UI
  showConsentBanner({
    onAccept: () => grain.grantConsent(['analytics']),
    onReject: () => grain.revokeConsent(),
  });
}

React

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>
  );
}

Documentation

For comprehensive guides, API reference, and examples, visit our documentation:

📚 Full Documentation

Key Topics

Key Concepts

Event Tracking

Track user actions with automatic batching and retry logic:

grain.track('button_clicked', { button: 'signup' });
await grain.trackPurchase({ orderId: '123', total: 99.99 });

Remote Configuration

Control your app dynamically without code deployments:

const featureEnabled = grain.getConfig('new_feature');
if (featureEnabled === 'true') {
  // Show feature
}

User Identification

Track users across sessions:

grain.setUserId('user_123');
await grain.setProperty({ plan: 'premium' });

Tracks: Journey Visualization

Track user journeys from start to goal to unlock path visualization:

// 1. Define meaningful event names for your journey
grain.track('signup_started', { source: 'homepage' });
grain.track('email_entered', { valid: true });
grain.track('password_created', { strength: 'strong' });
grain.track('signup_completed', { method: 'email' });

// 2. In the dashboard, create a Track:
//    - Start event: 'signup_started'
//    - Goal event: 'signup_completed'
//    - The system will automatically visualize all paths between them

// 3. Best practices for Tracks:
//    - Use consistent event naming (snake_case recommended)
//    - Track intermediate steps (not just start/end)
//    - Add properties to segment paths (e.g., source, device_type)
//    - Exclude noise: heartbeat events are filtered automatically

What you'll see in Tracks:

  • Conversion paths: Most common routes users take to reach the goal
  • Drop-off paths: Where users abandon the journey
  • Hub nodes: Critical events many paths flow through
  • Metrics: Conversion rate, time-to-goal, abandonment points

More Examples

Check the examples directory for:

  • Vanilla JavaScript usage
  • React integration
  • Next.js setup
  • E-commerce tracking
  • Authentication flows

Contributing

We welcome contributions! Please see our contributing guidelines for more details.

License

MIT © Grain Analytics

Support