Provider: Segment

Setup

1. Add Segment Snippet

Add the analytics.js tracking code provided by Segment to your index.html file.

2. Configure Angulartics2

In your root component (e.g., app.component.ts), inject Angulartics2Segment and call startTracking().

import { Component } from '@angular/core';
import { Angulartics2Segment } from 'angulartics2';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
  constructor(angulartics2Segment: Angulartics2Segment) {
    angulartics2Segment.startTracking();
  }
}

This will activate automatic page tracking and enable other tracking methods for Segment.

Specific Segment Features

Angulartics2 maps its core API to Segment's analytics.js methods:

  • pageTrack(path): Calls analytics.page(path).
  • eventTrack(action, properties): Calls analytics.track(action, properties).
  • setUserProperties(properties): Calls analytics.identify(userId, traits) where userId is extracted from the properties object.
  • setAlias(alias): Calls analytics.alias(alias).