Hi, I am initializing in this way. app.use(async ...
# ask-questions
j
Hi, I am initializing in this way. app.use(async function (req, res, next) { // Create a GrowthBook instance and store in the request req.growthbook = new GrowthBook({ apiHost: "http://localhost:4100", clientKey: "my-key", // Set this to
false
to improve performance in server-side environments enableDevMode: false, // Important: make sure this is set to
false
, otherwise features may change in the middle of a request subscribeToChanges: false, attributes: { id: 101, country: "US" }, trackingCallback: (experiment, result) => { // Example using Segment // console.log("MMM", experiment,result) // analytics.track("Experiment Viewed", { // experimentId: experiment.key, // variationId: result.key, // }); }, }); // Clean up at the end of the request res.on("close", () => req.growthbook.destroy()); // Wait for features to load (will be cached in-memory for future requests) req.growthbook .loadFeatures() .then(() => next()) .catch((e) => { console.error("Failed to load features from GrowthBook", e); next(); }); }); I just wanted to know where attributes: { id: 101, country: "US" }, this attribute will store to maintain stickiness?
f
Those attributes have to be stored on your end - by default, GrowthBook stores no state
j
So how it will maintain stickyness. for same Id?
f
well, you can use an ID that is already sticky, like one that your event tracker already has - or you can make your own id and store it in a cookie yourself
we have some example code on our docs for that
j
Can i get control over stickyness, like TTL for stickiness?
f
Sure, you can use any attribute you like for the assignment, even an ID you make yourself - and then you can control the stickyness