@newageerp/node-ab-tool
v1.0.25
Published
``` npm install @newageerp/node-ab-tool@latest ```
Readme
INSTALL
npm install @newageerp/node-ab-tool@latestENV variables
all .env
- ABTOOL_PROJECT - get value from manager, examples
- todayistheday-ab
- todayistheday-fr-ab
- wingmanx-ab
- ...
middleware.ts
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).*)',
}Usage
config types
up/[uuid]/config.ts
import { UpSellConfigType } from '@newageerp/node-ab-tool'
export const UpConfig: UpSellConfigType = {
}upsell flow
up landing page up/[uuid]/page.tsx
here example for one upsell a/b test support, templates a/b test support and important analytics event
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<typeof UpsellPageEnum>,
})
}
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}`
router.push(nextRoute)
} else {
router.push(`/${landing}/${checkout}/up-paid/${uuid}`)
}
}
initializePage().catch(console.error)
}, [])
upsell navigation hook
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<typeof UpsellPageEnum>,
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}`
router.push(nextRoute)
} else {
router.push(`/${landing}/${checkout}/up-paid/${uuid}`)
}
}
return { onNext }
}
export default useUpsellNavigation
Config example
Simple flow
import { UpSellConfigType } from '@newageerp/node-ab-tool'
export const UpConfig: UpSellConfigType = {
[UpsellPageEnum.enum.Default]: [
'profile-secrets',
'dating-secrets',
'unlimited',
]
}One upsell AB test
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',
]
}Split full templates
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'],
}
