@segment/integration-sdk

:mountain_cableway:Framework for building safe and reliable Segment integrations

Usage no npm install needed!

<script type="module">
  import segmentIntegrationSdk from 'https://cdn.skypack.dev/@segment/integration-sdk';
</script>

README

Introduction

The Segment Integration SDK is a framework designed to help developers build reliable integrations with Segment. Integrations built using this tool are consumers of Segment events, contrary to upstream producers of Segment events. To learn how to send events to Segment, visit our docs.

Quick Start

Installation

With yarn:

yarn add @segment/integration-sdk

With npm:

npm i --save @segment/integration-sdk

Basic Usage

// index.ts
import { Integration } from '@segment/integration-sdk'
import { Track, Identify, OrderCompleted } from '@segment/spec-ts'

interface Settings {}

export class MyIntegration extends Integration {
  constructor(public settings: Settings) {
    super()
    this.subscribe('track', this.track)
    this.subscribe('identify', this.identify)
    this.subscribe('Order Completed', this.orderCompleted)
  }

  async track(event: Track) {
    console.log('Track event handled...')
  }

  async identify(event: Identify) {
    console.log('Identify event handled...')
  }

  async orderCompleted(event: OrderCompleted) {
    console.log(event.properties.revenue)
  }
}

Examples

You can find a simple examples in the /examples directory.