How do you run Google Optimize A/B tests in React?

Learn why Google Optimize is no longer available and how to run React A/B tests with a current tool, stable variants, and event tracking.

Google Optimize A/B tests cannot be run in a React app now; Google says Optimize is no longer available. Use a current experimentation tool or an in-house test instead, and render each variant through React.

How do you run Google Optimize A/B tests in a React app?

You can’t start or run a Google Optimize test in 2026; use another experiment platform and connect it to your React app. Google says Optimize is no longer available and directs users toward third-party A/B testing integrations with Google Analytics. (support.google.com)

A practical replacement works like this:

  1. Choose an experiment platform or build a simple in-house assignment system. If you want results in GA4, check that your chosen platform supports an integration, or plan to send experiment events yourself. Google publishes an integration guide for experiment providers and a separate approach for custom experiments. (developers.google.com)
  2. Assign each user to a variant consistently. Get the assignment from your platform’s SDK or API, or from your own testing logic. Keep the assignment stable for that user during the test; avoid randomly choosing a variant every time the component renders.
  3. Pass the variant into React and render it there. React supports rendering different JSX based on a condition. For example:
function Hero({ variant }) {
  return variant === "B"
    ? <h1>Variant B headline</h1>
    : <h1>Control headline</h1>;
}
  1. Track exposure and the outcome. Send an event when a user is actually shown a variant, with an experiment ID and variant ID, then track the conversion you care about. Google’s custom-experiment guidance describes sending an exposure event and registering its parameters as event-scoped custom dimensions for GA4 reporting. (developers.google.com)
  2. Test the setup before sending real traffic. Verify that the assignment persists, the right JSX appears, and exposure and conversion events are recorded under the right variant. If assignment loads asynchronously, decide how to handle the page before it arrives; otherwise users may briefly see the wrong version.

This React-rendered approach is preferable to an old Optimize tutorial that edits page elements directly: React determines what to render from component logic, so keep variant changes in that logic rather than relying on an obsolete Optimize script. (react.dev)

The trade-off depends on who needs to operate tests. A React-based implementation gives developers control over complex changes, but usually means they must implement or maintain variant rendering and measurement. A third-party platform can provide its own experiment-management workflow; Google’s documentation says A/B tests in Google Analytics require integration with a third-party testing tool. (support.google.com)

In short, don’t install an old Google Optimize snippet or React wrapper expecting it to run. Choose a supported testing setup, assign users to variants, render those variants in React, and record exposure and conversions for analysis.

Related Reading

Start collecting feedback in 5 minutes.Try the no-code surveys your customers actually answer — free, no credit card.
Get started free

Latest in CRO & A/B Testing

Start collecting feedback in 5 minutes.

Try our no-code surveys that visitors actually answer.

Questions or Feedback?

We are always ready to hear from you.