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

@earnalliance/node

v0.0.14

Published

Official Earn Alliance SDK for Node.js

Downloads

82

Readme

npm version Test Discord

Official Earn Alliance SDKs for NodeJS

This is the Earn Alliance NodeJS SDK.

Links

  • Discord
  • Twitter Follow

Contents

Installation and Usage

To install a SDK, simply add the package, for example:

npm install --save @earnalliance/node
yarn add @earnalliance/node

Initialize

Setup client so it can start sending events!

// CJS syntax
const Alliance = require('@earnalliance/node');
// ESM syntax
import * as Alliance from '@earnalliance/node';

const alliance = Alliance.init({
  clientId: '[client id]',
  clientSecret: '[client secret]',
  gameId: '[game id]',

  // Optional
  dsn: '...',
});

The client configuration can also be read from environment variables if not provided as an option.

// If the client id, secret, game id and dsn are not specific, the init
// function will by default look for the environment variables
// `ALLIANCE_CLIENT_ID`, `ALLIANCE_CLIENT_SECRET`, `ALLIANCE_GAME_ID` and
// `ALLIANCE_DSN`.
const alliance = Alliance.init();

Set User Identifiers

Whenever a new user identifier is set, or a new user is registered, you can add or update the identifiers associated with the internal user id.

This is used to tell us the user has installed the app and enrich information when more game platform accounts or social accounts are added to help us map the user to the game events.

// This shows all of our currently supported platforms, but you only need to
// provide the identifiers that are relevant for your game.
alliance.setUserIdentifiers('[internal user id]', {
  'appleId': '...'
  'discordId': '...',
  'email': '[email protected]',
  'epicGamesId': '...',
  'steamId': '...',
  'twitterId': '...',
  'walletAddress': '0x00.00',
});

Note that if you pass any falsey value identifier to setUserIdentifiers, it will be ignored. This is the avoid unintentionally removing previously set identifiers. If you want to remove previously set identifiers, use the removeUserIdentifiers function.

alliance.removeUserIdentifiers('[internal user id]', ['steamId', 'appleId']);

Track User Start Session

Sends standard TRACK event for launching a game. This let's us know that the user has the game launched and is ready to start a challenge.

alliance.startGame('[internal user id]');

Track Events

Tracking events that happens in a game. Tracked events are batched together and sent after 30 seconds interval, or when a batch size of 100 events have accumulated, whichever comes first. Both the interval and the batch size are configurable in the client options.

The name of the events can be almost anything, but we recommend sticking to common terms as shown in the following examples.

// An event without any specific value, commonly used for counting event
// instances, i.e. "Kill X Zombies".
alliance.track('[internal user id]', 'KILL_ZOMBIE');

// An event with an associated value, commonly used for accumulating or
// checking min / max values, i.e. "Score a total of X" or "Achieve a
// highscore of at least X".
alliance.track('[internal user id]', 'SCORE', 100);

// The client can track events for multiple users in parallel.
alliance.track('[internal user id]', 'DAMAGE_DONE', 500);
alliance.track('[another user id]', 'DAMAGE_TAKEN', 500);

// Additional traits can be added to the event, which can be used to
// create more detailed challenges, i.e. "Kill X monsters with a knife".
alliance.track('[internal user id]', 'KILL', { weapon: 'knife', mob: 'zombie' });

Group Tracked Events

You can group events together, i.e. a game round or a match, whichever makes sense for your game. This allows for natural challenge scopes like "Kill X players in a match".

// Generates unique group id which will be associated with all the events
const round = alliance.startRound();
round.track('[internal user id]', 'KILL_ZOMBIE');

// Additional traits can be set when starting the round, which will be added
// to all events that are tracked for the specific round.
const round = alliance.startRound({ map: 'nuclear_wasteland' });
round.track('[internal user id]', 'KILL_ZOMBIE');

Flush event queue

For events that have higher priority (i.e. setUserIdentifiers), instead of initiating a scheduled batch, they trigger the use of an event queue flush. This means that as long as the client has not been flushed prior to the event, the event will be sent to the api right away.

Once the queue has been has been flushed, the client enters a 10 second cooldown period, during which any subsequent calls to flush, will wait for the cooldown to finish, before it's triggered. Not that any normal procedures, like the queue size reaches the batch limit, will still send the events to the api.

The flush function can also be called manually on the client instance, but it is still restricted by the same cooldown mechanic.

alliance.flush();