bumpy-student-89073
07/01/2022, 5:51 AMconst growthbook = new GrowthBook({
attributes: { id: visitor_id },
features: await getFeatures(),
trackingCallback: (experiment, result) => {
console.log("EXPERIMENT", experiment)
console.log("RESULT", result)
res.cookie("GB_EXPERIMENTS", JSON.stringify([
{
key: experiment.key,
variationId: String(result.variationId)
}
]))
}
});
fresh-football-47124
bumpy-student-89073
07/01/2022, 6:46 AMvariantId = 1
I don't get the cookie setfresh-football-47124
bumpy-student-89073
07/01/2022, 7:20 AMEXPERIMENT {
variations: [ false, true ],
key: 'prorb',
coverage: 1,
weights: [ 0.5, 0.5 ],
hashAttribute: 'id'
}
RESULT {
inExperiment: true,
hashUsed: true,
variationId: 0,
value: false,
hashAttribute: 'id',
hashValue: '03e900c0-9d56-4df6-8d38-c26c78af5077'
}
Visitor ID 03e900c0-9d56-4df6-8d38-c26c78af5077
EXPERIMENT {
variations: [ false, true ],
key: 'prorb',
coverage: 1,
weights: [ 0.5, 0.5 ],
hashAttribute: 'id'
}
RESULT {
inExperiment: true,
hashUsed: true,
variationId: 1,
value: true,
hashAttribute: 'id',
hashValue: '63bab7aa-8739-464a-b30a-1faf4bcf6dfc'
}
Visitor ID 63bab7aa-8739-464a-b30a-1faf4bcf6dfc
fresh-football-47124
bumpy-student-89073
07/01/2022, 7:39 AMfresh-football-47124
bumpy-student-89073
07/01/2022, 7:43 AMres.cookie
?fresh-football-47124
bumpy-student-89073
07/01/2022, 7:49 AMbusy-horse-73824
07/01/2022, 8:01 AMbumpy-student-89073
07/01/2022, 8:02 AMtrackingCallback
once, in the middlewarefresh-football-47124
future-teacher-7046
bumpy-student-89073
07/01/2022, 5:53 PM// Pick which page to render depending on a feature flag
let res = NextResponse.next();
if (growthbook.feature("prorb").on) {
const url = req.nextUrl.clone();
url.pathname = "/lp/practical-ruby-on-rails-for-beginners-20220618";
res = NextResponse.rewrite(url);
}
future-teacher-7046
res = NextResponse.rewrite
part that's causing the issue. When you create a new response object it loses everything you did earlier such as setting cookiesbumpy-student-89073
07/01/2022, 5:56 PMfuture-teacher-7046
bumpy-student-89073
07/01/2022, 5:58 PMgrowthbook.isOn("prorb")
return false?future-teacher-7046
bumpy-student-89073
07/01/2022, 6:09 PMfuture-teacher-7046
bumpy-student-89073
07/01/2022, 6:11 PMlet visitor_id = req.cookies[COOKIE] || crypto.randomUUID()
let experimentKey = null;
let variantId = null;
const growthbook = new GrowthBook({
attributes: { id: visitor_id },
features: await getFeatures(),
trackingCallback: (experiment, result) => {
experimentKey = experiment.key;
variantId = result.variationId;
}
});
// Pick which page to render depending on a feature flag
let res = NextResponse.next();
if (growthbook.feature("prorb").on) {
const url = req.nextUrl.clone();
url.pathname = "/lp/practical-ruby-on-rails-for-beginners-20220618";
res = NextResponse.rewrite(url);
}
res.cookie("GB_EXPERIMENTS", JSON.stringify([
{
key: experimentKey,
variationId: variantId
}
]))
// Store the visitor cookie if not already there
if (!req.cookies[COOKIE]) {
res.cookie(COOKIE, visitor_id)
}
return res
future-teacher-7046
bumpy-student-89073
07/01/2022, 7:54 PM