Skip to content

Track behavior in Google Analytics 4

Osvaldo edited this page Sep 25, 2023 · 5 revisions

With Abrantes you can track in Google Analytics 4 not only the variants that convert better, you can track all user behavior in all pages in an experiment. All you need is that a GA event is triggered in a page. This includes automatically collected events.

First you'll need a custom dimension to track the experiment results. You'll need to have one custom dimension for each simultaneous experiment on the same page or that share the same goal page. However, to keep things simple, it's advisable to have one custom dimension for each simultaneous experiment on the same site. For most websites 2 to 5 reusable dimensions is enough. You can name them experiment_1, experiment_2...

  • On your GA4 propriety go to Admin > Custom definitions
  • Click the blue button "Create custom dimension"
  • Dimension name can be, for example, "Experiment 1"
  • Scope should be always "Event"
  • Description anything you want, but please note that it's advisable to reuse this custom dimension in future experiments
  • Event parameter should be for example "experiment_1". You should name it lowercase and snake case as in this example.
  • Click save and done

Now to store data in this custom dimension your experiment should use:

MyTest.track("experiment_1");

Please note "MyTest" is an example and should match the name used to create the object in the previous line:

var MyTest = Object.create(Abrantes);

That's it, now Abrantes can store all behaviors in Google Analytics 4 and it's time to create reports.

Creating reports in Google Analytics 4

Please note that GA4 does not allow you to access data about the current day and in some cases it will take more than 24h until the full data is available. It's easier if you do the report at least 24h after starting the experiment, as you'll be able to see how data is presented.

Free form explorations

  • Go to explorations and create a new exploration. Give it a descriptive name.
  • Add the event name and your experiment 1 dimension to dimensions
  • As a metric use the event count
  • Technique is free form for now
  • Start with a table as visualization method
  • In rows you can have your "Experiment 1" dimension
  • In values add the event count
  • Cell type can be the default "Bar chart"

Now the important part. You'll need two tabs. One for page views (people added to one of the experiment's variations) and another tab with the conversion event.

On the page views tab:

  • Use event name exactly matches page_view in the filter
  • Use "Experiment 1" contains your experiment name as defined in MyTest.assignVariant("MyTest"); In the examples it's "MyTest".
  • If the AB test has more than one page in the user flow, you might need to add "Page path and screen class" as a dimension and then as a filter to ensure you'll measure users just once when they enter the experiment.

On the conversions tab it's the same, but instead of page_view you use the conversion event. If that event has to happen in a specific page or pages use the "Page path and screen class" filter.

Please note that if for some reason the page_view and your usual conversion event don't work or lead to misleading results, you can always create Google Analytics custom events, either to mark that a user has entered the experiment or that it has converted.

Funnel explorations

Funnels can measure users and sequences of events, and are ideal to measure an AB test. With Abrantes you can create multiple funnels focusing on different aspects of the experiment.

  • The dimensions should be event name and the dimension used to measure the experiment, for example "Experiment 1"
  • Technique: funnel exploration
  • Visualization: standard funnel
  • Steps: usually the first is page_view and the last the conversion event
  • Breakdown is the dimension used for the test. In this example "Experiment 1"
  • Finally as a filter you should use that your dimension (for example "Experiment 1") contains the assignVariant parameter.