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

@masivo/client

v1.0.1

Published

Official Masivo SDK for event tracking and customer engagement

Downloads

177

Readme

@masivo/client

Official Masivo SDK for web applications — event tracking and customer engagement in browser environments.

Important: This SDK requires a CLIENT API key. Do not use SERVER API keys — they will be rejected and the SDK will warn you about exposed server credentials. Create a CLIENT key in the Masivo dashboard.

React Native / mobile app? Use @masivo/rn instead — it includes push notification and in-app messaging support without any browser dependencies.

Installation

npm install @masivo/client
pnpm add @masivo/client
yarn add @masivo/client

Quick Start

import { createClient } from "@masivo/client";

const masivo = createClient({ apiKey: "your-client-api-key" });

await masivo.sendAnalyticsEvent({
  type: "ADD_TO_CART",
  customer_id: "customer-123",
  brand_id: "brand-456",
  product: {
    sku: "SKU-001",
    amount: 1,
    value: 29.99
  }
});

Events are automatically flushed when the browser tab is hidden or the page is unloaded, so no events are lost on navigation.

Events are sent on the analytics path: they feed tracking, journeys, and related flows without applying behavioral or punch-card loyalty rewards from the browser. Use your backend with a SERVER key when you need full loyalty campaign execution.

What this package adds over @masivo/core

@masivo/client is a thin wrapper around @masivo/core that registers two browser lifecycle listeners:

  • pagehide — flushes buffered events when the user navigates away.
  • visibilitychange (hidden) — flushes buffered events when the tab goes to background.

Both listeners are registered only if window and document exist, so the package is safe to import in SSR environments (Next.js, Remix, etc.) without throwing errors.

Allowed Event Types

This SDK uses CLIENT API keys, which can only emit:

  • Tracking eventsADD_TO_CART, EMPTY_CART, and other tracking types.
  • Custom event types — Any custom event type you have created in the Masivo platform.

Default event types like PURCHASE, ABANDONED_CART, BIRTHDAY, REGISTRATION, and TIER_ADJUSTMENT are not allowed from the client SDK. These must be sent from your backend using a SERVER API key directly via the Masivo REST API.

API

createClient(config)

Creates a new Masivo client instance. All core functionality (auth, batching, token refresh) comes from @masivo/core.

| Parameter | Type | Required | Description | | --- | --- | --- | --- | | config.apiKey | string | Yes | Your Masivo CLIENT API key | | config.brandId | string \| null | No | Default brand ID injected into events that have a platform but no explicit brand_id |

Returns a MasivoClient:

client.sendAnalyticsEvent(event)

Sends an event to Masivo on the analytics path.

| Field | Type | Required | Description | | --- | --- | --- | --- | | type | string | Yes | Event type (e.g. ADD_TO_CART, custom type) | | customer_id | string | Yes | External customer identifier | | brand_id | string \| null | Yes | Brand identifier, null if not applicable | | ...rest | unknown | No | Any additional event data |

Returns Promise<SendEventResult>:

{
  success: boolean;
  status: number;
  data: unknown;
}

client.flush()

Forces an immediate send of all buffered events.

await masivo.flush();

client.destroy()

Stops the background token refresh and clears internal state. Call this on logout.

masivo.destroy();

Error Handling

All error classes are re-exported from @masivo/core:

import { createClient, MasivoError, MasivoServerKeyError, MasivoAuthError, MasivoNetworkError } from "@masivo/client";

const masivo = createClient({ apiKey: "your-client-api-key" });

try {
  await masivo.sendAnalyticsEvent({
    type: "ADD_TO_CART",
    customer_id: "customer-123",
    brand_id: null
  });
} catch (error) {
  if (error instanceof MasivoServerKeyError) {
    console.error(error.message);
  } else if (error instanceof MasivoNetworkError) {
    console.error("Network error:", error.message);
  } else if (error instanceof MasivoAuthError) {
    console.error("Auth error:", error.message, error.details);
  } else if (error instanceof MasivoError) {
    console.error("API error:", error.status, error.message);
  }
}

| Error class | When | Properties | | --- | --- | --- | | MasivoServerKeyError | SERVER API key used instead of CLIENT | message | | MasivoNetworkError | Fetch fails (no connectivity, DNS, etc.) | message | | MasivoAuthError | Authorization fails (invalid/expired key) | message, status, details | | MasivoError | API returns an error response | message, status, details |

Usage with Next.js

// lib/masivo.ts
import { createClient } from "@masivo/client";

// Initialize once — safe to import in client components
export const masivo = createClient({ 
  apiKey: process.env.NEXT_PUBLIC_MASIVO_CLIENT_KEY!,
  brandId: process.env.NEXT_PUBLIC_MASIVO_BRAND_ID  // optional
});
// In a client component
"use client";
import { masivo } from "@/lib/masivo";

masivo.sendAnalyticsEvent({
  type: "ADD_TO_CART",
  customer_id: session.user.id,
  brand_id: null,
  product: { sku, value }
});

Batching Behavior

Events are queued and sent in bulk:

| Trigger | Condition | | --- | --- | | Queue size | Flush when 100 events are queued | | Idle | Flush after 30 seconds with no new events | | Max wait | Flush after 60 seconds regardless of activity | | Page hide | Flush automatically on navigation/tab close | | Visibility hidden | Flush automatically when tab goes to background | | Manual | Call client.flush() to send immediately |

Compatibility

  • Browsers (built-in fetch)
  • Node.js >= 18 — SSR safe, browser listeners are skipped
  • React Native — safe to import but use @masivo/rn for the full mobile experience

Zero external dependencies.

Links

License

MIT