Skip to main content

What You’ll Learn

  • Connecting Google Analytics via Sign In with Google or Service Account JSON
  • Assigning GA4 properties to child sites
  • Viewing visitor data across all child sites
  • Managing account refresh and reconnection

Integration Add-on - This add-on extends MainWP to work with Google Analytics. Requires Google Analytics to be installed on your child sites.
The MainWP Google Analytics Extension gives you valuable insights into your visitors’ traffic patterns and campaign performance so you can optimize your strategy and user experience.

Use this Extension To Track:

  • Views
  • Views by Page
  • Users
  • Users by Device
  • Users by Country
  • New Users
  • Average Engagement Time
  • Sessions by Source
Requirements
  • PHP 8.1 or higher on the MainWP Dashboard
  • Google Analytics (GA4) installed on your child sites
  • For JSON import: Google Analytics Admin API, Google Analytics API, and Google Analytics Data API

Connect your Google Analytics Account

You can connect Google Analytics in two ways. Use whichever fits your setup (you can use both): Google Analytics Add Account page with Sign In with Google and Import JSON File options

Option A: Sign In with Google

  1. In your MainWP Dashboard, go to MainWP > Add-ons > Google Analytics > Add Account.
  2. Keep the Sign In with Google tab selected, then click Sign In with Google.
  3. Complete Google authorization in the popup window.
  4. In Select Google Analytics Project, choose the account(s) you want to connect, then click Continue.
  5. In Confirm Google Analytics Connection, review the summary and click Confirm.
  6. Your account will appear under Manage Accounts in Accounts by Sign In.
Notes
  • If your MainWP Dashboard server does not meet the required PHP version, the Sign In with Google tab is disabled and you can use Import JSON File.
  • This flow uses MainWP Bridge (bridge.mainwp.com) for secure authentication. See the MainWP Bridge Privacy Policy.

Option B: Connect a Service Account (JSON file)

Step 1 - Enable required APIs in Google Cloud Console
1

Go to https://console.cloud.google.com and create a new project (optional).

Google Cloud Console new project creation dialog
2

Open APIs & Services > Enabled APIs & services.

Animation showing navigation to APIs and Services in Google Cloud Console
3

Enable the required APIs.

Enable:
  1. Google Analytics Admin API
  2. Google Analytics API
  3. Google Analytics Data API
Google Cloud API Library showing required APIs to enableAnimation showing how to search and enable APIs in Google Cloud
Step 2 - Create a Service Account and JSON key
  1. In APIs & Services, click + Create credentials and select Service Account.
  2. Give it a name and click Done.
  3. Open the new Service Account, then go to the KEYS tab.
  4. Click Add Key > Create new key > JSON > Create.
  5. A JSON file will download automatically.
Animation showing Service Account creation in Google Cloud Console Animation showing how to create and download a JSON key for Service Account Step 3 - Add the Service Account as Viewer in Google Analytics The Service Account can be added as a Viewer to the entire Google Analytics account (all properties) or to specific GA4 properties.
1

Go to your Google Analytics Dashboard and open Admin.

Go to Google Analytics Dashboard and open Admin settings.
2

Choose account-level or property-level access.

Google Analytics Admin settings showing account and property access options
3

Click Add users.

Google Analytics Access Management with Add users button
4

Copy the Service Account email from Google Cloud Console.

Google Cloud Console Credentials page showing Service Account email
5

Paste the email, set role to Viewer, and click Add.

Google Analytics Add users form with email field and Viewer role
If you added property-level access, repeat for each GA4 property you want to use. Step 4 - Connect the JSON key in MainWP
  1. In your MainWP Dashboard, go to MainWP > Add-ons > Google Analytics > Add Account > Import JSON File.
  2. Upload the JSON key file and click Connect Account.
  3. The account will appear under Manage Accounts in Accounts by JSON.
MainWP Google Analytics Add Account page with JSON file upload Important Notes
  • The Google Analytics Extension does not insert Google Analytics tracking code on child sites.
  • Add the tracking code manually or by using a third-party plugin.

Assigning sites from your Google Account to Child Sites in your MainWP Dashboard

The add-on automatically assigns properties to child sites based on URL matching. You can also assign properties manually:
1

Go to MainWP > Sites > Manage Sites.

Animation showing navigation to Manage Sites page
2

Open the child site Settings page.

Locate the site and click its name to open Settings.
3

Select the matching Google Analytics property.

Find the Google Analytics section and choose the Google Analytics property.
4

Click Save Settings.

Google Analytics Visitor Data

After you connect your Google Analytics account and assign GA4 properties to child sites, you can view data on MainWP > Add-ons > Google Analytics > Visitor Data. Animation showing Google Analytics Visitor Data page with analytics widgets You can enable or disable widgets in Page Settings, and rearrange them as needed. Animation showing how to rearrange widgets in Page Settings To change the child site, select it from the site dropdown. Animation showing Child Site selection dropdown for analytics data

Widgets

A Google Analytics widget is available on the MainWP Overview page and on each individual child site Overview page. As always, widgets can be enabled or disabled in Page Settings, and they can be rearranged as needed. Google Analytics widget on the Overview page displaying visitor statistics

Settings & Data Refresh

  • Graphs display interval: Choose Week or Month
  • Fetch Google Analytics data automatically: Enable scheduled data refresh
  • Auto fetch GA data frequency: Set how often automatic refresh runs
  • Save Settings: Save your interval and schedule preferences
  • Refresh Data: Trigger an immediate data refresh

Troubleshooting

Sign-in account needs verification/reconnection
  • Go to MainWP > Add-ons > Google Analytics > Manage Accounts
  • For disconnected Sign In accounts, click Reconnect Account
  • Use Refresh Data after reconnecting
Service Account key disabled or rotated
  • Re-enable the Service Account in Google Cloud Console
  • Create and download a new JSON key from Keys > Add Key > Create new key
  • Upload the new key in MainWP > Add-ons > Google Analytics > Add Account > Import JSON File
Google Cloud Console showing disabled Service Account status Animation showing how to create a new JSON key from Service Account