Welcome to the OpenCities help centre. Search for what you're after, or browse the categories.
Can't find what you're looking for? Submit a support ticket and we'll be in touch.


Connect your OpenCities site with Google Analytics

avatar of OpenCities Product Team

OpenCities Product Team

Last updated

This task is for users with the following roles: OC Site Manager and OC System Administrator.

Before you can start gathering data about your site's performance, you need to connect your OpenCities site with Google Analytics. After you connect with Google Analytics, you can view your site's metric data in Google Analytics itself or use the Insights Dashboard to view a simplified snapshot of measured data.

We know of the transition from Universal Analytics (UA) to Google Analytics 4 (GA4) by July 2023. We have a few options for you, depending on where your organization stands:

  1. If you have previously connected using a UA property and need to start collecting data using GA4, start dual tagging now.
  2. If you have previously started dual tagging and set up your Insights Dashboard, you can now use GA4 with the Insights Dashboard.
  3. If you are a new user or have never connected to Google Analytics, please use the instructions below to connect to Google Analytics 4.

Please note that if you are starting fresh, you only need to connect with GA4. However, while we are in the transition period, the instructions for UA will remain in this article for those who need to reference them.

There are four steps to take when connecting to GA4:

  1. Create a Google Analytics account (if you already have one, skip this step)
  2. Create a GA4 property and get a measurement ID
  3. Add the Search Terms parameter
  4. Insert your GA script into Site Settings
  5. Test your connection

We also have this helpful video which you can follow:

Create a GA4 property

To get started, you will need access to a Google Analytics account for your organization. If you already have one that measured your old site, you can use that one as long as you create a new property for your OpenCities site to keep the data for your new site separate. If you don't have one, you can follow these instructions to create one.

These instructions will take you through creating a GA4 property; you must note down your GA4 Measurement ID as you go.

  1. Log in to your Google Analytics account, then go to Admin Settings by selecting the gear icon in the bottom-left corner.
  2. Select Create Property, and give it a Property name representing GA4 and your site. For example, "GA4 Point Russell Public Site".
    creating a property
  3. Select a Reporting time zone and Currency relevant to your city or council, select Next, specify any Business information you want to include, and then select Create.
  4. Now, set up a data stream by selecting Web.
  5. Enter your Website URL and a Stream name and select Create stream. You'll see the Web stream details page; take note of the Measurement ID. The Website URL needs to be your live site URL, beginning with "www." If you want to connect while pre-live, you can enter your pre-live URL and switch it to the live one after you launch.

Add the Search Terms parameter

Although search results tracking is already enabled for your GA4 property, you'll need to manually add the Search Terms parameter.

  1. In your GA4 property, go to Custom definitions in the main menu. You'll see the current list of Custom dimensions; the list should include oc_value_1 and oc_value_2, which will have been automatically added when authorizing your Insights Dashboard.
  2. Select Create custom dimension and give it a Dimension name. The name can be whatever you choose.
  3. Use the Event parameter dropdown menu to select search_term.
  4. Select Save to create the dimension.

Now, when users search on your site, the search term will be recorded alongside the event and user counts.

Insert the script into Site Settings

You can now add the Measurement ID to your OpenCities site admin. Keep in mind that Google Analytics will start recording site data as soon as you enter the script into your Site Settings. We recommend you only do this once you're ready to go live so the data you gather is accurate to your community.

Below is a sample of the script you need to connect your OpenCities site with your Google Analytics account.

  1. In a new browser window, go to your site's admin and go to More > Site Management > your site > Settings > Site Settings.
    the Site Settings icon in Site Management
  2. Scroll down and paste the sample script into the Google analytics field. This is the sample script:
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=GA4-CODE-GOES-HERE"></script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', 'GA4-CODE-GOES-HERE');
  3. Replace the bold text GA4-CODE-GOES-HERE with your GA4 Measurement ID. Please note there are two instances of this code.
  4. Select Save Settings and Save.

Once you Save this script in your Site Settings, your site will begin sending data through to Google Analytics; remember, you should only do this once you're ready to go live and start collecting data relevant to your community.

Test your connection

You can now test that your property collects data from your OpenCities site.

  1. In your GA4 property, go to Reports > Real-time to see reports of various real-time events. You'll see the current site metrics, including Users in Last 30 Minutes.
  2. To ensure it's working correctly, open your site in a new browser window, and click through a few pages on your site.
  3. Switch back to your GA4 report and ensure that your efforts are logged under your real-time reports.

Please note that it may take a couple of minutes for GA4 data to appear. 

Now that your site is connected to Google Analytics, you can continue monitoring your site's performance from this dashboard or set up the Insights Dashboard to gain a snapshot of key metrics you can share with others in your team.

Remember that any subsites will need a different property so that you can measure their performance separately.

What else?

Was this article helpful?
3 out of 5 found this helpful