worried-planet-2191
10/03/2024, 3:26 PMfresh-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"));
});