Google Analytics is an analytics service that enables you to measure traffic and engagement across your websites and apps. Google Analytics 4 is the latest version of Google Analytics.
The Google Analytics 4 integration allows you to receive the audience created in Google Analytics and to target them with AB Tasty.
⭐ Good to know: Google Analytics 4 Audiences
Audiences are groups of users defined by a chosen set of criteria. Dimensions, metrics, and events can be used to segment practically any subset of users.
For more information on how to use audiences please refer to the Google Analytics 4 documentation.
To achieve Google Analytics 4 audiences targeting, we push our own unique identifier (AB Tasty visitor ID) in a user property for every session and then list the value of this user property for the different existing audiences through Google Analytics’s API. Then audiences and their composition are pushed to AB Tasty at the beginning of the next day.
Thus, the Google Analytics 4 integration set up process is taking place on several platforms :
- Google Cloud Platform: to create the credentials to access Google Analytics data.
- Google Analytics 4: to set up the collection of the AB Tasty visitor ID
- AB Tasty: to effectively set up the integration
An email account with admin access to Google Analytics 4 account is required to complete the setup.
Create the credentials on Google Cloud Platform
To access Google Analytics 4 API programmatically we need to have credentials with granted accesses. Those are OAuth type of credentials and are created within the Google Cloud Platform.
Access a GCP project
- Go to the Google Cloud Platform console
- Select an existing project or create a new one. (Documentation to create a new project)
Activate the Google Analytics 4 API
- In the Google Cloud Platform interface, open the console left side menu and select APIs & services
- On the left, click Library, search for the “Google Analytics Data API” and select it. Click “Enable”.
OAuth consent screen setup
Before creating the OAuth credentials you need to check that you have an OAuth consent screen setup. If you don’t, you need to set it up (if you just created the GCP project it will be the case). The OAuth consent screen is the screen that will appear when you will give access right to your credentials.
Check the OAuth consent screen: Open the console left side menu and select APIs & services : click Credentials>Create Credentials>OAuth consent screen. If you see an app already exists here, it means the consent screen is set up and you can proceed to the next step: Oauth Credentials creation.
If there is no existing app, you will see the first step of the creation process:
- Choose the “Internal” option if you are a Google Workspace user, otherwise choose “External”. Click the create button.
- Under App information, enter an App name. It can be something similar to the project name.
- User support email: enter your email address (the one used to connect to GCP)
- Developer contact information, email address: enter your email address (the one used to connect to GCP)
- Other fields are optional, click “Save and continue”.
- Click “Add or remove scopes”
- Tick the “.../auth/userinfo.email” scope. Validate by clicking the “Update” button.
- Click “Save and continue”.
- Add your email address (the one used to connect to GCP) as a test user. Click “Save and continue”.
- You are at the summary screen, the OAuth consent screen is now ready and you proceed to the OAuth Credentials creation step.
OAuth Credentials creation
- Open the console left side menu and select APIs & services
- On the left, click Credentials>Create Credentials>OAuth client ID
- Select “Web Application” as the Application type. Enter a descriptive name of your choice e.g. “GA4 to AB Tasty Audience bridge”.
- Under “Authorised redirect URIs” add “https://developers.google.com/oauthplayground”
- Other fields are optional, click “Create” to finalise the OAuth credentials creation.
- A confirmation message appears, it also displays the Client ID and the Client Secret of your Oauth credentials. Copy-paste and save for later (you can also download them in a json format).
Give Google Analytics access rights to your OAuth Credentials
- Go to the Google OAuth Playground
- Open the configuration panel and tick the “Use your own OAuth credentials”. The “OAuth Client ID” and “OAuth Client secret” fields appear.
- Fill the “OAuth Client ID” and “OAuth Client secret” fields with your own (saved from the previous OAuth Credentials step)
- In the left panel, Step 1 “Select and authorize APIs”, search for “Analytics Reporting API v4” and tick the 2 items underneath ("https://www.googleapis.com/auth/analytics" and "https://www.googleapis.com/auth/analytics.readonly")
- Click “Authorize APIs”
- The Google Access Right interface appears : select the account with which you have access to the Google Analytics property and then click “authorize” to grant access.
- You are redirected to the Oauth Playground, Step 2. Click “Exchange authorization code for tokens”
- “Refresh token” field is now populated, copy and save the content of the field.
Congratulations you now have all the required information to set up the integration on AB Tasty interface (see next step).
For more information on Oauth Playground please refer to this documentation.
Enable the integration on AB Tasty
- Go to Profile> Integrations>DMP & CRM Onboarding
- In the “Other CDP/CMP tools” box, select “Google Analytics 4 Audiences” and click the connect button.
- You have different field to fill in to set up the integration :
- Property ID : it is the unique ID of your GA4 property. To retrieve your Property ID go to the Google Analytics interface and click Admin>Property>Property Settings. Property ID appears at upper right. More information here.
- GA Measurement ID : it is the unique ID of a data stream (i.e. one of the data sources that provides data to your property). To retrieve your GA Measurement ID go to the Google Analytics interface and click Admin>Property>Data Streams> Web and choose your data stream. GA Measurement ID appears at upper right. More information here.
- Client ID: part of the credentials to be able to access Google Analytics Data (see previous steps)
- Client secret: part of the credentials to be able to access Google Analytics Data. Copy paste the value saved from the previous steps
- Refresh Token: part of the credentials to be able to access Google Analytics Data. Copy paste the value saved from the previous steps
Configure the custom definition on Google Analytics 4
To push the AB Tasty Visitor ID we use a user property named “ab_tasty_visitor_id” that is sent with an event named “abtasty”. Thus we need to set up the collection of the custom definition.
The AB Tasty Visitor ID is then pushed back to AB Tasty for targeting.
- In the left panel Click “Configure” then “Create custom dimensions”
- Enter the “Dimension name” you want to display in Google Analytics 4 e.g. “AB Tasty Visitor ID”
- Select “User” as the scope
- Enter a description (optional)
- Enter “abtasty_visitor_id” as the “User property
- Click “Save”
Congratulations, integration is now setup and you can target your Google Analytics 4 Audiences with AB Tasty. For information on how to use your audiences, please refer to this documentation.
⭐ Good to know: Technical specifications
- Audiences will be refreshed daily
- AB tasty pushes the “abtasty_visitor_id” to Google Analytics 4 with the “abtasty” event, thus once integration is set up the “abtasty” event and “abtasty_visitor_id” will be visible on the Google Analytics 4 interface.
- The abtasty_visitor_id is used to achieve user matching.
- For the audiences to be used in AB Tasty’s segment builder (once exported from Google Analytics 4), we need to match at least one user i.e. empty audiences will not be displayed in the segment builder.
- For the audience to be visible in the segment builder you need to wait 24 hours after the setup of the integration. This is due to the different synching mechanisms between the tools (data collection by Google Analytics 4 and then the data import from Google Analytics 4 to AB Tasty).