This message was deleted.
# experimentation
w
This message was deleted.
f
the experiment array that's empty there is only for visual editor experiments
there is an experiment as a feature flag rule that I see in that response - and thats is "show-delivery-time"
i
ah ok - thanks for clarifying do you know when the tracking callback should fire exactly? I have it defined like this:
Copy code
window.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 help
f
it should fire as soon as a user is assigned
I take it you're not getting the console.log either?
i
nope nothing
f
can you share the full SDK implementation you're using?
i
sure, here's the script:
Copy code
window.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:
Copy code
<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>
I was trying the refresh event and setting an attritbute to see if it would trigger the callback but I don't think it's needed
f
ya, I dont think it is
I wonder if your isOn check is happening before the payload is loaded
i
should I try removing it?
oh one question - does the async script have to be the last in the head, or is it just important that it's after the rest of the growthbook_config setup? I notice that there are a lot of other scripts injected after it when the page is rendered
c
did you ever get this working? having the same issue
in case it helps, the problem for me was that gb.isOn(“show-delivery-time”) is not evaluated when the data is loaded. Once i put it in a callback to call it when the data is loaded, it works.
isOn
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.
Copy code
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"));

  
});
116 Views