# Google Analytics Api

The Analytics section is built using the Google Analytics API. Below are the variables you need to configure to make it work:

* `GOOGLE_ANALYTICS_GA_ID=`
* `GOOGLE_ANALYTICS_CLIENT_EMAIL=`
* `GOOGLE_ANALYTICS_PRIVATE_KEY=`
* `GOOGLE_ANALYTICS_PROPERTY_ID=`

#### Retrieving `GOOGLE_ANALYTICS_GA_ID`:

1. Go to [Google Analytics](https://analytics.google.com/).
2. Set up a new GA4 property and obtain the **Measurement ID** (e.g., `G-XXXXXXX`).

#### Retrieving `GOOGLE_ANALYTICS_PROPERTY_ID`:

1. In Google Analytics 4 (GA4), select your property.
2. Click the gear icon (⚙️) at the bottom left to open **Admin** settings.
3. In the **Property** column (middle section), click **Property Settings**.
4. Your **Property ID** will be displayed at the top of the page in this format: `XXXXXXXXX`.

#### Retrieving `GOOGLE_ANALYTICS_CLIENT_EMAIL` and `GOOGLE_ANALYTICS_PRIVATE_KEY`:

**Steps:**

1. **Enable the Analytics Data API**:
   * Go to the Google Cloud Console.
   * Create or select a project.
   * Enable the **Analytics Data API**.
2. **Create a Service Account**:
   * In the Google Cloud Console, go to **IAM & Admin → Service Accounts**.
   * Create a new service account and download the JSON key file.
   * In the JSON file:
     * `client_email` corresponds to `GOOGLE_ANALYTICS_CLIENT_EMAIL`.
     * `private_key` corresponds to `GOOGLE_ANALYTICS_PRIVATE_KEY`.

#### Final Step: Share GA4 Access with the Service Account

1. In your GA4 property, go to **Admin → Account Access Management**.
2. Add the service account email (e.g., `service-account-name@project-id.iam.gserviceaccount.com`) with **Viewer** or higher permissions.


---

# 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://zakariaes-organization.gitbook.io/saascore-docs/configuration/google-analytics-api.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.
