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

徘徊边缘 提交于 2019-12-11 21:57:36

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/51584799/angulartics2-starttracking-does-not-exist-on-type-angulartics2googleanalytic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!