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