Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current Value override doesn't work with Javascript SDK #49

Open
ryangall7 opened this issue Nov 16, 2023 · 2 comments
Open

Current Value override doesn't work with Javascript SDK #49

ryangall7 opened this issue Nov 16, 2023 · 2 comments

Comments

@ryangall7
Copy link

I've added the Javascript SDK to our bundle with web pack. The dev tools can read the features and user attributes no problem, but overriding the Current Value in dev tools doesn't seem to change the feature value.

Javascript Setup:

import { GrowthBook } from "@growthbook/growthbook";

const gb = new GrowthBook({
  apiHost: "https://cdn.growthbook.io",
  clientKey: "******************",
  enableDevMode: true,
  subscribeToChanges: true,
  trackingCallback: (experiment, result) => {
    // TODO: Use your real analytics tracking system
    console.log("Viewed Experiment", {
      experimentId: experiment.key,
      variationId: result.key
    });
  }
});
window.gb = gb; // Expose for debugging

...

gb.setAttributes({
  id: cartToken,
  email: window?.userAttributes?.email,
  customerId: window?.userAttributes?.customerId,
  totalSpent: window?.userAttributes?.totalSpent,
  ordersCount: window?.userAttributes?.ordersCount,
  tags: window?.userAttributes?.tags,
  country: Shopify.country,
  locale: Shopify?.locale,
  currency: Shopify?.currency?.active,
  url: window.location.href,
  userAgent: navigator.userAgent,
  screenWidth: window.innerWidth,
  screenSize: screenSize,
  themeId: Shopify.theme.id,
  themeName: Shopify.theme.name,
  themeRole: Shopify.theme.role
});


//===========================
// setup growthbook
//===========================

export const setupGrowthbook = async function(){

    // Wait for features to be available
    await gb.loadFeatures();

    const value = gb.getFeatureValue("google-top-quality-store");
    console.log("google-top-quality-store", value);

}

Heres the devtools screen:
Screenshot 2023-11-16 at 3 26 55 PM

The feature never shows as a force feature value:
Screenshot 2023-11-16 at 3 28 34 PM

I've been digging through to code to try and find the method by which these are getting set. It seems theres something with messages sent to the window so I started logging any related to GB

window.addEventListener("message", function (event) {
  const data = event.data;
  if(data?.type?.startsWith("GB_")){
    console.log(data);
  }
});

but I only get one message:

{
	attributes: {id: '31295c7d037d94ba9af407aee0fb2eba', email: undefined, customerId: undefined, totalSpent: undefined, ordersCount: undefined, …}
	experiments: {}
	features: { 
		google-top-quality-store : {defaultValue: false, rules: Array(1)}
	}
	overrides: {},
	type: "GB_REFRESH"
}

which also appears to have no overrides.

@bttf
Copy link
Contributor

bttf commented Apr 2, 2024

Hi @ryangall7 Thanks for submitting. I'm unable to reproduce the issue on my local. We've updated the SDK a few times now - it's at 0.36.0 now. Have you tried latest and seen the same results?

@velialiev
Copy link

velialiev commented Dec 17, 2024

Same issue here. I think I've managed to find the problem. In my case this happened since devtools' forced features are loaded asynchronously and are not awaited by await gb.init(), so if you rely on awaiting init and doesn't set setRenderer you won't get updates from devtools

@bttf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants