This message was deleted.
# announcements
w
This message was deleted.
f
Is it waiting for the fetch call?
n
can you shed any light on the
source: 'unknownFeature'
message?
f
You might need a loadFeatures()
n
Copy code
if (typeof window !== 'undefined') {
  // get existing growthbook user
  const growthbook_user = window.sessionStorage.getItem("growthbook_user_id")
  let growthbook_user_id
  if (growthbook_user) {
    growthbook_user_id = growthbook_user
  } else {
    // generate a growthbook userID and set it
    growthbook_user_id = uuid()
    window.sessionStorage.setItem("growthbook_user_id", JSON.stringify(growthbook_user_id))
  }

  growthbook = new GrowthBook({
    apiHost: "<https://cdn.growthbook.io>",
    clientKey: "sdk-cKFk90qAra2QhKcY",
    attributes: {
      id: growthbook_user_id
    },
    enableDevMode: true,
    trackingCallback: (experiment, result) => {
      console.log('wth')
      // track using GA4
      window.gtag("event", "experiment_viewed", {
        event_category: "experiment",
        experiment_id: experiment.key,
        variation_id: result.variationId,
      })
    }
  })
  // Load features from the GrowthBook API
  growthbook.loadFeatures()

  if ("gtag" in window) {
    window.dataLayer && window.dataLayer.push({
      user_id: growthbook_user_id,
      client_id: growthbook_user_id
    })
  }
}
^ this where I landed using session storage for the uuid
f
Okay
Okay, seems to be working
n
Should I see the experiment listed under "Experiments" here?
f
Yes, if there is an experiment rule
n
Oh okay. I was assuming it wasn't working since I wasn't getting a log out of the trackingCallback and the feature is always
false
.
Experiment rule == targeting condition?
f
no, an experiment rule is an experiment rule
159 Views