This message was deleted.
# ask-questions
w
This message was deleted.
b
Current setup is as easy:
Copy code
useEffect(() => {
    // Load feature definitions from GrowthBook API
    loadGrowthbookDefinitions()
      .then((res) => {
        // Set features to the provider
      growthbook.setFeatures(res?.data?.features);

        // Set user attributes for targeting (from segment analytics)
        const segmentId = getCookie("ajs_anonymous_id");
        growthbook.setAttributes({
          id: segmentId,
        });
      })
      .catch(() => {});
  }, []);
f
I haven't tested this specifically, but I think something like this would work:
Copy code
export function getServerSideProps() {
  // Need a separate GrowthBook instance for server-side code
  const growthbook = new GrowthBook({
    features: ...,
    attributes: ...
  });

  // Get your features
  const feature = growthbook.isOn("my-feature");

  // Return feature plus tracking data
  return {
    props: {
      feature,
      trackingData: Array.from(growthbook.getAllResults().values())
    }
  } 
}

// In your page, track to segment in a useEffect hook
export function MyPage({feature, trackingData}) {
  useEffect(() => {
    trackingData.forEach(({experiment, result}) => {
      window.analytics.track(...)
    })
  }, []);
}
b
Thanks @future-teacher-7046 for your help. I'll give it a try 👋
142 Views