NgRx
该插件允许你捕获 NgRx 的 actions/state,并在稍后回放会话录制时进行检查。这对于理解和修复问题非常有用。
npm i @openreplay/tracker-ngrx --save
将生成的 meta-reducer 添加到你的 imports 中。更多详情请参阅 NgRx 文档。
如果你的网站是单页应用程序(SPA)
Section titled 如果你的网站是单页应用程序(SPA)import { StoreModule } from '@ngrx/store';
import OpenReplay from '@openreplay/tracker';
import trackerNgRx from '@openreplay/tracker-ngrx';
//...
const tracker = new OpenReplay({
projectKey: PROJECT_KEY
});
const metaReducers = [tracker.use(trackerNgRx(<options>))]; // check list of available options below
tracker.start();
//...
@NgModule({
imports: [StoreModule.forRoot({}, { metaReducers })]
})
export class AppModule {}
如果你的 Web 应用采用服务端渲染(SSR)
Section titled 如果你的 Web 应用采用服务端渲染(SSR)如果你的应用采用 SSR,请参照下面的示例。确保 tracker.start() 在应用启动后被调用(在 useEffect 或 componentDidMount 中)。
import { StoreModule } from '@ngrx/store';
import OpenReplay from '@openreplay/tracker/cjs';
import trackerNgRx from '@openreplay/tracker-ngrx/cjs';
//...
const tracker = new OpenReplay({
projectKey: PROJECT_KEY
});
const metaReducers = [tracker.use(trackerNgRx(<options>))]; // check list of available options below
//...
@NgModule({
imports: [StoreModule.forRoot({}, { metaReducers })]
})
export class AppModule {}
}
你可以自定义中间件的行为来净化你的数据。
trackerNgRx({
actionFilter: action => action.type !== 'DRAW', // only actions which pass this test will be recorded
actionTransformer: action => action.type === 'LOGIN' ? null : action,
actionType: action => action.type // action type for search, that's the default one
stateTransformer: state => {
const { jwt, ..._state } = state;
return _state;
},
})