``` npm install @newageerp/node-ab-tool@latest ```
npm install @newageerp/node-ab-tool```
npm install @newageerp/node-ab-tool@latest
* ABTOOL_PROJECT - get value from manager, examples
* todayistheday-ab
* todayistheday-fr-ab
* wingmanx-ab
* ...
`typescript
import { abDataNextSrv } from '@newageerp/node-ab-tool'
const abTestResp = await abDataNextSrv.checkForRoutes(
req,
${process.env.ABTOOL_PROJECT},
{
homePageTemplate: HomePageEnum,
quizPageTemplate: QuizPageEnum,
emailPageTemplate: EmailPageEnum,
resultPageTemplate: ResultPageEnum,
checkoutPageTemplate: CheckoutPageEnum,
upsellPageTemplate: UpsellPageEnum,
},
AbToolVariableEnums
)
if (abTestResp) {
return abTestResp
}
export const config = {
matcher: '/((?!_next/static|_next/image|favicon.ico).*)',
}
`
`typescript
import { UpSellConfigType } from '@newageerp/node-ab-tool'
export const UpConfig: UpSellConfigType = {
}
`
here example for one upsell a/b test support, templates a/b test support and important analytics event
`typescript
useEffect(() => {
const initializePage = async () => {
const template = upSellTemplatesSplit.getTemplate(
UpConfig,
abTool.flowData.upsellPageTemplate
)
if (template !== abTool.flowData.upsellPageTemplate) {
abTool.setFlowData({
...abTool.flowData,
upsellPageTemplate: template as z.infer
})
}
await analyticsBrowser.anTrackEvent('UpSellRedirect', uuid, {
attr: {
upsellPageTemplate: template,
},
})
await onCreateCart()
const nextSlug = upSellNavigation.nextPathByConfigItemIndex(UpConfig, template, -1)
if (nextSlug) {
const nextRoute = /${landing}/${checkout}/up/${uuid}/${nextSlug}/${landing}/${checkout}/up-paid/${uuid}
router.push(nextRoute)
} else {
router.push()
}
}
initializePage().catch(console.error)
}, [])
`
`typescript
import { useRouter } from 'next/navigation'
import { UpConfig } from '@/app/[landing]/[checkout]/up/[uuid]/config'
import { UpsellPageEnum } from '@/types/templates'
import { z } from 'zod'
import { upSellNavigation } from '@newageerp/node-ab-tool'
const useUpsellNavigation = (
landing: string,
checkout: string,
uuid: string,
upsellEnum: z.infer
currentUpsell: string,
) => {
const router = useRouter()
const onNext = () => {
const nextSlug = upSellNavigation.nextPathByConfigItemSlug(UpConfig, UpsellPageEnum.enum[upsellEnum], currentUpsell);
if (nextSlug) {
const nextRoute = /${landing}/${checkout}/up/${uuid}/${nextSlug}/${landing}/${checkout}/up-paid/${uuid}
router.push(nextRoute)
} else {
router.push()
}
}
return { onNext }
}
export default useUpsellNavigation
`
`typescript
import { UpSellConfigType } from '@newageerp/node-ab-tool'
export const UpConfig: UpSellConfigType = {
[UpsellPageEnum.enum.Default]: [
'profile-secrets',
'dating-secrets',
'unlimited',
]
}
`
`typescript
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',
]
}
`
`typescript
export const UpConfig: UpSellConfigType = {
[UpsellPageEnum.enum.SplitTest]: [
[
{
slug: UpsellPageEnum.enum.SplitTestA,
percent: 50,
splitTemplates: true,
},
{
slug: UpsellPageEnum.enum.SplitTestB,
percent: 50,
splitTemplates: true,
},
],
],
[UpsellPageEnum.enum.SplitTestA]: ['profile-secrets-test'],
[UpsellPageEnum.enum.SplitTestB]: ['cheatcodes-masterclass-v2'],
}
``