Skip to content

Latest commit

 

History

History
 
 

segment

README.md

Segment logo

Segment

homepage: segment.com
docs: segment.com/docs/sources/website/analytics.js
import: import { NgxAnalyticsSegment } from 'ngx-analytics/segment';

Setup

  1. Add NgxAnalyticsModule to your root NgModule passing an array of providers to enable
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';

import { NgxAnalyticsModule } from 'ngx-analytics';
import { NgxAnalyticsSegment } from 'ngx-analytics/segment';

const ROUTES: Routes = [
  { path: '',      component: HomeComponent },
  { path: 'about', component: AboutComponent },
];

@NgModule({
  imports: [
    BrowserModule,
    RouterModule.forRoot(ROUTES),

    // added to imports
    NgxAnalyticsModule.forRoot([NgxAnalyticsSegment]),
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
  1. Required: Import your providers in the root component. This starts the tracking of route changes.
// component
import { NgxAnalyticsSegment } from 'ngx-analytics/segment';

@Component({  ...  })
export class AppComponent {
  constructor(ngx-analyticsSegment: NgxAnalyticsSegment) {}
}