# Import Google Analytics Audience to Feature Experimentation

## Pull Google Analytics Audiences

The Google Analytics 4 integration allows you to receive the audience created in Google Analytics and to target them with AB Tasty Feature Experimentation (FE\&R).

{% hint style="info" %}
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](https://support.google.com/analytics/topic/9303474?hl=en\&ref_topic=9143232).
{% endhint %}

To achieve Google Analytics 4 audiences targeting, you need to push the FE\&R 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 FE\&R 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 FE\&R Visitor ID
* FE\&R: to effectively set up the integration

{% hint style="warning" %}
**An email account with admin access to Google Analytics 4 account is required to complete the setup**
{% endhint %}

### 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

![Capture\_d\_e\_cran\_2022-04-13\_a\_\_12.05.40.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FLPbe8nTBCW6FUBiD4Ybc%2Fa2a47d35842a40949018304a09e928a6.png?alt=media\&token=d299e1d1-c9a3-4a20-820d-a8f959b58d1f)

* Go to the [Google Cloud Platform console](https://console.cloud.google.com/)
* Select an existing project or create a new one. ([Documentation to create a new project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_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**”.

![Capture\_d\_e\_cran\_2022-04-13\_a\_\_12.11.33\_\_1\_.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FUjxMiQ8lfFdVAtIpbcd4%2F6e7ef728cf87e48475eade51a9d78a18.png?alt=media\&token=4026a486-e934-4ff1-a60f-ed89fc8b0861)

### OAuth credentials

#### **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.**

![Capture\_d\_e\_cran\_2022-04-20\_a\_\_17.47.03.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FIMahi1CJEBotMLuO0M7y%2F01eeff17827522ed78163e083a88be2f.png?alt=media\&token=3c3e71bc-dfc9-4c46-915b-c6be36b8e413)

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.**

![Capture\_d\_e\_cran\_2022-04-20\_a\_\_17.51.15.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FWzmCs893cUSbjHWOECQ5%2F36045137466e863a40ce20fd77ce329d.png?alt=media\&token=99fdc621-7c13-4002-981f-9fe79f778d82)

* 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”.**

![Capture\_d\_e\_cran\_2022-04-20\_a\_\_17.57.45\_\_1\_.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FIRaH09C7LyKDYZgbdbt0%2F1cd2d86d34ef76d8d2570d03747bda02.png?alt=media\&token=0d4d8d53-8d50-40be-be75-fa16b519c6a6)

* Click “**Add or remove scopes**”
* Tick the “**.../auth/userinfo.email**” scope. Validate by clicking the “**Update”** button.
* **Click “Save and continue”.**

![Capture\_d\_e\_cran\_2022-04-20\_a\_\_18.02.53.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2F3QI9FlYHYV3FX9tNCKbi%2Fd4dc50182f77980af2e2312c42584c60.png?alt=media\&token=512b4115-b451-4f94-8276-d8020cd464b8)

* **Add your email address (the one used to connect to GCP) as a test user. Click “Save and continue”.**

![Capture\_d\_e\_cran\_2022-04-20\_a\_\_18.16.00.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2Fz3Vjl0jxdh3zUePosRMv%2Fd739b2d45040b9fa739013d55798082d.png?alt=media\&token=be7612c8-089d-4ffa-aacd-ce65c7f5a753)

* **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**

![Capture\_d\_e\_cran\_2022-04-13\_a\_\_12.20.45.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FUON9jMk5AZsOEdYq8HFc%2F7b43d0249a94014b217c17c7e1ccab52.png?alt=media\&token=e4d14e06-e305-471b-a0db-c3c820344d77)

* 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.

![credentials\_organizationId\_0\_project\_innovation-183314\_organizationId\_0\_project\_innovation-183314\_\_1\_.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FqPWrx6fdzrg4aD4mdgA4%2F8c9728210c2ce6e7eb3b4b176268b0bf.png?alt=media\&token=daf4ac60-0e69-462a-bbec-1c361f00d033)

* 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).

![Capture\_d\_e\_cran\_2022-04-13\_a\_\_13.28.58.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2F6cTwZvyccozbrvtsNQQu%2F5fbdcc758d70bcc08343701e8c7fffe6.png?alt=media\&token=9dd39101-127d-4d91-90b4-d014f3e83a93)

### Give Google Analytics access rights to your OAuth Credentials

* Go to the [Google OAuth Playground](https://developers.google.com/oauthplayground/)
* 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**”

![Capture\_d\_e\_cran\_2022-04-13\_a\_\_13.38.28.png](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FXtTsjJUsiJXlr3KZtEzU%2F6f3da19fba916cebcf0f634e5c1db8fc.png?alt=media\&token=7f2c0a70-76a6-46f3-88fe-40543127450d)

* 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.

{% columns %}
{% column %}
![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2F5M0NpPlKRIA67D2aclGt%2Fa471d0871da1a4fd5e444a3697017e01.png?alt=media\&token=aef50d1d-5ea2-40e0-88c8-b898f9a661ad)

{% endcolumn %}

{% column %}
![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FD0PpiMDDcbYx2sDN5w4e%2Fe4f2d8f7b10185d578cdfe56b3dc1142.png?alt=media\&token=da15a113-2f77-4a45-96f7-a319010f9d4b)
{% endcolumn %}
{% endcolumns %}

* You are redirected to the Oauth Playground, Step 2. Click “**Exchange authorization code for tokens**”

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2F1TZ9KBqsIztSrgwIXgoK%2F829e145b3a70ecfda6b9e1f071f2fd44.png?alt=media\&token=6f41108a-5c23-4601-843f-110829892f48)

* “**Refresh token**” field is now populated, copy and save the content of the field.

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FMfYToEoWUZSggiJCk3tn%2Fc8545eff8ecd3246ddad3baedf5777d1.png?alt=media\&token=f1f40672-cfa6-4223-b4c1-68e37ea694e4)

Congratulations! You now have all the required information to set up the integration on AB Tasty interface (see next step).&#x20;

<sup>For more information on Oauth Playground please refer to this</sup> [<sup>documentation</sup>](https://developers.google.com/google-ads/api/docs/oauth/playground#remove_the_oauth2_playground_from_your_client_id)<sup>.</sup>

<sup>For more information on Oauth 2.O please refer to this</sup> [<sup>documentation</sup>](https://support.google.com/cloud/answer/6158849) <sup>or this</sup> [<sup>documentation</sup>](https://developers.google.com/identity/protocols/oauth2/web-server)<sup>.</sup>

### Enable the integration on Feature Experimentation

<figure><img src="https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FT8LQPo1vSU20KSOpaUrl%2Fimage.png?alt=media&#x26;token=075a46b0-7557-4594-916f-df3c26024da0" alt=""><figcaption></figcaption></figure>

To enable the GA4 integration on Feature Experimentation, follow the steps below:

1. Access [**Settings > Integrations > Feature Experimentation Tab > Pull**](https://app2.abtasty.com/settings/integration/integration-hub?page=feature-experimentation)
2. Select **Google Analytics 4 > Create**
3. Select your Environment
4. Fill in to set up the integration :

* **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
* **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](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id).

![](https://2350286830-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6Yw9IRJ6KbbucQPwZUCZ%2Fuploads%2FMoeoq2a7gI1FjQGvbpU3%2F1235c10210b1379f54418b1d36a775c9.png?alt=media\&token=1f7b0715-801b-479a-bd0b-7cd23b1f0d0d)

### Configure the custom definition on Google Analytics 4

You need to push the FE\&R Visitor ID in a user property named “flagship\_visitor\_id”. Naming is very important because it is what will be pushed back to FE\&R.

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. “FE\&R 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 global information on how to retrieve audiences, please refer to [this page](https://docs.abtasty.com/flagship-deprecated/integrations/retrieving-your-third-party-tools-audiences-in-ab-tasty-feature-experimentation-rollouts).

{% hint style="info" %}
Technical specifications

* Audiences will be refreshed daily
* The flagship\_visitor\_id is used to achieve user matching. It needs to be collected for every session as a user property and the naming must be respected.
* For the audiences to be used in FE\&R (once exported from Google Analytics 4), we need to match at least one user i.e. empty audiences will not be displayed.
* For the audiences to be visible in FE\&R 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 FE\&R).
  {% endhint %}
