modern-ocean-57629
03/18/2025, 3:57 PMstickyBucketAssignmentDocs
? I'm using Nextjs and I want to enable sticky bucketing, Growthbook is inited via initSync
on React client.. which suddenly requires that unknown field. I cannot get any useful documentation about it.happy-autumn-40938
03/18/2025, 4:08 PMstickyBucketAssignmentDocs
on initSync
or anywhere for that matter. Would you mind sharing where you are seeing this requirement?modern-ocean-57629
03/18/2025, 5:05 PMmodern-ocean-57629
03/18/2025, 5:05 PMhappy-autumn-40938
03/18/2025, 5:29 PMgb.getStickyBucketAssignmentDocs()
modern-ocean-57629
03/18/2025, 5:32 PMgb
does not exist at this stagemodern-ocean-57629
03/18/2025, 5:33 PMhappy-autumn-40938
03/18/2025, 5:34 PMgBook.initSync({
payload,
stickyBucketAssignmentDocs: gBook.getStickyBucketAssignmentDocs(),
}),
Does this work?modern-ocean-57629
03/18/2025, 5:36 PMstickyBucketAssignmentDocs
must be passed in constructor and not in initSync.modern-ocean-57629
03/18/2025, 5:37 PMgb
instance with required attributes, 2d is to initialize it.
stickyBucketAssignmentDocs
is required on 1st stephappy-autumn-40938
03/18/2025, 5:46 PMfunction getAllStickyBucketAssignmentDocs(
stickyBucketService: StickyBucketService,
attributes: Attributes,
payload: FeatureApiResponse,
) {
// @ts-ignore
const ctx = { global: {} };
const attributes = getStickyBucketAttributes(ctx, payload);
return stickyBucketService.getAllAssignments(attributes);
}
modern-ocean-57629
03/18/2025, 5:49 PMexample repoI'm using Nextjs and in examples repo there is no case with sticky bucketing at all š
modern-ocean-57629
03/18/2025, 5:49 PMCan you use the sync version of this method to generate the docs?let me try
happy-autumn-40938
03/18/2025, 5:51 PMmodern-ocean-57629
03/18/2025, 5:51 PMThe SDK itself has a helper for thisare you referring to
getStickyBucketAttributes
?happy-autumn-40938
03/18/2025, 5:54 PMgetStickyBucketAttributes
will need to be extracted from the SDK codebase as well.
function getStickyBucketAttributes(
ctx: EvalContext,
data?: FeatureApiResponse
): Record<string, string> {
const attributes: Record<string, string> = {};
const stickyBucketIdentifierAttributes = deriveStickyBucketIdentifierAttributes(
ctx,
data
);
stickyBucketIdentifierAttributes.forEach((attr) => {
const { hashValue } = getHashAttribute(ctx, attr);
attributes[attr] = toString(hashValue);
});
return attributes;
}
and likely also deriveStickyBucketIdentifierAttributes
function deriveStickyBucketIdentifierAttributes(
ctx: EvalContext,
data?: FeatureApiResponse
) {
const attributes = new Set<string>();
const features =
data && data.features ? data.features : ctx.global.features || {};
const experiments =
data && data.experiments ? data.experiments : ctx.global.experiments || [];
Object.keys(features).forEach((id) => {
const feature = features[id];
if (feature.rules) {
for (const rule of feature.rules) {
if (rule.variations) {
attributes.add(rule.hashAttribute || "id");
if (rule.fallbackAttribute) {
attributes.add(rule.fallbackAttribute);
}
}
}
}
});
experiments.map((experiment) => {
attributes.add(experiment.hashAttribute || "id");
if (experiment.fallbackAttribute) {
attributes.add(experiment.fallbackAttribute);
}
});
return Array.from(attributes);
}
happy-autumn-40938
03/18/2025, 5:54 PMmodern-ocean-57629
03/18/2025, 5:56 PMimport { getHashAttribute } from "@growthbook/growthbook/dist/core";
import {
EvalContext,
FeatureApiResponse,
} from "@growthbook/growthbook/dist/types/growthbook";
?modern-ocean-57629
03/18/2025, 5:56 PM@growthbook/growthbook/dist/core
looks a bit risky since it reaches deep content of a packagehappy-autumn-40938
03/18/2025, 5:57 PMmodern-ocean-57629
03/18/2025, 5:58 PMgetHashAttribute
also has to be extracted from the SDKhappy-autumn-40938
03/18/2025, 5:58 PMhappy-autumn-40938
03/18/2025, 5:59 PMmodern-ocean-57629
03/18/2025, 6:01 PMmodern-ocean-57629
03/18/2025, 6:09 PMstickyBucketAssignmentDocs
which was not that hard because you guys provide interfaces š:modern-ocean-57629
03/18/2025, 6:10 PMconst savedAssignments = JSON.parse(
getCookie(
stickyBucketService.getKey(
"id",
(getCookie(GB_UUID_COOKIE) || "",
),
) || "{}",
);
that returnsmodern-ocean-57629
03/18/2025, 6:11 PMmodern-ocean-57629
03/18/2025, 6:13 PMgetKey
happy-autumn-40938
03/18/2025, 6:14 PMhappy-autumn-40938
03/18/2025, 6:59 PMmodern-ocean-57629
03/19/2025, 9:00 AMhappy-autumn-40938
03/19/2025, 4:27 PM