Hey all! Attempting to use the split content feature on plasmic! Here’s how I have it setup per this doc (Split content setup | Learn Plasmic)
My confusion lies mainly on setup and if this is adequate enough for us to run a/b tests. Is there more setup we need in order to have a/b testing function?
@jason no matter what we do we aren’t getting the second variation to show up. We’ve tried several different devices, browsers, private mode, non private mode etc.
We are using @plasmicapp/loader-nextjs @ 1.0.358. Could that be an issue?
Hi, it’s not possible to see where you use the variation object to render your page. If you are passing the variation object also to your <PlasmicRootProvider> which is used to render the page (not only to the one in extractPlasmicQueryData). Another detail is that it’s preferred to call getActiveVariation only after maybeFetchComponentData. But from looking into your page, I am unsure whether the middleware is routing the requests or not, could you confirm that?
import { NextRequest, NextResponse, userAgent } from "next/server"
import { getMiddlewareResponse } from "@plasmicapp/loader-nextjs/edge"
// Exclude paths that are definitely not Plasmic pages with variations
export const config = {
matcher: ["/:path((?!_next/|api/|favicon\\.ico|plasmic-host).*)"],
}
export async function middleware(req: NextRequest) {
// Only pick a variation for GET requests
if (req.method !== "GET") {
return
}
const newUrl = req.nextUrl.clone()
const PLASMIC_SEED = req.cookies.get("plasmic_seed")
const ua = userAgent(req)
const browser = ua.browser.name?.includes("Chrome")
? "Chrome"
: ua.browser.name?.includes("Safari")
? "Safari"
: "Other"
// Rewrite to a new pathname that encodes the custom traits for
// this request, as well as some randomness for A/B tests
const { pathname, cookies } = getMiddlewareResponse({
path: newUrl.pathname,
traits: {
browser,
},
cookies: {
...(PLASMIC_SEED ? { plasmic_seed: PLASMIC_SEED.value } : {}),
},
})
// Rewrite the response to use this new pathname
newUrl.pathname = pathname
const res = NextResponse.rewrite(newUrl)
// Save anything that needs to be saved in a cookie -- specifically,
// the custom trait that corresponds to the random seed. The same
// random seed will be used to pick the A/B test bucket each time
// the user visits, to ensure that a visitor will always see the
// same A/B test bucket.
cookies.forEach(cookie => {
res.cookies.set(cookie.key, cookie.value)
})
return res
}
Highlighting @fmota’s message again. Can you share where <PlasmicRootProvider> is created in CatchallPage? I assume it’s in your <Layout> component, but I can’t see that. Are you passing the correct variation there?