Anura Docs

Anura SDK for Server-side JavaScript

The Anura SDK for server-side JavaScript simplifies using Anura Direct for developers. Allowing you to quickly get up and running with analyzing your traffic.

Getting Started

  1. Have an open active account with Anura - You can see more about Anura's offerings here.
  2. Minimum Requirements - To use the SDK, you will need Node >=18.
  3. Install the SDK - You can run the following command to install the SDK via npm:

    npm install @anuraio/anura-sdk

  4. View our Quick Examples to immediately begin using the SDK!

Quick Examples

Create the Anura Direct Client

import { AnuraDirect, AnuraClientError, AnuraServerError } from '@anuraio/anura-sdk'; // ES Module Import
const { AnuraDirect, AnuraClientError, AnuraServerError } = require('@anuraio/anura-sdk'); // CommonJS Import

const direct = new AnuraDirect('your-instance-id-value-here');

Set an element of additional data for Anura Direct

direct.addAdditionalData('1', 'your-data-value');

Update an element of additional data

// To update an element of additional data, simply add the element again but with a new value.
const indexToUpdate = '1';
direct.addAdditionalData(indexToUpdate, 'your-new-data-value');

Remove an element from additional data

const indexToRemove = '1';
direct.removeAdditionalData(indexToRemove);

Get a result from Anura Direct

(async function() {
  const direct = new AnuraDirect('your-instance-id');
  try {
    const result = await direct.getResult({
      ipAddress: 'visitors-ip-address',
      userAgent: 'visitors-user-agent', // optional
      app: 'visitors-app-package-id', // optional
      device: 'visitors-device-id', // optional
      source: 'your-source-value', // optional
      campaign: 'your-campaign-value', // optional
    });

    console.log(result);
  } catch (error) {
      if (error instanceof AnuraClientError) {
        // Handle 4XX responses here.
      } else if (error instanceof AnuraServerError) {
        // Handle 5XX responses here.
      } else {
        // Handle any other type of error thrown here.
      }
  }
})();

API Reference

AnuraDirect

Can get results from Anura Direct. These results are fetched using /direct.json API endpoint.

Methods

async getResult(options: GetResultOptions): Promise<DirectResult>

GetResultOptions Parameters:

Name Type Description Required
ipAddress string The IP address of your visitor. Both IPv4 & IPv6 addresses are supported. Yes
userAgent any The user agent string of your visitor.
app any The application package identifier of your visitor (when available.)
device any The device identifier of your visitor (when available.)
source any A variable, declared by you, to identify "source" traffic within Anura's dashboard interface.
campaign any A subset variable of "source," declared by you, to identify "campaign" traffic within Anura's dashboard interface.
addAdditionalData(key: string, value: string): void removeAdditionalData(key: string): void get instance(): string get additionalData(): Map<string, string> set instance(instance: string): void

DirectResult

The result upon a successful call to getResult() from the AnuraDirect client. It contains not only the result from Anura DIrect, but some other methods to help you use the result as well.

Methods

iSuspect(): boolean isNonSuspect(): boolean isMobile(): boolean get result(): string get mobile(): number|null get ruleSets(): string[]|null get invalidTrafficType(): string|null