Hi! Our team is using GrowthBook together with Amp...
# ask-questions
h
Hi! Our team is using GrowthBook together with Amplitude. I’m a client-side developer and I’d like to clarify one point.
Copy code
export const gbInstance = new GrowthBook({
  apiHost: import.meta.env.VUE_APP_GROWTHBOOK_API_HOST,
  clientKey: import.meta.env.VUE_APP_GROWTHBOOK_CLIENT_KEY,
  enableDevMode: !isProduction(),
  plugins: [autoAttributesPlugin()],
  trackingCallback: (experiment, result) => {
    $analytics.track({
      event_type: 'Experiment Viewed',
      event_properties: {
        experimentId: experiment.key,
        variationId: result.key
      }
    });
    console.log(`key-${experiment.key} result-${result.key}`);
  }
});
const initializeGrowthBook = async () => {
  try {
    if ($analytics) {
      gbInstance.updateAttributes({
        id: $analytics.amplitude.getUserId(),
        deviceId: $analytics.amplitude.getDeviceId()
      });
    }
    await gbInstance.init({ streaming: true });
    gbFlags.initialize(gbInstance);
    return gbInstance;
  } catch (e) {
    return null;
  }
};
I’m implementing it like this, and in the plugins I specify
autoAttributesPlugin()
. That generates attributes for targeting (one of them is
id
). When setting up an experiment in the admin panel, you can assign it based on
anonymous_id
or
user_id
. How is this
id
connected with
user_id
or
anonymous_id
? Or do I need to explicitly set
user_id
and
anonymous_id
when initializing? If so, how should this be connected with Amplitude, since it has both
user_id
and
device_id
?