angular - 通用方法订阅 Ionic 模态框打开事件
我正在使用 Google Analytics 来跟踪用户在我的应用中访问的页面。
当我启动 GA 跟踪器时,我会订阅 app.viewDidEnter 事件。所以,每当用户进入一个新视图时,跟踪器都会捕捉到并注册它。而且我不需要逐个视图地检查代码,添加任何额外的代码。这是一种通用的方法。
public startTrackerWithId(trackerId: string) {
return this.ga.startTrackerWithId(trackerId)
.then(() => {
this.log.d("Google Analytics tracker started");
return this.ga.enableUncaughtExceptionReporting(true);
}).then(() => {
this.app.viewDidEnter.subscribe((enteredView: ViewController) => {
if(enteredView.component){
let viewName = enteredView.component.name;
this.log.d("Tracking view", viewName);
this.ga.trackView(viewName);
}else{
this.log.d("Not tracking view ", enteredView);
}
});
}).catch(e => {
this.log.w("Error starting GoogleAnalytics", e);
});
}
但这不包括模态窗口。 如果用户打开任何模态窗口,追踪器不会追踪任何内容。
我想知道是否有一种通用的方法来检测用户何时打开了模态窗口。类似于一个我可以订阅的事件,例如:modal.present().subscribe(...)。