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(...)。