@newageerp/node-ab-tool
v1.0.18
Published
``` npm install @newageerp/node-ab-tool@latest ```
Downloads
195
Readme
INSTALL
npm install @newageerp/node-ab-tool@latest
IMPLEMENT
middleware.ts
const abTestResp = await abDataNextSrv.checkForRoutes(
req,
`PROJECT_AB_KEY`, // todayistheday-ab, wingmanx-ab...
{
homePageTemplate: HomePageEnum,
quizPageTemplate: QuizPageEnum,
emailPageTemplate: EmailPageEnum,
resultPageTemplate: ResultPageEnum,
checkoutPageTemplate: CheckoutPageEnum,
upsellPageTemplate: UpsellPageEnum,
},
AbToolVariableEnums
)
if (abTestResp) {
return abTestResp
}
Upsell methods
Config example
Simple flow
import { UpSellConfigType } from '@newageerp/node-ab-tool'
export const UpConfig: UpSellConfigType = {
[UpsellPageEnum.enum.Default]: [
'profile-secrets',
'dating-secrets',
'unlimited',
]
}
AB test flow
import { UpSellConfigType } from '@newageerp/node-ab-tool'
export const UpConfig: UpSellConfigType = {
[UpsellPageEnum.enum.Default_AbTest]: [
[
{
slug: 'profile-secrets',
percent: 50,
},
{
slug: 'profile-secrets-b',
percent: 50,
},
],
'dating-secrets',
'unlimited',
]
}
Get next slug by current slug
import { upSellNavigation } from '@newageerp/node-ab-tool'
const nextSlug = upSellNavigation.nextPathByConfigItemSlug(UpConfig, UpsellPageEnum.enum[upsellEnum], currentUpsell);
Get next slug by current index
import { upSellNavigation } from '@newageerp/node-ab-tool'
const nextSlug = upSellNavigation.nextPathByConfigItemIndex(UpConfig, abTool.flowData.upsellPageTemplate, -1)
AB test part
getSplitItemForReq usage
const input = await getSplitItemForReq({req, project});
if (input) {
const currentSplit = getSplitItemUrlWinner(input);
return NextResponse.redirect(
new URL(`/${trimChar(currentSplit.url, '/')}${req.nextUrl.search}`, req.url),
)
}
getSplitItemForPath usage
const input = await getSplitItemForPath({path: req.nextUrl.pathname, project});
if (input) {
const currentSplit = getSplitItemUrlWinner(input);
return NextResponse.redirect(
new URL(`/${trimChar(currentSplit.url, '/')}${req.nextUrl.search}`, req.url),
)
}