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, you need to push the Flagship Visitor ID in a user property for every session.
Our integration will 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 Flagship 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 Flagship Visitor ID
- Flagship: 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 Flagship 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.
For more information on Oauth 2.O please refer to this documentation or this documentation.
Enable the integration on Flagship
In the Flagship integrations settings 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
You need to push the Flagship Visitor ID in a user property named “flagship_visitor_id”. Naming is very important because it is what will be pushed back to Flagship.
The user property “flagship_visitor_id” needs to be pushed for every session. This can be achieved thanks to a dedicated event for exemple.
Set the user property:
- In the Google Analytics 4, left panel, click “Configure” then “Create custom dimensions”
- Enter the “Dimension name” you want to display in Google Analytics 4 e.g. “Flagship Visitor ID”
- Select “User” as the scope
- Enter a description (optional)
- Enter “flagship_visitor_id” as the “User property
- Click “Save
Congratulations, integration is now setup and you can target your Google Analytics 4 Audiences with Flagship!
For information on how to use the audiences, please refer to this documentation.
⭐ Good to know: Technical specifications
Need additional information?
Submit your request at firstname.lastname@example.org
Always happy to help!