Pinia
此插件允许你捕获 Pinia 的变更/状态,并在稍后回放会话录制时进行检查。这对于理解和修复问题非常有用。
npm i @openreplay/tracker-vuex
像往常一样初始化 @openreplay/tracker 包并将插件加载到其中。调用该插件并设置 store 名称,这将返回一个带名称的 store 跟踪器实例,你可以将你的 store 实例作为参数来调用它,以启用对该 store 的跟踪。
如果你的网站是单页应用程序 (SPA)
Section titled 如果你的网站是单页应用程序 (SPA)import OpenReplay from '@openreplay/tracker';
import trackerVuex from '@openreplay/tracker-vuex';
如果你的 Web 应用是服务器端渲染 (SSR)
Section titled 如果你的 Web 应用是服务器端渲染 (SSR)import OpenReplay from '@openreplay/tracker/cjs';
import trackerVuex from '@openreplay/tracker-vuex/cjs';
跟踪 Pinia Store
Section titled 跟踪 Pinia Store
//...
import { tracker } from '@openreplay/tracker';
tracker.configure({
projectKey: 'YOUR_PROJECT_KEY',
ingestPoint: "https://openreplay.mydomain.com/ingest", // when dealing with the self-hosted version of OpenReplay
});
// ...
const examplePiniaStore = useExamplePiniaStore()
const vuexPlugin = tracker.use(trackerVuex(<options>)) // check list of available options below
const piniaStorePlugin = vuexPlugin('STORE NAME') // add a name to your store,
// optional (will be randomly generated otherwise)
piniaStorePlugin(examplePiniaStore) // start tracking state updates
// now you can use examplePiniaStore as usual pinia store (destructure values or return it as a whole etc)
你可以通过选项自定义插件的行为以净化你的数据。它们与标准 createLogger 插件的选项类似。
trackerVuex({
filter (mutation, state) {
// returns `true` if a mutation should be logged
// `mutation` is a `{ type, payload }`
return mutation.type !== "aBlacklistedMutation";
},
transformer (state) {
// transforms the state before logging it.
// for example return only a specific sub-tree
return state.subTree;
},
mutationTransformer (mutation) {
// mutations are logged in the format of `{ type, payload }`
// we can format it any way we want.
return mutation.type;
},
})
如果你想了解如何使用此插件在会话回放中捕获状态变化的实际示例,请查看我们在这里提供的详细教程。