1.1.2 • Published 11 months ago

sidelines-amplitude v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

sidelines-amplitude

This Node.js package enables the creation of multiple, distinct Amplitude instances for event tracking, differentiated by unique API keys. It's designed to integrate seamlessly into your projects, allowing for sophisticated event and session management tailored to individual company settings in Amplitude.

Features

  • Multiple Instances: Easily configure multiple Amplitude clients.
  • Customizable Options: Set session identifiers, timeouts, and more.
  • Enhanced Logging: Integrate with your existing logging system for better debug capabilities.
  • Bulk Event Handling: Efficiently manage event uploads within Amplitude's recommended limits.

Getting Started

Installation

Install using npm:

    npm install sidelines-amplitude
    

Or using yarn:

    yarn add sidelines-amplitude

Configuration

Require and configure the package in your Node.js application:

        const Amplitude = require('sidelines-amplitude');
        const amplitudeClient = new Amplitude({{apiKey, companyName, options}});

Multiple instances can be created for different api keys companyName should be exact spelled as the Amplitude settings> Organization settings> General> Organization

Options params (optional)

  • session_id_key ('user_id') - Let you associate events with a particular session identifier.
  • session_timeout (5 * 60) - The time each session exists on amplitude, renew every event send.
  • attribution_event_type ('CompanyName install') - Determine which event will be sent on the attribution.
  • with_logs (false) - If true the package will send messages to console.
  • logger_cb (null) - If you would like to connect the package to you logger.

How to use

Send event

Send single event to amplitude. event - Object.required. type - string 'event' / 'attribution' (default: 'event'). session - boolean - Weather if to use Amplitude sessions logic or not (default: false).

        await amplitudeClient.sendEvent({event, type, session})

Event schema

   user_id: string.required
   event_type: string.required
   event_properties: object.optional
   user_properties: object.optional
   root_properties: object.optional
   session_id: string || -1

Attribution event schema

   user_id: string.required,
   platform: string.required.lowercase(),
   user_properties: object.optional,
   android_id: string.optional,
   adid: string.required on android,
   idfa: string.required on IOS (on of idfa || idfv),
   idfv: string.required on IOS (on of idfa || idfv),
   time: number.optional

Send bulk events

Send events in bulks according to Amplitude's rate limits

"Limit your upload to 100 batches per second and 1000 events per second. You can batch events into an upload, but we recommend not sending more than 10 events per batch. Amplitude expects fewer than 100 batches per second, and the 1000 events per second limit still applies."

        await bulkSendEvents = async (events)

logger_cb

There is a option to add logger_cb on the amplitude instance options. Example:

        const Amplitude = require('sidelines-amplitude');
        const loggerCb = (logType, log) => logger[logType](log);
        const amplitudeClient = new Amplitude({{apiKey, companyName, options:{ logger_cb: loggerCb }}});

loggerCb Params:

    logType: info/ error
    log : {message, error}
1.1.2

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago