Google Analytics Api
Setting Up Google Analytics Variables for GA4 Integration
Last updated
Setting Up Google Analytics Variables for GA4 Integration
Last updated
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=
GOOGLE_ANALYTICS_GA_ID
:Go to .
Set up a new GA4 property and obtain the Measurement ID (e.g., G-XXXXXXX
).
GOOGLE_ANALYTICS_PROPERTY_ID
:In Google Analytics 4 (GA4), select your property.
Click the gear icon (⚙️) at the bottom left to open Admin settings.
In the Property column (middle section), click Property Settings.
Your Property ID will be displayed at the top of the page in this format: XXXXXXXXX
.
GOOGLE_ANALYTICS_CLIENT_EMAIL
and GOOGLE_ANALYTICS_PRIVATE_KEY
:Steps:
Enable the Analytics Data API:
Go to the Google Cloud Console.
Create or select a project.
Enable the Analytics Data API.
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
.
In your GA4 property, go to Admin → Account Access Management.
Add the service account email (e.g., service-account-name@project-id.iam.gserviceaccount.com
) with Viewer or higher permissions.