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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@wunderbar-network/mini-digital-sdk

v1.4.1

Published

SDK for back-end (Node) and front-end (TypeScript/JavaScript) applications, to send analytics events to Mini.Digital

Downloads

9

Readme

@wunderbar-network/mini-digital-sdk

CI

Library that provides an interface to capture analytics events, and send them to Mini Digital. This library can be used in either Node.js or browser-based TypeScript/JavaScript projects (including frameworks like React or Vue).

The SDK is natively built using TypeScript and the ESM module format, and it compiles to the ES2022 target. There is also backwards CommonJS compatibility provided.

Installation

To install the SDK, you can use npm or yarn. Run the following command:

npm install @wunderbar-network/mini-digital-sdk

or

yarn add @wunderbar-network/mini-digital-sdk

Usage

To send a quick Web (front-end) event using the Mini Digital SDK, do the following (TypeScript/ESM syntax):

// Import the library
import { type AnalyticsEvent, EventTrackingService } from "@wunderbar-network/mini-digital-sdk";

// Declare event
const event: AnalyticsEvent = {
  eventName: "my_first_mini_digital_event",
  eventCategory: "system_outcome_event",
  eventSource: "MyProject.EventTestingPlayground",
  anonymousUser: true,
};

// Send event!
EventTrackingService.postEvent(event);

See our API reference to get a deeper understanding of the event schema, and how to send events from different platforms (back-end, mobile, etc).

Sending events to the production endpoint assumes you have already created your project during the Mini Digital App onboarding process. You can always send events to the Mini Digital Event Sink / Sandbox running locally.

Using bundles inside pure HTML & JavaScript

When not using a package manager (such as npm or yarn), bundles for different module formats can also be directly referenced in client side code (within a <script> tag, or in a separate script file). They can be obtained either from the Mini Digital CDN, or be found in the lib/bundles folder by manually building this project.

Mini Digital provides bundles in two module formats that can be used inside client-side code:

  1. mini-digital-sdk.min.mjs - ES2015 Modules/ESM bundle for most modern browsers
  2. mini-digital-sdk.min.umd.js - Universal Module Definition/UMD bundle, primarily intended for older browsers or other environments

When referencing bundles from the Mini Digital CDN, the CDN URL is as follows:

https://cdn.mini.digital/lib/js/v1.4/mini-digital-sdk.min.mjs

The version in the CDN URL above is in the format v#MAJOR.#MINOR and will always give the latest published revision. Released versions can be seen on our GitHub releases page.

All of the bundles are minified (hence the .min in the file names), and source maps (attaching .map to the end of the file name) are also available.

Note: The SDK also provides a third module format (CommonJS/CJS), called mini-digital-sdk.min.cjs (and it is also available either via the CDN or from the lib/bundles folder). This bundle is primarily intended for backwards compatibility with older Node.js projects (using the require rather than import syntax), and cannot be used within Web Browsers without previously being converted to a "browser-friendly" version using tools such as webpack or browserify.

Using the ES2015 Modules/ESM bundle

The ESM bundle is recommended to be used whenever possible, as most modern browsers on desktop and mobile will come with ESM support. To reference the ESM bundle version of the SDK from the Mini Digital CDN and send an event, do the following:

<button type="button" id="myButton">Send Interaction Event</button>

<script type="module">
  // Import the ESM-compatible library from the CDN
  import { EventTrackingService } from "https://cdn.mini.digital/lib/js/v1.4/mini-digital-sdk.min.mjs";

  document.getElementById("myButton").addEventListener("click", () => {
    EventTrackingService.postEvent({
      eventName: "button_clicked",
      eventCategory: "interaction_event",
      eventSource: "MyHtmlPage.Button",
      anonymousUser: true,
    });
  });
</script>

Using the Universal Module Definition/UMD bundle

For older browsers, a UMD version of the bundle can also be used. To send the same event as above, while also referencing the UMD bundle version of the SDK from the Mini Digital CDN, do the following:

<button type="button" id="myButton">Send Interaction Event</button>

<!-- Import the UMD-compatible library from the CDN -->
<script type="text/javascript" src="https://cdn.mini.digital/lib/js/v1.4/mini-digital-sdk.min.umd.js" defer onload="afterLibraryLoaded()"></script>

<script type="text/javascript">
  // Function to execute after the UMD library has loaded
  function afterLibraryLoaded() {
    document.getElementById("myButton").addEventListener("click", () => {
      // The Mini Digital SDK "lives" in the global `window.MiniDigital` object
      window.MiniDigital.EventTrackingService.postEvent({
        eventName: "button_clicked",
        eventCategory: "interaction_event",
        eventSource: "MyHtmlPage.Button",
        anonymousUser: true,
      });
    });
  }
</script>

Config

By default, the config is set to send events to the production Mini Digital endpoint. If you wish to override the default Mini Digital URL (to point to e.g. a local testing instance), you can do so by overriding the config namespace variable:

import { EventTrackingConfig } from "@wunderbar-network/mini-digital-sdk";

// Override the default value
EventTrackingConfig.miniDigitalUrl = "http://localhost:3333/";

You can also choose to pause sending events (e.g. in your test suites/CI builds), or not use cookies (to store anonymous tracking IDs):

import { EventTrackingConfig } from "@wunderbar-network/mini-digital-sdk";

// Override the default value
EventTrackingConfig.pauseTracking = true;
EventTrackingConfig.useCookies = false;

See our API reference for the full list of configuration options.