incalculable-orange-14964
10/03/2024, 3:26 PM% curl <https://gb-api.spencerkohan.com/api/features/sdk-CtRoip48W39SQYvy>
{
"status":200,
"features":{"show-delivery-time":{"defaultValue":false,"rules":[{"coverage":1,"hashAttribute":"id","seed":"b045dc6d-dbbd-431b-9f0b-f303dd7886cc","hashVersion":2,"variations":[false,true],"weights":[0.5,0.5],"key":"test-experiment","meta":[{"key":"0","name":"contriol"},{"key":"variant-a","name":"variant-a"}],"phase":"0","name":"Test Experiment"}]}},
"experiments":[],
"dateUpdated":"2024-10-03T15:01:28.770Z"
}
My experiment is running - is there any step I might be missing to get the assignment?
One detail I wasn't sure about: I set my assignment attribute to "id" because I saw this was automatically set by growthbook, but I wasn't sure if I have to do something else to trigger the assignmentfresh-football-47124
fresh-football-47124
incalculable-orange-14964
10/03/2024, 4:04 PMwindow.growthbook_config.trackingCallback = (experiment, result) => {
console.log('reporting assignment event');
fetch(trackingEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
shop_id: "6d259ec9-47dd-4e7e-8be6-cbce1b4e7b29",
event_name: "userAssigned",
parameters: {
experiment_id: experiment.key,
variation_id: result.key,
},
}),
});
};
but the callback doesn't seem to be firing, even if the feature flag is available
I also tried clearing the cookies to get a new assignment and it didn't helpfresh-football-47124
fresh-football-47124
incalculable-orange-14964
10/03/2024, 4:08 PMfresh-football-47124
incalculable-orange-14964
10/03/2024, 4:12 PMwindow.growthbook_config = window.growthbook_config || {};
window.growthbook_queue = window.growthbook_queue || {};
window.growthbook_queue.push((gb) => {
// Do whatever you need with the GrowthBook instance here
console.log('growthbook loaded');
console.log(gb.getAttributes());
let attributes = gb.getAttributes();
gb.updateAttributes({
id: attributes.id,
anonymous_id: attributes.id,
});
if(gb.isOn("show-delivery-time")) {
console.log('show-delivery-time');
} else {
console.log('don\'t show-delivery-time');
}
document.dispatchEvent(new CustomEvent("growthbookrefresh"));
});
window.growthbook_config.trackingCallback = (experiment, result) => {
console.log('reporting assignment event');
fetch(TRACKING_ENDPOINT, {
method: "POST",
headers: {
"Content-Type": "application/json", // specify the content type, if necessary
},
body: JSON.stringify({
shop_id: "6d259ec9-47dd-4e7e-8be6-cbce1b4e7b29",
event_name: "userAssigned",
// anonymous_id: experiment
parameters: {
experiment_id: experiment.key,
variation_id: result.key,
},
}),
});
};
And then this is added at the end of the head
tag:
<script async
data-api-host=API_HOST
data-client-key=CLIENT_KEY
src="<https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/auto.min.js>"
></script>
incalculable-orange-14964
10/03/2024, 4:14 PMfresh-football-47124
fresh-football-47124
incalculable-orange-14964
10/03/2024, 4:25 PMincalculable-orange-14964
10/03/2024, 4:35 PMcalm-monitor-96855
10/23/2024, 2:03 PMcalm-monitor-96855
10/23/2024, 5:35 PMisOn
and getFeatureValue
apparently actually initiate the experiment. https://github.com/growthbook/growthbook/issues/3121
So I believe updating the queue push to this would work.
window.growthbook_queue.push((gb) => {
// Do whatever you need with the GrowthBook instance here
console.log('growthbook loaded');
console.log(gb.getAttributes());
let attributes = gb.getAttributes();
gb.updateAttributes({
id: attributes.id,
anonymous_id: attributes.id,
});
const applyResult = () => {
if(gb.isOn("show-delivery-time")) {
console.log('show-delivery-time');
} else {
console.log('don\'t show-delivery-time');
}
}
document.addEventListener("growthbookdata", applyResult)
document.dispatchEvent(new CustomEvent("growthbookrefresh"));
});