Set up GA4 for your tests
VariFlask runs your tests on its own tracking, so you don't need GA4 for anything to work. Hooking it up is optional, but it's worth doing. Your loop can then read GA4's numbers for each variant (engagement, time on page, conversions) and use them when it decides what to promote and what to try next. You also get to slice your own GA4 reports by test and variant.
It takes three steps, about 5 minutes total.
1. Connect GA4 and map your site
In VariFlask, go to Settings > Integrations, connect Google Analytics, then pick the GA4 property for each site.
We only ask for read access. We never change anything in your GA4.
2. Send test events to GA4
Open your site in VariFlask and find the GA4 event forwarding card on the Integrations tab. We check your GA4 for you and tell you what to do:
- We recommend turning this on. Your GA4 isn't getting test events yet. Click Turn on and we send them for you.
- Leave this off. Your GA4 already gets our test events, most likely from your own GTM tags. Turning it on would count each event twice.
- On. We're already sending them.
When you map a site that isn't getting test events yet, we turn this on by ourselves. If you switch it on or off by hand, we never change your choice.
It works whether GA4 is installed through Google Tag Manager or gtag.js. You don't need to add any GTM tags.
What we send
Three events, each with these parameters:
| Event | When it fires |
|---|---|
experiment_assigned |
A visitor is put into a test on a page |
experiment_impression |
The changed part of the page scrolls into view |
experiment_conversion |
The visitor hits one of the test's goals |
| Parameter | What it is |
|---|---|
experiment_id |
Which test the visitor saw |
variant_id |
Which variant the visitor saw |
experiment_name |
The test's name |
variant_name |
The variant's name |
is_control |
true for the original page |
goal_id |
The goal that was hit (conversions only) |
The snippet also pushes the same events onto window.dataLayer, so you can
use them in GTM if you want.
3. Add three custom dimensions in GA4
GA4 ignores event parameters and user properties until you register them. Add these three, once per GA4 property:
- In GA4, go to Admin > Custom definitions > Custom dimensions.
- Click Create custom dimension.
- Set Scope to Event. Set both Dimension name and Event
parameter to
experiment_id. Save. - Do the same for
variant_id. - Create one more with Scope set to User. Set both Dimension
name and User property to
vf_variant. Save.
| Dimension name | Scope | Event parameter or user property |
|---|---|---|
experiment_id |
Event | experiment_id |
variant_id |
Event | variant_id |
vf_variant |
User | vf_variant |
Why the third one? experiment_id and variant_id only sit on our test
events. A purchase happens later, on its own purchase event, so GA4 can't
link it to a variant from those two. vf_variant is saved on the visitor
instead, so GA4 attaches it to everything they do afterwards, purchases
included. It holds the first 8 characters of each variant ID the visitor is
in (up to 4 tests), like d5fe5f20,1a2b3c4d.
The VariFlask GA4 card shows which of the three you've added.
Don't see a name in GA4's list? Just type it in. GA4 only lists names it has already seen, and it won't see these until test events start reaching it. You can add the dimensions before that happens.
You can also add experiment_name and variant_name (Event scope) if you want nicer labels
in your own reports.
GA4 takes about 24 to 48 hours to fill in new custom dimensions. Until then
your reports show (not set) for them, and the loop just skips the GA4 check.
How to tell it's working
- Right away: open GA4 > Reports > Realtime, then load a page with a
running test in another tab. You should see
experiment_assignedin the event list within a minute or so. - In VariFlask: the GA4 confirmatory signal card on your site turns green once GA4 starts returning numbers per variant, usually a day or two after you add the dimensions.
Purchases on Shopify
GA4 is a second opinion. For winners picked on orders, turn on purchase tracking in VariFlask too. It counts each order against the variant the buyer saw, without waiting on GA4.
Open your site in VariFlask, then the Track purchases card on the Integrations tab:
- With the VariFlask Shopify app: it's turned on for you. Approve the updated app permissions if Shopify asks.
- Without the app: copy the pixel code from the card, then in Shopify go to Settings > Customer events > Add custom pixel, paste it, Save, and Connect.
Once it's live, new tests on that store use Purchase as their main goal, and each test shows orders, revenue, and revenue per visitor for each variant. Orders placed within 7 days of the buyer's last store visit count.
Already sending these from GTM?
Some people set up GTM tags for our events by hand before we could send them. If that's you, leave GA4 event forwarding off. Our check spots this and tells you to keep it off.
If you'd rather keep doing it in GTM, here's the setup:
- Create a Data Layer Variable for each of
experiment_id,variant_id,experiment_name,variant_name,is_controlandgoal_id. - Create a Custom Event trigger. Turn on regex matching and use
^experiment_(assigned|impression|conversion)$. - Create a GA4 Event tag. Set your measurement ID, set Event Name to
{{Event}}, and add the parameters above, each pointing at its Data Layer Variable. Fire it on the trigger from step 2. - Test it in GTM Preview, then publish the container.
How VariFlask uses the numbers
Every 6 hours we pull sessions and engaged sessions for each variant from GA4,
plus purchases and purchase revenue once vf_variant is registered.
Continuous Loops use these as a second opinion:
- If our tracking says "promote" but GA4 points the other way, the round is held back as inconclusive.
- If our tracking is inconclusive but GA4 shows a clear lift (more than 10%) either way, the round can move to promote or hold.
- Rounds that just need more visitors never get promoted on GA4 alone.
So the tests you run get checked against the analytics your team already trusts.