# Google Analytics 4

### GA4 Script Tag

If you have added the GA4 Script Tag directly to your page's HTML, Optibase will automatically detect it and trigger an event when a Variant is shown to a user.

You do not need to connect Google Analytics to Optibase for that to happen; if you have Google Analytics set up on your website in that way, that is Optibase's default behavior.

The event that Optibase will send will have the name: `optibase_variant_shown`, event\_category `optibase`, and event\_label: `{testId:variantId}`.

### Google Tag Manager

If you have added GA4 through the Google Tag Manager, you must manually set up the trigger and a custom tag. Follow this guide to do that: [Google Analytics 4 with GTM](/integrations/google/google-analytics-4-with-gtm.md)

## Audiences

You can connect your Google Analytics account and property to Optibase by going to the integrations page in the Optibase Web app.

As mentioned before, you do NOT need to connect Google Analytics to Optibase to start collecting events mentioned above.

Connecting your Google Analytics account and property to Optibase allows you to create audiences for Variants automatically through Optibase.

More about Google Analytics Audiences: <https://support.google.com/analytics/answer/12799087>

To automatically create an audience for Variants in a Test for Google Analytics:

1. Connect the Google Analytics account and property you have setup above.
2. Navigate to the Optibase Test you want to import into Google Analytics, go under settings, and click Create Audiences.
3. This will create an Audience for each Variant in that Test. The audience will include everybody who has seen the Variant.
4. You should then see the newly created audiences in Google Analytics.

<figure><img src="/files/oAkv6iy0jo98BrvS6e0T" alt="" width="563"><figcaption></figcaption></figure>

5. You can then click on the Audience to see analytics about users who saw a specific Variant.

Important: It will take 24h/48h for the audiences to accumulate new users.

## Create an Audience for Variant

You can also create an Audience for a Variant when you are creating a Variant:<br>

<figure><img src="/files/MNZgpV66PBNYuPsrjX9n" alt="" width="375"><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.optibase.io/integrations/google/google-analytics-4.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
