Avo Inspector Node.js SDK

Quick Start Guide

Find the Quick Start Guide in our GitHub repo.

Installation

The library is distributed with NPM, install with npm:

npm i node-avo-inspector

Import

import * as Inspector from "node-avo-inspector";

Initialization

Obtain the API key in Inspector tab in your Avo.app workspace.

You will need to create an instance of AvoInspector with the constructor:

constructor(options: {
    apiKey: string;
    env: AvoInspectorEnv;
    version: string;
    appName?: string;
    publicEncryptionKey?: string;
});

All the following methods are available in the AvoInspector class.

Parameters:

  • apiKey - the API key you get in your Avo account
  • env - current environment: "dev", "staging" or "prod"
  • appVersion - your application version. A lot of Inspector features rely on versioning and you need to provide a comparable string here to get value from them. We recommend using semantic versioning or integers that are incremented in every release.
  • appName - your application name. Optional; Provide it to make it easier to distinguish between data from different apps.
  • publicEncryptionKey - optional. Your hex-encoded P-256 public key for property value validation.

Property value validation

You can enable property value validation to validate property values against the constraints defined in your tracking plan, such as allowed values, regex patterns, and min/max ranges.

💡

Property value validation is available for version 1.2.0+ of the Node.js Inspector SDK. If you are using an older version, please update to the latest version.

To enable property value validation:

  1. Enable property value validation in settings - Go to workspace settings in your Avo workspace and enable property value validation.

To be able to decrypt the property values in the Inspector Debugger, you need to generate a public/private key pair:

Step 1: Generate encryption keys

Run the following command in your terminal to generate a public/private key pair:

node -e "const { createECDH } = require('crypto'); const ecdh = createECDH('prime256v1'); ecdh.generateKeys(); console.log('Private Key:', ecdh.getPrivateKey('hex')); console.log('Public Key:', ecdh.getPublicKey('hex', 'compressed'));"

This will output:

  • Public key - Used by Avo to encrypt property values
  • Private key - Used by you to decrypt values in the Inspector Debugger

Step 2: Store your private key securely

Save your private key in a secure location like a password manager. You’ll need this to decrypt values in the Inspector Debugger. Never share or expose your private key to a third party.

Step 3: Add the public key to the Inspector initialization

Pass the public key when initializing the AvoInspector instance:

const inspector = new Inspector.AvoInspector({
  apiKey: 'YOUR-API-KEY',
  env: 'dev',
  version: '1.0.0',
  appName: 'My App',
  publicEncryptionKey: 'YOUR-HEX-PUBLIC-KEY',
});
🔒

Property values are encrypted end-to-end. Avo only stores encrypted values and cannot decrypt them. Only you can decrypt the values using your private key in the Inspector Debugger dashboard.

Learn more about decrypting property values in the Inspector Debugger and the property value issue types that can be detected.

Sending event schemas to Avo Inspector

This is the core of the Avo Inspector SDK.

trackSchemaFromEvent(eventName: string, eventProperties: {
    [propName: string]: any;
}): void;

Parameters:

  • eventName - string event name, also known as event type.
  • eventProperties - The actual event properties, which will be converted to an event schema on the device and the event schema sent to Avo. The resulting keys will be object field names and the values will be object field value types converted to schema types.
Example format:
var eventProperties = {
  userId: 1337,
  emailAddress: 'jane.doe@avo.app',
  key: 'value',
};

Configuring Logs

enableLogging controls printing of tracked event schemas and other helpful information to logcat. Enabled by default in development environments.

enableLogging(enable: boolean): void;

Parameters:

  • enable - boolean flag that sets whether Avo Inspector SDK will print logs .