How to run an A/B test with Google Analytics 4
Last updated: 29 November 2026.
Google Analytics 4 can't run an A/B test by itself: it counts visitors and events, but it does not show different versions of a page to different visitors. To A/B test with GA4, you add a testing tool that splits visitors and sends each visitor's version to GA4. Pickbook A/B does this with one setting, and you can then filter your GA4 reports by version.
What GA4 can and cannot do
Google Analytics 4 is a measurement tool, so it can report what visitors did but can't decide which version each visitor sees. Until 2023, Google had a separate testing tool for that job, Google Optimize. Google's own help page says that Google Optimize and Optimize 360 are no longer available as of 30 September 2023, and that Google is investing in third-party A/B testing integrations for Google Analytics.
An A/B test needs 3 jobs done. Here is who does each one when you use GA4 with Pickbook A/B:
| Job | Google Analytics 4 | Pickbook A/B |
|---|---|---|
| Give each visitor a version | No | Yes. Each visitor gets one version by chance and sees the same version on return visits in the same browser. |
| Count the goal for each version | Yes, if you register the version as a custom dimension | Yes. It counts each visitor once, in the version they were given. |
| Say which version won | No. A report shows numbers, with no rule for when a difference is more than luck. | Yes. It names a winner only when the difference is unlikely to be luck. |
Google's statements were checked on Google's help pages on 29 November 2026. Sources are listed at the end of this page.
Step 1: Create the test
Create the test in Pickbook A/B first, because the test decides the versions that GA4 will later report. Name the versions, for example Current headline and New headline, and choose the goal, such as a sign-up or a click on your main button.
Before the test starts, Pickbook A/B tells you how many visitors it needs and whether it can finish within 60 days at your traffic. Your GA4 reports already show how many visitors the page gets in a month, so you can check that number in What can I test with my traffic? before you set anything up. Read How long should an A/B test run? for examples.
Step 2: Send each visitor's version to GA4
Add data-analytics="ga4" to the Pickbook A/B script tag, and Pickbook A/B sends GA4 an event
named pickbook_version each time a visitor is given a version. The event has 2 parameters:
pickbook_test, with the name of the test, and pickbook_version, with the name
of the version.
- The setting is off until you add it.
- Pickbook A/B sends the test name and the version name, and nothing else. It never sends visitor IDs or personal data to GA4, and it reads nothing back from GA4.
- Each version is sent once per page.
- If the GA4 script loads after the Pickbook A/B script, Pickbook A/B tries again for 5 seconds. If GA4 loads later than that, that page sends no event.
- You can list more tools in the same setting, for example
data-analytics="ga4,plausible", or usedata-analytics="all".
The setting needs the gtag function on your page, which the Google tag snippet defines.
Pickbook A/B sends the event by calling that function. A page that loads GA4 only through Google Tag Manager
gets no pickbook_version event unless the page also defines gtag. After you add the
setting, check in the Realtime report that the event arrives.
If you work with an AI coding agent, it can do steps 1 and 2 for you. Read A/B testing with AI agents for how.
Step 3: Register the version as a custom dimension
GA4 shows a custom event parameter in its reports only after you register it as a custom dimension. Google's developer guide says that to analyze custom parameters in Google Analytics reports, you must first register them as custom dimensions or metrics, and that new data can take up to 48 hours to appear in your reports after you register one. A standard GA4 property can hold 50 event-scoped custom dimensions, so 2 for your tests leave plenty of room.
- In Google Analytics, open Admin, then the Custom definitions page.
- Create a custom dimension with the event-scoped parameter
pickbook_version. - Create a second one with the parameter
pickbook_test, if you run more than one test.
You can see the event at once in the Realtime report, before the dimensions are ready. This is a quick way to check that the setting works.
Step 4: Read the versions in a GA4 report
Once the custom dimension has data, you can split any GA4 report or exploration by version. For example,
build an exploration with the pickbook_version dimension as rows and look at where visitors
of each version went next, how long they stayed, or which pages they viewed.
This is where GA4 adds the most. Pickbook A/B counts one yes-or-no goal and any extra goals you add, and GA4 shows everything else the visitors did. If the new version wins on sign-ups but its visitors leave the next page at once, GA4 is where you see it.
Why the winner should not come from GA4
Read the winner from Pickbook A/B and use GA4 to understand it. A GA4 report is not built to answer "which version won" for 3 reasons:
- A report can count visits or events instead of visitors, so one keen visitor can count several times.
- GA4 misses visitors whose browser blocks it or who did not give consent, so the counts in each version can differ from the visitors really tested.
- A report has no rule for when a difference is more than luck, and no planned number of visitors to wait for.
Pickbook A/B counts each visitor once, in the version they were given. It works out how many visitors the test needs before it starts and gives one answer when every version has them. Read How to tell a real difference from luck for why waiting matters, and How Pickbook A/B picks a winner for the method.
Privacy and consent with GA4
Turning on the GA4 setting does not change how GA4 itself handles consent. Pickbook A/B sends the version through the Google tag like any other event, so the consent settings you already have for GA4 apply to it.
The Pickbook A/B script sets no cookies. It keeps a random visitor ID in the browser's local storage, which can need consent under EU rules, so it has a consent mode and a mode that keeps nothing in browser storage. Read Cookieless A/B testing for the details. Pickbook A/B keeps your tests and your visitors' data in a database in the European Union. Your first test is free, one per website. See the pricing on Pickbook A/B for the plans after that.
If you are moving away from GA4 to a lighter analytics tool, the same setting works with Plausible, Fathom, Umami, PostHog, and Microsoft Clarity. Read A/B testing with Plausible, Fathom, or Umami. If you used Google Optimize before, read A Google Optimize alternative for small websites.
Questions
Can Google Analytics 4 run A/B tests?
No, Google Analytics 4 can't run A/B tests on its own. It can report on versions that another tool shows, after you send it each visitor's version and register that as a custom dimension.
What replaced Google Optimize for GA4?
Google did not release a direct replacement. Google says Optimize and Optimize 360 are no longer available as of 30 September 2023, and that it is investing in third-party A/B testing integrations for Google Analytics. Any tool that splits visitors and sends GA4 an event can fill the gap.
Why don't I see pickbook_version in my GA4 reports?
You probably haven't registered it as a custom dimension yet, or the data is still on its way. Google says new data can take up to 48 hours to appear after you register one. The Realtime report shows the event sooner.
Does Pickbook A/B need Google Analytics?
No, Pickbook A/B does not need Google Analytics. It counts its own visitors and goals and gives its own answer. Sending versions to GA4 is optional.
What does it cost?
Your first test is free, one per website, and you don't need a card. After that, the Solo plan is $9 a month, the Plus plan is $19 a month, and the Team plan is $49 a month.
Sources
- [Sunset September 2023] Google Optimize, Google Analytics Help, checked on 29 November 2026.
- Set up event parameters, Google for Developers, checked on 29 November 2026.
- [GA4] About custom dimensions and metrics, Google Analytics Help, checked on 29 November 2026.