Angulartics2: startTracking() does not exist on type 'Angulartics2GoogleAnalytics'

1.1k views Asked by At

I've followed the instructions on the readme of Angulartics2 for Google Analytics:

app.module.ts:

import { Angulartics2Module } from 'angulartics2';
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
...
imports: [Angulartics2Module.forRoot([Angulartics2GoogleAnalytics])

app.component.ts

import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
...
constructor(
    angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics
) {
    angulartics2GoogleAnalytics.startTracking();
}

angulartics2GoogleAnalytics.startTracking() throws an error though: Angulartics2: startTracking() does not exist on type 'Angulartics2GoogleAnalytics'.

Can anyone tell me why? I'm using Angular 5.2.8.

2

There are 2 answers

0
user3255061 On

Turns out RXJS 6.0.0 is required: https://github.com/angulartics/angulartics2/issues/266. I believe using RXJS 5 causes angulartics2/ga not to be found, hence the error mentioned in my question.

0
angularconsulting.au On

I had the same issue myself by looking in to some new docs but then I just figure out there is no startTracking() in the sources https://github.com/angulartics/angulartics2/blob/master/src/lib/providers/ga/ga.ts

Also see this https://github.com/angulartics/angulartics2/wiki/Google-Analytics

export class AppComponent {
  constructor(angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics) {}
}

UPDATE: the startTracking() exists on the next branch through, added 6 days ago. The next branch does not released as a new version yet so the package version you are getting from npm does not contain any new code from the next branch.