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

@mira-network/mira-data-stream

v0.1.0

Published

JavaScript SDK for Mira Data Stream analytics and event tracking

Readme

Mira Data Stream JavaScript SDK

A lightweight, flexible SDK for tracking events, page views, and user identities in web applications.

Installation

npm install mira-data-stream

Usage

Basic Usage

import { track, identify, page, setWriteKey } from 'mira-data-stream';

// Set your authentication write key (required)
// You can get this from the Mira Data Stream Producer API when creating a service
setWriteKey('your-write-key-here');

// Track an event
track('button_clicked', { 
  button_id: 'signup',
  page: 'landing' 
});

// Identify a user
identify('user123', {
  name: 'John Doe',
  email: '[email protected]'
});

// Track page view
page('home');

Advanced Usage

You can create a custom instance with specific configuration:

import { init } from 'mira-data-stream';

const analytics = init({
  apiUrl: 'https://api.example.com/tracking',
  writeKey: 'your-write-key-here', // Required for authentication
  flushInterval: 5000 // 5 seconds
});

// Use the custom instance
analytics.track('custom_event', {
  property1: 'value1',
  property2: 'value2'
});

Usage in React

import { useEffect } from 'react';
import { page, track, setWriteKey } from 'mira-data-stream';

function MyComponent() {
  useEffect(() => {
    // Set write key for authentication
    setWriteKey('your-write-key-here');
    
    // Track page view when component mounts
    page('my-component');
  }, []);

  const handleClick = () => {
    track('button_clicked', {
      component: 'MyComponent'
    });
  };

  return (
    <div>
      <h1>My Component</h1>
      <button onClick={handleClick}>Click Me</button>
    </div>
  );
}

API Reference

Functions

  • track(eventName, properties, options) - Track an event
  • identify(userId, traits) - Identify a user
  • page(name, properties, options) - Track a page view
  • setWriteKey(writeKey) - Set the write key for authentication with the server
  • flush() - Manually flush the event queue
  • reset() - Reset user identity
  • init(options) - Initialize a new SDK instance with custom options

Options

  • apiUrl - API URL for the Mira Data Stream Backend (default: 'http://localhost:8000/api/v1')
  • userId - User ID for identifying the current user
  • anonymousId - Anonymous ID for tracking non-logged-in users (auto-generated if not provided)
  • writeKey - Write key for authentication with the server (required)
  • flushInterval - Interval in milliseconds for flushing the event queue (default: 10000)

Authentication

The Mira Data Stream requires a write key for authentication. Each write key corresponds to a specific service in the backend.

To get a write key:

  1. Create a service through the Mira Data Stream Producer API
  2. Use the write key provided by the API in your SDK initialization
// Set the write key for authentication
setWriteKey('your-write-key-here');

// Or when initializing a new instance
const analytics = init({
  writeKey: 'your-write-key-here'
});

Browser Support

The SDK works in all modern browsers that support the Fetch API (Chrome, Firefox, Safari, Edge). For older browsers, you may need to include a polyfill for the Fetch API.

Development

If you want to contribute to this SDK, see the PUBLISHING.md file for development setup, testing, and publication instructions.

# Install dependencies
npm install

# Run tests
npm test

# Build the SDK
npm run build

License

MIT