Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideProduct feedbackGitHubNuGetDev CommunitySubmit a ticketLog In

Integrate Google Analytics 4 audiences

How to import your Google Analytics 4 (GA4) audiences to Optimizely Web Experimentation.

πŸ‘

Beta

Integrating Google Analytics 4 (GA4) audiences is currently in beta. Contact your Customer Success Manager or sign up for the beta on Optimizely.com.

You can use your Googe Analytics 4 (GA4) audiences to act on insights gathered from experiment results with your GA4 integration. This lets you target experiments based on segments in GA4 without the need for custom development.

Using GA4 audiences unlocks new targeting capabilities within Web Experimentation. For example, GA4 has demographics-based audience creation (age and gender) and predictive audience identification for potential purchases within a specified timeframe. Watch the video or use the interactive demo to learn how to use this feature.

Prerequisites

  • An Optimizely Web Experimentation account.
  • An existing Google Analytics 4 property.

Connect GA4 with Optimizely Web Experimentation

  1. Go to Settings > Integrations > Google Analytics 4 Audience Targeting.

  2. Toggle the integration status to On and click Accept on the Add-On Platform Terms of Service page.

  3. Click Sign in with Google and enter the required information to connect Optimizely Web Experimentation with your Google account.

  4. If prompted, select all options to grant Optimizely access your Google Account. Click Allow.

  5. Click Edit next to Settings. Enter your 9-digit Google Analytics Property ID. See Google's documentation for help locating your property ID.

  1. Input your Google Analytics User ID which is a variable or function name that retrieves the User ID or Device ID stored in GA4. This is dependent on your GA4 configuration.

    🚧

    Important

    You would leverage User ID if you bring your own identifiers to GA4. Meanwhile, Device ID gets its value from the client ID property of the _ga cookie, the default option if you did not set up a connection to bring in identifiers from other systems.

    The field input is the function name, such as get_ga_id.

    Note: This code snippet must be implemented in either Optimizely's projectJS or in your source code before the Optimizely snippet.

    //A sample function call that returns the device ID (_ga cookie)
    //The function would be different if you send a specific identifer type to GA4
    //This call  must be implemented in project JS or before the Optimizely snippet
    
    window['optimizely'] = window['optimizely'] || [];
     
    window['get_ga_id']=function(){
      console.log('GA4 Audience looking for _ga cookie');
      let myCookie = '';
      const value = '; ' + document.cookie;
      const parts = value.split('; _ga=');
      if (parts.length == 2)
          myCookie = parts.pop().split(';').shift();
     
      const regex=/^GA\d\.\d\./;
      if(regex.test(myCookie))
        myCookie = myCookie.replace(regex, '');
     
      console.log('GA4 Audience returning value: '+myCookie);
      return myCookie;
    };
    
  2. Click Save.

Target experiments using GA4 audiences

After connecting GA4 to Optimizely Web Experimentation you can target experiments using GA4 audiences:

  1. Go to Audiences > Create New Audience.

  2. Enter the audience Name.

  3. Expand Google Analytics 4.

  4. Drag and drop your GA4 audience to the Audience Conditions section.

  5. Configure the audience as desired using the drop-down list.

  6. Click Save Audience.

See the end-user documentation on Target audiences using the Audience Builder for more information on configuring audiences.

πŸ“˜

Note

Each visitor's inclusion to a GA4 audience is updated on a daily basis as GA4 has up to a 48-hour data processing delay. To ensure accurate audience membership into an experiment, do not run an experiment targeting a GA4 audience that was created and is currently active in a running experiment via Report Generation.