Google Analytics

Uniform enables you to add personalization and testing capabilities to your applications. Google Analytics is a popular product for capturing and reporting on activity in your application. Uniform is able to push personalization and testing data to Google Analytics, improving the reach of your analytics.


This analytics integration in Uniform is for GA4. The previous generation product, (Universal Analytics), is being deprecated by 1st July 2023. You can learn more about Universal Analytics and its corresponding Uniform integration.

This section describes how to activate tracking personalization and testing from Uniform in GA4.

In GA4, Event title and Event Category are deprecated in favor of parameters. To provide backward compatibility on tracking variants for personalization and tests on Uniform without title and category, you are required to manually create these custom dimensions for events in your Google Analytics dashboard.

  1. Log into Google Analytics.

  2. Navigate to your GA4 property.

  3. Navigate to Configure > Custom definitions.

  4. Add the following custom dimensions:

    Dimension nameScopeEvent parameterNotes
    Event CategoryEventevent_category
    Event LabelEventevent_label
    Is Control GroupEventis_control_groupLearn more about control groups for Uniform.

The Uniform tracker can dispatch event data to Google Analytics using a plugin. You must add this plugin to your front-end application.

  1. If your application doesn't already use the Google Analytics global site tag (gtag.js), you must add the script.

    About this step

    In a web application, the global site tag must be added immediately after the head tag is closed, meaning it must be the first thing after </Head>.

  2. Add the following npm packages to your front-end application:


    About this step

    Make sure the package you add is version is 16.3 or greater.

  3. Add the Google Analytics plugin to the Uniform Context object.

    import { enableGoogleGtagAnalytics } from '@uniformdev/context-gtag'; ... const gaPlugin = enableGoogleGtagAnalytics({ emitAll: true }); const context = new Context({ ... plugins: [gaPlugin] }); ...

    About this step

    The Uniform Context object is passed to the tracker. The precise code used to add the tracker to your application depends on your front-end. For more information about the tracker, see the guide on how to add the Uniform tracker.

The plugin causes the tracker to fire GA4 events when Uniform
renders personalized components or variants for A/B tests on your application. Each event is accompanied by its corresponding event_label, event_category, and is_control_group values.