Google Analytics Api
Setting Up Google Analytics Variables for GA4 Integration
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
:
GOOGLE_ANALYTICS_GA_ID
:Go to Google Analytics.
Set up a new GA4 property and obtain the Measurement ID (e.g.,
G-XXXXXXX
).
Retrieving GOOGLE_ANALYTICS_PROPERTY_ID
:
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
.
Retrieving GOOGLE_ANALYTICS_CLIENT_EMAIL
and GOOGLE_ANALYTICS_PRIVATE_KEY
:
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 toGOOGLE_ANALYTICS_CLIENT_EMAIL
.private_key
corresponds toGOOGLE_ANALYTICS_PRIVATE_KEY
.
Final Step: Share GA4 Access with the Service Account
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.
Last updated