Skip to main content
Google Analytics
Updated over 2 weeks ago

The MainWP Google Analytics Extension gives you valuable insights into your visitor’s search and traffic patterns, your marketing campaigns, and much more, allowing you to optimize your strategy and the online experience of your users.

Use this Extension To Track:

  • Views

  • Views by Page

  • Users

  • Users by Device

  • Users by Country

  • New Users

  • Average Engagement Time

  • Sessions by Source

NOTE: Due to the change in authentication method, users updating to version 4.1 of the extension will have to re-add their Google Analytics account by following the steps below.

Establishing a connection with Google Analytics Account

  1. Follow the steps outlined in this Google Analytics help document to create a new GA4 property if you don’t already have one, and add a Web data stream: https://support.google.com/analytics/answer/9304153

  2. Then go to your Google Cloud Console: https://console.cloud.google.com

  3. Create a new Project or select an existing one

  4. Navigate to APIs & Services > Enabled APIs & services

  5. Here we need to enable 3 APIs:

    1. Google Analytics Admin API,

    2. Google Analytics API, and

    3. Google Analytics Data API


  6. Search for them one by one, and Enable them

  7. Navigate to OAuth consent screen, select External, and click Create


  8. Next,

    1. Give it a descriptive App name

    2. Select a user support email from the dropdown menu

    3. Add your MainWP Dashboard domain under the Authorized domains

    4. Enter an email for a Developer contact information

    5. Click Save and Continue

  9. On the next screen, Scopes, don’t make any changes and click Save and Continue

  10. Same as with Scopes, don’t make any changes on the Test users screen and click Save and Continue

  11. On Summary screen, click Back to Dashboard, and click the PUBLISH APP button

  12. Next, Navigate to Credentials, click the + CREATE CREDENTIALS button, then OAuth client ID

  13. Select Web application

  14. Give it a desired name, and in the Authorized redirect URIs section, click the + ADD URI button, and enter https://your-dashboard-url.com/wp-admin/admin.php?page=Extensions-Mainwp-Google-Analytics-Extension&mainwp_ga=1
    NOTE: Replace the your-dashboard-url.com with your actual Dashboard URL

  15. Then click the Create button


    NOTE: We will not be using this OAuth 2.0 Client IDs JSON file, so there is no need to download it.

  16. Click the + CREATE CREDENTIALS button again, and this time, select Service Account

  17. Give it a desired name, and click Done

  18. Now click on the newly created Service Account, then KEYS tab

  19. Then click on the ADD KEY button, then Create new key

  20. From the popup modal, select JSON and then CREATE

  21. JSON file will be downloaded automatically to your computer

  22. Now navigate back to your Google Analytics

  23. Open the Admin settings for your GA4 property, and open Property Access Management


  24. Click on the Add users button

  25. The email address we want to add can be found on the Credentials page on the Google Cloud Console

  26. Enter it in the Email addresses field, set the role as Viewer, and click Add

    IMPORTANT NOTE: Repeat steps 23 to 26 for each GA4 property you wish to see the data for in the MainWP Google Analytics extension

  27. Now navigate to your MainWP Dashboard > Extensions > Google Analytics > Add Account page, and upload the JSON file, which was downloaded automatically

  28. The account should now be visible in the Manage Accounts tab



    NOTE: Multiple Google Accounts can be added by repeating the same process.

Important Notes:

The Google Analytics Extension doesn’t allow you to insert the Google Analytics tracking code on your child sites. To do that, you will need to add the code manually or use a 3rd party plugin.

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

  1. Go to the MainWP > Sites > Manage Sites page

  2. Locate the desired child site and click the Edit action

  3. Locate the Google Analytics section

  4. Select the correct property in the Google Analytics account property option

  5. Click the Save Settings button

  6. Repeat the process for all your child sites

  7. When you are done, you will see those sites in the dropdown on the Extensions > Google Analytics > Visitor Data page

Google Analytics Visitor Data

After you connect your Google Analytics account and assign GA4 properties to your Child Sites, you will be able to see all Google Analytics data on the Extensions > Google Analytics > Visitor Data page.

You can disable and enable widgets in the Page Settings, and you can re-arrange them in any way you wish.

To change the Child Site, simply select it from the dropdown menu.

Widgets

Google Analytics widget will be added to the Overview page and on the Individual Child site Overview page.

As always, the widgets can be enabled or disabled in the Page Settings, and they can be re-arranged however you wish.

Resolve the issue with account Disconnection

If the Service Account on the Google Cloud Console is temporarily Disabled, the connection may break in the MainWP Google Analytics extension.

To reconnect the Google Analytics account, re-enable the Service Account, and navigate to KEYS. Then from the ADD KEY dropdown, select Create New Key and download the JSON Key file.

You can now upload that JSON Key file on the Add Account page to connect the account.

Did this answer your question?