important-tailor-75460
12/13/2023, 10:16 AMtrackingCallback: (experiment, result) => {
// TODO: Use your real analytics tracking system
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.key,
});
},
famous-bird-26809
12/13/2023, 10:20 AMfamous-bird-26809
12/13/2023, 10:22 AMimportant-tailor-75460
12/13/2023, 10:23 AMfresh-football-47124
important-tailor-75460
12/13/2023, 10:38 AMimportant-tailor-75460
12/13/2023, 10:40 AMimportant-tailor-75460
12/13/2023, 12:58 PMTypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
at Function.invokeGetter (<anonymous>:3:28)
famous-bird-26809
12/13/2023, 4:07 PMfamous-bird-26809
12/13/2023, 4:43 PMimportant-tailor-75460
12/13/2023, 4:44 PMfamous-bird-26809
12/14/2023, 11:32 AMimportant-tailor-75460
12/15/2023, 10:29 AMconst getFeatures = await fetch(`<https://cdn.growthbook.io/api/features/${process.env.NEXT_PUBLIC_GROWTH_BOOK_FEATURES_SDK}>`);
const { features } = await getFeatures.json();
return { features };
You can find your Features endpoint in GrotwhBook dashboard by going SDK configuration -> SDK Connections -> and then click in your SDK Connection and copy Full API Endpoint
After fetching your Features then you can Initialize your GrowthBook:
Note: do not forget to pass features that you fetched in new GrowthBook({features}) check example beneath
const gb = new GrowthBook({
enableDevMode: true,
features,
trackingCallback: (experiment, result) => {
if (process.env.NEXT_PUBLIC_ENVIRONMENT === ENVIRONMENT_MODE.DEV) {
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.variationId,
});
}
},
});
gb.setAttributes({
id: user.id,
});
NOTE: also it is important to provide id
gb.setAttributes({
id: user.id,
});
Now whenever you use feature flag the experiment that is connected to that feature flag will be called automatically and should trigger trackingCallback
---------------------------------------------------
if this doesn’t work for you then you can try to play manually with experiments by fetching experiments from the API
https://api.growthbook.io/api/v1/experiments/
this one requires Bearer token more info you can get here: https://docs.growthbook.io/api/#tag/experiments/operation/listExperiments
also you can fetch experiments for one specific project that you want by providing projectId query param https://api.growthbook.io/api/v1/experiments/?projectId=
and then try to create GrowthBook with experiments param
const gb = new GrowthBook({
enableDevMode: true,
features,
experiments,
trackingCallback: (experiment, result) => {
if (process.env.NEXT_PUBLIC_ENVIRONMENT === ENVIRONMENT_MODE.DEV) {
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.variationId,
});
}
},
});
gb.setAttributes({
id: user.id,
});
brief-honey-45610
12/15/2023, 4:41 PMimportant-tailor-75460
12/17/2023, 6:03 PMconst getFeatures = await fetch(`<https://cdn.growthbook.io/api/features/${process.env.NEXT_PUBLIC_GROWTH_BOOK_FEATURES_SDK}>`);
const { features } = await getFeatures.json();
return { features };
and then:
const growthbook = new GrowthBook({
enableDevMode: true,
features,
trackingCallback: (experiment, result) => {
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.variationId,
});
},
});
growthbook.setAttributes({
id: user.id,
});
id: user.id -> this is id that I generate with firebase SDK but It could be any unique id
then I wrap my app with GrowthBookProvider:
<GrowthBookProvider growthbook={growthbook}>{children}</GrowthBookProvider>;
and after this whenever I use my feature flag that is connected with an experiment in GrowthBook dashboard it returns me feature flag value true or false but also it triggers trackingCallbackfamous-bird-26809
12/18/2023, 7:26 AM