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

@swaarm/swaarm-web-sdk

v1.0.4

Published

SDK that allows developers to easily connect and send events to a Swaarm platform

Downloads

8

Readme

Swaarm SDK

The Swaarm SDK is an attribution and measurement SDK that enables interaction with the Swaarm platform through a simple API.

Installation

You can include the SDK in your project by either:

  1. Adding dist/swaarm-web-sdk.min.js to your HTML page.

  2. Installing it via npm:

    Swaarm SDK on npm

Configuration

To configure the Swaarm SDK, initialize it using:

SwaarmSdk.initialize("example.swaarm.com", "<token>");

Replace "example.swaarm.com" with your Swaarm tracking domain and "<token>" with your specific access token.

Optional Parameters:

  • Callback: Invoked once initialization completes.
  • Attribution Callback: Invoked when attribution data is available (see Attribution Data).
  • Event Interval: Time (in seconds) between sending events to the server.
  • Debug Mode: Enables additional logging.

Example:

SwaarmSdk.initialize(
    "https://my-tracking-domain",
    "my-token",
    () => console.log("Initialization finished"),
    (attributionData) => console.log("Attribution data available", attributionData),
    2,  // Event interval in seconds
    true // Debug mode enabled
);

Usage

Registering the User for Attribution

To register the user for attribution on landing pages, use:

SwaarmSdk.land();

Sending Custom Events

Use the event method to track user actions.

Parameters:

  • typeId (string, required) – Type of event (e.g., "registration").
  • aggregatedValue (number, optional) – Value aggregated in reports (e.g., number of items purchased).
  • customValue (string, optional) – Free-form string value for event details.
  • revenue (number, optional) – Monetary value associated with the event.
  • currency (string, optional) – Currency for the revenue value.

Example:

SwaarmSdk.event(
  'registration',
  25.0,
  '{"email": "[email protected]"}'
);

Attribution Data

The Swaarm SDK periodically contacts the server to retrieve attribution data until valid data is received.

Retrieving Attribution Data

To get the currently available attribution data:

SwaarmSdk.getAttributionData();

Registering an Attribution Callback

You can register a callback function to be invoked when successful attribution happens:

SwaarmSdk.initialize(
    "https://my-tracking-domain",
    "my-token",
    () => console.log("Initialization finished"),
    (attributionData) => console.log("Attribution data available", attributionData),
    2,
    true
);

Attribution Data Schema

UML Diagram

+------------------------------------+
|   AttributionData                  |
+------------------------------------+
| - offer: AttributionOffer?         |
| - publisher: AttributionPublisher? |
| - ids: Ids?                        |
| - decision: PostbackDecision?      |
+------------------------------------+
        |
        |------------------> +-------------------------+
                             |   AttributionOffer      |
                             +-------------------------+
                             | - id: String?           |
                             | - name: String?         |
                             | - lpId: String?         |
                             | - campaignId: String?   |
                             | - campaignName: String? |
                             | - adGroupId: String?    |
                             | - adGroupName: String?  |
                             | - adId: String?         |
                             | - adName: String?       |
                             +-------------------------+

        |------------------> +-----------------------+
                             |  AttributionPublisher |
                             +-----------------------+
                             | - id: String?         |
                             | - name: String?       |
                             | - subId: String?      |
                             | - subSubId: String?   |
                             | - site: String?       |
                             | - placement: String?  |
                             | - creative: String?   |
                             | - app: String?        |
                             | - appId: String?      |
                             | - unique1: String?    |
                             | - unique2: String?    |
                             | - unique3: String?    |
                             | - groupId: String?    |
                             +-----------------------+

        |------------------> +----------------------+
                             |       Ids            |
                             +----------------------+
                             | - installId: String? |
                             | - clickId: String?   |
                             | - userId: String?    |
                             +----------------------+

        |------------------> +-----------------------+
                             |   PostbackDecision    |
                             +-----------------------+
                             | - passed              |
                             | - failed              |
                             +-----------------------+

Class: AttributionData

Contains details about the offer, publisher, IDs, and postback decision.

Fields:

  • offer (AttributionOffer?) – Offer information.
  • publisher (AttributionPublisher?) – Publisher details.
  • ids (Ids?) – Attribution identifiers.
  • decision (PostbackDecision?) – Attribution decision (passed or failed).

Class: AttributionOffer

Holds details about the offer involved in the attribution.

Fields:

  • id – Offer ID.
  • name – Offer name.
  • lpId – Landing page ID.
  • campaignId – Campaign ID.
  • campaignName – Campaign name.
  • adGroupId – Ad group ID.
  • adGroupName – Ad group name.
  • adId – Ad ID.
  • adName – Ad name.

Class: AttributionPublisher

Holds details about the publisher responsible for serving the offer.

Fields:

  • id – Publisher ID.
  • name – Publisher name.
  • subId – Tracking sub-identifier.
  • subSubId – Secondary tracking sub-identifier.
  • site – Website where the ad was displayed.
  • placement – Ad placement location.
  • creative – Ad creative.
  • app – Application where the ad appeared.
  • appId – Application ID.
  • unique1, unique2, unique3 – Unique tracking identifiers.
  • groupId – External publisher ID (e.g., CRM, anti-fraud tool).

Class: Ids

Contains identifiers related to the attribution process.

Fields:

  • installId – App installation ID.
  • clickId – Click event ID.
  • userId – User ID.

Enum: PostbackDecision

Represents possible postback outcomes.

Values:

  • passed – Postback succeeded.
  • failed – Postback failed.

Assigning Application-Specific User IDs

To associate in-app users with SDK users, use:

SwaarmSdk.associateUserId("in-app-user-id");

This will enable the SDK to distinguish between sessions created by different users, and sessions created by the same user across different devices.