@traveloka/core/abtest
Also see: /docs/guides/ab-test/
Traveloka A/B test module. It's used in withTravelokaApp (for the normal NextJS-based flow) and ABTestMiddleware (for the middleware-based flow). (You can search for ../abtest string in core to verify this.)
Unless you are using the middleware-based flow, A/B test treatment is calculated in the client-side to ensure the server res.
Important files
-
The main context file
packages/core/abtest/ABTestContext.tsx
-
Utilities
packages/core/abtest/useABTest.ts— Exposes A/B test data to the component (only for onenamespace). Also handles devtool override and tracking.fetchABTestConfig— called to fetch A/B test data (by the context AND the middleware).fetchExperimentConfig— called to fetch A/B test data from Experiment API
-
Special folders
packages/core/abtest/abtasty— third-party A/B testing script to load on your page (https://www.abtasty.com/)packages/core/abtest/abtestClient— interfaces thewwwrepo with@traveloka/abtest-client
How this module works
NextJS-based flow
withTravelokaAppinitializesABTestProvider, passingabTestNamespacesby reading the from thePage.abTestNamespacesproperty exposed by yourtPagecomponent.ABTestProviderprovides A/B test config data, which is null during server rendering.- On the client side,
useEffectis triggered and it fetches the actual A/B test data
Middleware-based flow
- See
packages/core/server/ABTestMiddleware.ts - It is only run on certain paths, so there is no performance penalty for the paths that do not use A/B testing.
Experiment API
- Use
fetchExperimentConfigto get experiment config - It requires
getServerSideProps