> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mainwp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Analytics

> The MainWP Google Analytics Extension gives you the ability to view your Google Analytics data for your child sites in your MainWP Dashboard. It adds a widget to your main dashboard where you can monitor Google Analytics data from.

<div id="addon-data" style={{display: 'none'}} data-title="Google Analytics" data-purchase-url="https://mainwp.com/extension/google-analytics/" data-pricing-tier="pro" data-bundle="MainWP Pro" data-addon-type="integration" data-version="5.0" data-developer="MainWP" data-changelog-url="https://mainwp.com/changelog/mainwp-google-analytics-extension/" data-integrates-with="Google Analytics" data-owned-by="Google LLC" data-privacy-url="https://policies.google.com/privacy" />

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

***

<Info>
  **Integration Add-on** - This add-on extends MainWP to work with Google Analytics. Requires Google Analytics to be installed on your child sites.
</Info>

<iframe src="https://www.youtube.com/embed/JX0lM20ShjA" title="Google Analytics video tutorial" className="w-full aspect-video rounded-xl" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowFullScreen />

The [MainWP Google Analytics Extension](https://mainwp.com/extension/google-analytics/) 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):

<img src="https://mintcdn.com/mainwp/N50GAiWDBzkdyfTh/images/add-ons/sign-with-google.png?fit=max&auto=format&n=N50GAiWDBzkdyfTh&q=85&s=90c3842f4f78531e2b7d12707d5611a5" alt="Google Analytics Add Account page with Sign In with Google and Import JSON File options" width="1885" height="825" data-path="images/add-ons/sign-with-google.png" />

### 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 [MainWP Bridge](/advanced/miscellaneous/mainwp-bridge) and the [MainWP Bridge Privacy Policy](https://mainwp.com/mainwp-bridge-privacy-policy).

<Warning>
  If HTTP basic auth protects your MainWP Dashboard before it has paired with MainWP Bridge, **Sign In with Google** can fail because MainWP Bridge must be able to reach your Dashboard. If you need to keep HTTP basic auth enabled, use **Import JSON File** instead.
</Warning>

### Option B: Connect a Service Account (JSON file)

**Step 1 - Enable required APIs in Google Cloud Console**

<Steps>
  <Step title="Go to https://console.cloud.google.com and create a new project (optional).">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-new-project-dialog.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=c79aa060e3389150df50c1769b4936c0" alt="Google Cloud Console new project creation dialog" width="941" height="992" data-path="images/add-ons/ga-new-project-dialog.png" />
  </Step>

  <Step title="Open APIs & Services > Enabled APIs & services.">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-apis-services-nav.gif?s=e60ff1e57ff409d616d6886943808404" alt="Animation showing navigation to APIs and Services in Google Cloud Console" width="517" height="601" data-path="images/add-ons/ga-apis-services-nav.gif" />
  </Step>

  <Step title="Enable the required APIs.">
    Enable:

    1. **Google Analytics Admin API**
    2. **Google Analytics API**
    3. **Google Analytics Data API**

    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-api-library-apis.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=2264c9d74134370213681c294fa7b71f" alt="Google Cloud API Library showing required APIs to enable" width="884" height="847" data-path="images/add-ons/ga-api-library-apis.png" />

    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-enable-api.gif?s=89c9a3c02dc449d554ab97ac1b265196" alt="Animation showing how to search and enable APIs in Google Cloud" width="1199" height="759" data-path="images/add-ons/ga-enable-api.gif" />
  </Step>
</Steps>

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

<img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-service-account-create.gif?s=4ab91af27817c96f830d3929a4136406" alt="Animation showing Service Account creation in Google Cloud Console" width="625" height="679" data-path="images/add-ons/ga-service-account-create.gif" />

<img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-json-key-download.gif?s=585833b1ebbaf38c9bd7be82c0f0dce8" alt="Animation showing how to create and download a JSON key for Service Account" width="1427" height="846" data-path="images/add-ons/ga-json-key-download.gif" />

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

<Steps>
  <Step title="Go to your Google Analytics Dashboard and open Admin.">
    Go to [Google Analytics Dashboard](https://analytics.google.com/) and open Admin settings.
  </Step>

  <Step title="Choose account-level or property-level access.">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-admin-access-settings.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=2a66f582e85b0ae3eda06dac467dee3b" alt="Google Analytics Admin settings showing account and property access options" width="1200" height="1192" data-path="images/add-ons/ga-admin-access-settings.png" />
  </Step>

  <Step title="Click Add users.">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-add-users-button.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=c4dc3c164ed8761a5abce5ef5ec39071" alt="Google Analytics Access Management with Add users button" width="1255" height="265" data-path="images/add-ons/ga-add-users-button.png" />
  </Step>

  <Step title="Copy the Service Account email from Google Cloud Console.">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-service-account-email.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=e8167add3f44bc6757ade09077e4e99b" alt="Google Cloud Console Credentials page showing Service Account email" width="1422" height="509" data-path="images/add-ons/ga-service-account-email.png" />
  </Step>

  <Step title="Paste the email, set role to Viewer, and click Add.">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-add-users-form.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=ad4dc1b11ffe6d0d170da880d218e345" alt="Google Analytics Add users form with email field and Viewer role" width="1246" height="1051" data-path="images/add-ons/ga-add-users-form.png" />
  </Step>
</Steps>

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

<img src="https://mintcdn.com/mainwp/0ngAbmgMtzBUDiO6/images/add-ons/import-json.png?fit=max&auto=format&n=0ngAbmgMtzBUDiO6&q=85&s=87221e5030fcad16ea1bbb875b5a9e2e" alt="MainWP Google Analytics Add Account page with JSON file upload" width="1909" height="772" data-path="images/add-ons/import-json.png" />

**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:

<Steps>
  <Step title="Go to MainWP > Sites > Manage Sites.">
    <img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-manage-sites-nav.gif?s=5172cb99ed70393632eaf31ec134480f" alt="Animation showing navigation to Manage Sites page" width="856" height="476" data-path="images/add-ons/ga-manage-sites-nav.gif" />
  </Step>

  <Step title="Open the child site Settings page.">
    Locate the site and click its name to open Settings.
  </Step>

  <Step title="Select the matching Google Analytics property.">
    Find the **Google Analytics** section and choose the **Google Analytics property**.
  </Step>

  <Step title="Click Save Settings." />
</Steps>

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

<img src="https://mintcdn.com/mainwp/prJFyo89l1sl-7Fz/images/add-ons/ga-visitor-data-page.gif?s=8c0e5a95468a12231a06c363ca1c8383" alt="Animation showing Google Analytics Visitor Data page with analytics widgets" width="1440" height="810" data-path="images/add-ons/ga-visitor-data-page.gif" />

You can enable or disable widgets in [Page Settings](/getting-started/mainwp-user-interface), and rearrange them as needed.

<img src="https://mintcdn.com/mainwp/prJFyo89l1sl-7Fz/images/add-ons/ga-widget-rearrange.gif?s=31b38a8d40066d67487cbfd9f0d89076" alt="Animation showing how to rearrange widgets in Page Settings" width="1440" height="810" data-path="images/add-ons/ga-widget-rearrange.gif" />

To change the child site, select it from the site dropdown.

<img src="https://mintcdn.com/mainwp/prJFyo89l1sl-7Fz/images/add-ons/ga-site-dropdown.gif?s=990fb6255acee37ccd4cd6bc4b5c6009" alt="Animation showing Child Site selection dropdown for analytics data" width="1440" height="810" data-path="images/add-ons/ga-site-dropdown.gif" />

## 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](/getting-started/mainwp-user-interface), and they can be rearranged as needed.

<img src="https://mintcdn.com/mainwp/0ngAbmgMtzBUDiO6/images/add-ons/ga-widget.png?fit=max&auto=format&n=0ngAbmgMtzBUDiO6&q=85&s=a65d5bd4243cd16cde5bef6a54e388ed" alt="Google Analytics widget on the Overview page displaying visitor statistics" width="1388" height="990" data-path="images/add-ons/ga-widget.png" />

## 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 with Google shows `site secret not found`**

* This error usually means the default WordPress REST API endpoint at `/wp-json/` is blocked, disabled, filtered, or behind authentication.
* Make sure your MainWP Dashboard allows access to `/wp-json/`.
* If HTTP basic auth protects your MainWP Dashboard, **Sign In with Google** can fail because MainWP Bridge cannot complete the initial pairing or re-registration check.
* If you need to keep HTTP basic auth enabled, use **Import JSON File** instead.

**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**

**Required PHP functions missing**

* Google Analytics requires `bccomp`, `putenv`, and `getmypid`.
* If Google Analytics data is unavailable, review [Required PHP Functions for MainWP](/advanced/miscellaneous/required-php-functions-for-mainwp) to check whether these functions are disabled on your server.

<img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-service-account-disabled.png?fit=max&auto=format&n=m5iWPkGmGTv3i5YV&q=85&s=fb8a8188095931915336a4cf440a1752" alt="Google Cloud Console showing disabled Service Account status" width="569" height="518" data-path="images/add-ons/ga-service-account-disabled.png" />

<img src="https://mintcdn.com/mainwp/m5iWPkGmGTv3i5YV/images/add-ons/ga-new-json-key.gif?s=46b06acaf54e44ccbcdc56e5ae3fb79f" alt="Animation showing how to create a new JSON key from Service Account" width="730" height="834" data-path="images/add-ons/ga-new-json-key.gif" />

***

## Related Resources

* [Analytics Add-ons](/add-ons/analytics) - Browse all analytics integrations
* [Pro Reports Extension](/add-ons/agency/pro-reports-extension-overview) - Include analytics data in reports
* [Available Pro Reports Tokens](/add-ons/agency/available-pro-reports-tokens) - Google Analytics tokens
* [MainWP Bridge Privacy Policy](https://mainwp.com/mainwp-bridge-privacy-policy) - Privacy details for Bridge-based sign in
