Google Analytics 4 API Setup

This guide walks you through setting up automated GA4 data fetching.

Prerequisites

Step 1: Enable the API

  1. Go to Google Cloud Console
  2. Select the same project used for GSC
  3. Go to APIs & ServicesLibrary
  4. Search for “Google Analytics Data API”
  5. Click Enable

Step 2: Get Your GA4 Property ID

  1. Go to Google Analytics
  2. Select your 360tft property
  3. Click Admin (gear icon)
  4. Under Property Settings, find Property ID
  5. Copy the number (e.g., 123456789)

Step 3: Grant Access to Service Account

  1. In GA4, go to AdminAccount Access Management
  2. Click +Add users
  3. Enter the service account email (same as GSC)
  4. Set role to Viewer
  5. Click Add

Step 4: Add GitHub Secrets

Add these secrets to your GitHub repo:

Secret Name Value
GSC_SERVICE_ACCOUNT Already done ✓
GA4_PROPERTY_ID Your GA4 property ID (e.g., 123456789)

Step 5: Test Locally

cd scripts/ga4

# Copy service account from GSC folder
cp ../gsc/service_account.json .

# Install dependencies
pip install google-analytics-data

# Run with property ID
python fetch_ga4_data.py --property YOUR_PROPERTY_ID

What Data Is Collected

Overview Metrics

Breakdowns

Insights Generated

Output

Reports saved to:

Combined with GSC

When both GSC and GA4 are set up, you get:

GSC GA4
Search queries User behavior
Rankings Bounce rates
Impressions Session duration
Click-through rates Traffic sources
Search performance Engagement metrics

Together: Full picture of how users find your site AND what they do when they arrive.