Skip to content

Ampli

The Ampli CLI, Ampli Wrapper, and Amplitude SDK work together to generate a tracking library based on your Tracking Plan.

The autogenerated library, the Ampli Wrapper, is a lightweight wrapper over the Amplitude SDK that provides type-safety, supports linting, and enables features like input validation. The code replicates the spec in the Tracking Plan and enforces rules and requirements.

Tip

Visit the ampli-examples GitHub repo for example applications that use the Ampli Wrapper.

Ampli CLI

The Ampli CLI connects your codebase to your tracking plan. Each Source in your tracking plan represents a runtime in which you wish to generate a strongly typed Wrapper.

ampli pull logs in and downloads the Ampli Wrapper for your current tracking plan.

ampli status verifies implementation status of event tracking in your project.

Ampli Wrapper

The Ampli Wrapper is a dynamic, code-generated SDK. It has strong types for the events in your tracking plan, and provides autocomplete and static type checking.

ampli.songPlayed({ title: Song #1 })

The Ampli Wrapper is a light wrapper for untyped Amplitude SDKs.

Amplitude SDK

The Amplitude SDK is a static, open source SDK with untyped events.

amplitude.logEvent({ event_type: Song Played, event_properties: { title: Song #1 }})

The Ampli Wrapper runs on top of the Amplitude SDK. The client.instance is the Amplitude SDK client that makes the underlying calls to Amplitude. If you don't specify a client.instance, Ampli uses a default instance.

class Ampli {
  var client: AmplitudeClient;

  load(options) {
    // use provided AmplitudeCLient if available, default otherwise
    this.client = options.client.instance || Amplitude.getInstance().init(...);
  }

  // track method wraps Amplitude SDK's logEvent()
  track(event: Event) {
    // use the Amplitude client to logEvents to the server
    this.client.logEvent(event.eventType, event.eventProperties);
  }

  // strongly typed event method wraps "generic" track
  myEvent(properties: MyEventProperties) {
    this.track(new MyEvent(properties));
  }
}

You can override the default client configuration with client.options.


Last update: 2022-08-10