Note: This section describes how the auto-generated code works on the Node.js platform and the TypeScript programming language. Reach out to us about examples for other platforms and programming languages.

The SDK exposes type-safe functions for every event in your team’s tracking plan. The function’s arguments correspond to the event’s properties and are strongly-typed.

By default, Itly will generate the tracking library in ./src/itly/index.ts. The index.ts TypeScript module will automatically initialize your analytics backend SDKs (including credentials) and export a usable instance of the library.

The code generated by Iteratively will import/include all SDKs for the analytics providers your team is using (e.g. Amplitude). 

To use the library, import it into any module that needs to track at least one event.

import itly from './itly';

First, initialize the Itly SDK once when your application starts. The init() method accepts an options object that lets you configure how the Itly SDK works:

  • context can be a typed object that specifies the properties to add to every event, or a resolver function that is called whenever an event is tracked and returns a just-in-time created context object.
  • disabled specifies whether the Itly SDK does any work. When true, all calls to the Itly SDK will be no-ops. Useful in local or development environments.
  • environment specifies the environment the Itly SDK is running in: either production or development. In production, production analytics provider Access Tokens are used and validation errors log rather than throw. In development, development analytics provider Access Tokens are used and validation errors throw exceptions.
  • destinations specifies any analytics provider-specific configuration. The Itly SDK passes these objects in when initializing the underlying SDKs.

For example:

Then, call the event’s function.

itly.trackSomeEvent({ prop: value });

Itly includes code docs in the auto-generated library so your IDE can display relevant documentation for every function and property as you type.

Because TypeScript is a type-safe language, TypeScript itself will warn you if the arguments you pass to your track function are of the wrong type. This will not happen with type-unsafe languages (e.g. JavaScript), but in those cases, the auto-generated library will perform those checks at runtime.