https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
c

careful-controller-13102

09/05/2023, 8:10 AM
Hello, is there any other places where i can access the experiment & variation id other than trackingCallback? GrowthBook Instance + trackingCallback
Copy code
export const growthbookClient = new GrowthBook({
  apiHost: process.env.NEXT_PUBLIC_GB_API_HOST,
  clientKey: process.env.NEXT_PUBLIC_GB_CLIENT_KEY,
  enableDevMode: true,
  trackingCallback: (experiment, result) => {

    // need to check if the attribute is available upon snowplow event sent
    const extraAttributes = growthbookClient.getAttributes();
    console.log('extraAttributes => ', extraAttributes);

    trackStructEvent(
      {
        label: experiment.key, // experiment id
        property: result.key, // variant id
        category: extraAttributes.invoiceId,
        action: 'Viewed Experiment',
      },
      [TRACKER_NAME],
    );
  },
});
--- For example, I've initialised growthbook in
growthbook.ts
and I've a page called
home.tsx
on this page i'd want to send additional payload alongside the experiment and variationID. As these two files are in separate places, i can't get experiment and variationID in
home.tsx
under
handleBannerClick
.
Copy code
const handleBannerClick = (bannerUrl: string) => {
    toast.success('Banner Clicked');
    trackStructEvent(
      {
        action: 'Banner Clicked',
        category: experiment.id, <-- how can i get this
        label: variation.key <-- how can i get this
      },
      [TRACKER_NAME],
    );
  };

  console.log('EmailBannerCard Rendered', {
    banner_url,
    selectedLanguage,
  });
s

swift-helmet-3648

09/05/2023, 5:34 PM
Hi Shun Yuan, let me look into this
Hi @careful-controller-13102 This isn't something we currently support. One thing to note is the potential for multiple experiments to be running on any given page. If you'd like to use experiment/variation IDs regardless, there are workarounds you can build using JavaScript such as storing these IDs in a persistent object somewhere.
c

careful-controller-13102

09/06/2023, 6:47 AM
alright thanks man! Appreciate it
s

straight-whale-38038

09/18/2023, 1:03 PM
@careful-controller-13102 you can implement the Observer Pattern to make other related objects know when the trackin callback has been triggered.
8 Views