我正在尝试将我的prject与mixpanel集成以进行分析。我正在使用Angularatics2Module来达到这个目的。我已经通过以下方式在我的app.module.ts中导入了angularatics2Module和mixpanel:
import { Angulartics2Module, Angulartics2GoogleAnalytics } from 'angulartics2';
import mixpanel from 'mixpanel-browser/src/loader-module';
@NgModule({
imports: [
....
AppRoutingModule,
Angulartics2Module.forRoot([mixpanel])
],
declarations: [
...
],
providers: [
..
],
bootstrap: [
AppComponent
]
})
export class AppModule {
}
我还在index.html中添加了以下脚本
<!-- start Mixpanel --><script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("myprojecttoken");</script><!-- end Mixpanel -->
在我的组件中,我导入了Angularatics2Module,我按照以下方式跟踪事件:
在.ts文件中:
import { Angulartics2Module } from 'angulartics2';
in .html:
<button angulartics2On="click" angularticsEvent="Signup Click" angularticsCategory="Signup" [angularticsProperties]="{label: 'Signup'}" class="btns md-button" (click)="goToConnect()">Sign Up</button>
<button angulartics2On="click" angularticsEvent="Login Click" angularticsCategory="Login" [angularticsProperties]="{label: 'Login'}" class="btns md-button" (click)="goToLogin()">Log In</button>
但我收到以下错误:
mixpanel-core.js:1512 Uncaught TypeError: Cannot read property 'name' of undefined
at MixpanelLib.get_config (mixpanel-core.js:1512)
at MixpanelLib.toString (mixpanel-core.js:1538)
at stringify (core.es5.js:155)
at stringifyType (compiler.es5.js:14686)
at compiler.es5.js:14396
at Array.reduce (<anonymous>)
at compiler.es5.js:14391
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (compiler.es5.js:14373)
at compiler.es5.js:13950
at Array.forEach (<anonymous>)
at CompileMetadataResolver.getNgModuleMetadata (compiler.es5.js:13941)
at JitCompiler._loadModules (compiler.es5.js:25043)
at JitCompiler._compileModuleAndComponents (compiler.es5.js:25002)
at JitCompiler.compileModuleAsync (compiler.es5.js:24964)
请指导我做错的地方。感谢。