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): Callsanalytics.page(path).eventTrack(action, properties): Callsanalytics.track(action, properties).setUserProperties(properties): Callsanalytics.identify(userId, traits)whereuserIdis extracted from the properties object.setAlias(alias): Callsanalytics.alias(alias).