Skip to main content
Version: Config V1 (legacy)

Google Analytics - Send feature flag analytics to Google Analytics

Sending Feature Flag Evaluation Analytics to Google Analytics

Integrate your feature flag evaluations with Google Analytics experiments to gain advanced insights into how your features are used and to assess the outcomes of A/B tests.

Setup Instructions

  1. Install SDKs: Add both the ConfigCat SDK and Google Analytics SDK to your application.
  2. Configure SDKs:
    • ConfigCat SDK: Initialize with your ConfigCat SDK key.
    • Google Analytics SDK: Set up with your Google Analytics measurement ID.
  3. Integrate Feature Flag Evaluations:
    • During the initialization of the ConfigCat SDK, subscribe to the flagEvaluated hook.
    • Send feature flag evaluation data to Google Analytics using the experience_impression event name. Include the following parameter:
      • exp_variant_string: Construct this string to include the tool name (configcat), the feature flag's key, and its value. For example: configcat-isMyAwesomeFeatureEnabled-true.

Code samples:

const configCatClient = configcat.getClient("#YOUR_SDK_KEY", PollingMode.AutoPoll, {
setupHooks: (hooks) =>
hooks.on('flagEvaluated', evaluationDetails => {
const variant = "configcat-" + evaluationDetails.key + "-" + evaluationDetails.value;
gtag('event', 'experience_impression',
{
'exp_variant_string': variant,
'variation_id': evaluationDetails.variationId
});
}),
});
note

For Text feature flags with lengthy values (e.g., JSON), send the variationId instead of the value as the exp_variant_string to Google Analytics. The variationId is a hashed version of the feature flag value, accessible on the ConfigCat Dashboard by enabling the Show VariationIDs to support A/B testing setting. Learn more here.

  1. Deploy your application and wait for feature flag evaluations to occur. This process might take 1-2 days for the experience_impression events to populate in Google Analytics.

  2. Define an audience in Google Analytics using the exp_variant_string parameter with the same values that you using in your events (e.g. configcat-isMyAwesomeFeatureEnabled-true) it by following the guide here. This allows you to leverage feature flag evaluation events effectively.

Example audiences reports

Google Analytics Audience report