Hypertune
  • Introduction
  • Getting Started
    • Set up Hypertune
    • Next.js (App Router) quickstart
    • Next.js (Pages Router) quickstart
    • React quickstart
    • Remix quickstart
    • Gatsby quickstart
    • Vue quickstart
    • Nuxt quickstart
    • Node.js quickstart
    • React Native quickstart
    • JavaScript quickstart
    • Python quickstart
    • Rust quickstart
    • Go quickstart
    • Web quickstart
    • GraphQL quickstart
  • Example apps
    • Next.js and Vercel example app
  • Concepts
    • Architecture
    • Project
    • Schema
    • Flag lifecycle
    • Logic
    • Variables
    • Splits
    • A/B tests
    • Staged rollouts
    • Multivariate tests
    • Machine learning loops
    • Events
    • Funnels
    • Hypertune Edge
    • Reduction
    • SDKs
    • GraphQL API
    • Git-style version control
    • App configuration
  • Use Cases
    • Feature flags and A/B testing
    • Landing page optimization
    • In-app content management
    • Pricing plan management
    • Permissions, rules and limits
    • Optimizing magic numbers
    • Backend configuration
    • Product analytics
  • Integrations
    • Vercel Edge Config integration
    • Google Analytics integration
    • Segment integration
    • Webhooks
      • Creating webhooks
      • Handling webhooks
  • SDK Reference
    • Installation
    • Type-safe client generation
    • Initialization
    • Build-time logic snapshot
    • Hard-coded fallbacks
    • Local-only, offline mode
    • Hydrate from your own server
    • Wait for server initialization
    • Provide targeting attributes
    • Local, synchronous evaluation
    • Remote logging
    • Getting flag updates
    • Serverless environments
    • Vercel Edge Config
    • Custom logging
    • Shutting down
Powered by GitBook
On this page
  • 1. Send A/B test exposures to Google Analytics
  • 2. Create a custom dimension for your A/B test
  • 3. View A/B test results
  • That's it
  1. Integrations

Google Analytics integration

PreviousVercel Edge Config integrationNextSegment integration

Last updated 11 months ago

You can send exposures and feature flag values from Hypertune to Google Analytics to add comparisons and breakdowns to your Google Analytics reports. This lets you see the impact of feature releases on key metrics.

1. Send A/B test exposures to Google Analytics

Add a new file called trackHypertuneExposure.ts that creates and exports a helper function to send A/B test exposures to Google Analytics:

declare const window: any;

export default function trackHypertuneExposure(
  dimensionName: string,
  value: any,
): void {
  window.gtag("event", "hypertune_exposure", {
    user_properties: { [dimensionName]: value },
  });
}
declare const window: any;

export default function trackHypertuneExposure(
  dimensionName: string,
  value: any,
): void {
  window.analytics.track("hypertune_exposure", {
    user_properties: { [dimensionName]: value },
  });
}

Also make sure you've set up a Google Analytics destination in Segment with a mapping that forwards all events including their properties. Here's an example:

Then call this function immediately after getting your feature flag:

import trackHypertuneExposure from "../lib/trackHypertuneExposure";
import useHypertune from "../lib/useHypertune";

export default function Editor() {
  const rootNode = useHypertune();
  
  const showNewEditor = rootNode.showNewEditor({ fallback: false });
  trackHypertuneExposure("ht_new_editor_test", showNewEditor);
  
  return showNewEditor ? <NewEditor /> : <OldEditor />;
}

2. Create a custom dimension for your A/B test

Open Google Analytics. Click Admin in the left sidebar, then Custom definitions, then Create custom dimension. Set:

  • Scope to User

  • Dimension name and User property to the dimension name you set in the call to trackHypertuneExposure, e.g. ht_new_editor_test

Here's what this looks like:

3. View A/B test results

Navigate to any report, then:

  1. In the top bar click Add comparison

  2. Set Dimension to the custom dimension for your A/B test, e.g. ht_new_editor_test

  3. Set Match Type to contains

  4. Set Value to true

  5. Repeat steps 1 to 4 but with Value set to false

You can now compare the test and control arms of your A/B test across all results in the report.

That's it

To track exposures for a new A/B test and view its results in Google Analytics, you just need to:

  1. Call trackHypertuneExposure in your code immediately after you access its flag

  2. Create a custom dimension in Google Analytics with the same dimension name you passed to trackHypertuneExposure

Then you can add comparisons to compare the test and control arms of your A/B test across all your reports.

A/B test