Set up Google Analytics for your website

  • Updated

Connecting Google Analytics 4 to your Configured Commerce website includes the following steps. These steps are described in more detail below:

  1. Create or sign in into your Google Analytics account.
  2. Create a new Google Analytics 4 web property for your Optimizely site and environment. You will need to do this once for Sandbox and, after completing Sandbox testing, again for Production.
  3. Create a new web data stream for the GA4 web property.
  4. Add custom dimensions to the web data stream.
  5. Save or record the Measurement ID for your new GA4 web property.

Create or sign in to your Google Analytics account

Create a new Google Analytics 4 Web Property for your site and environment

  1. Click Admin on the left navigation bar.
  2. Select the main website account under Account.
  3. Verify that your website has not already been set up by reviewing the list of Properties available in the dropdown list under Property.
  4. Select Create Property.
  5. Enter a name for your site in the Property name field. Optimizely recommends that you indicate the environment to which the property relates. For example, “My Website Name – Sandbox.”
  6. Update the Reporting time zone and Currency fields, as necessary.
  7. Click Next.
  8. Fill out any information you choose in the About your business section.
  9. Click Create. The page should automatically update to the Data Streams page with the headline Start collecting data.

Create a new web data stream

  1. Click Web to create a new Web data stream. On the Set up data stream page, enter your Website URL and create a Stream name.
  2. Click the stream Settings button to the bottom right. On the Enhanced measurement settings page, disable everything except Page views. Click Save.
  3. Click Create stream. Your GA4 stream has been created. You will see the Installation instructions screen, but installation is not required until Google Tag Manager setup is complete.
  4. Close the Installation instructions page.
  5. Take note of the Stream Name, Stream URL, Stream ID, and Measurement ID on the Web Stream Details page. The Measurement ID will be required for setting up Google’s Tag Manager and the go-live checklist. Close the Web Stream Details page.
  6. Acknowledge the user data collection agreement by returning to the Admin > Property menu. Under Data Settings, select Data Collection. Open the bottom section entitled User Data Collection Acknowledgement, and click I acknowledge.

Create custom dimensions

  1. Return to the Admin > Property menu. Click on Custom definitions, then Create custom dimensions.
  2. Create each of the below dimensions one at a time and click Save each time.
No. Dimension name Scope Description

Event parameter/

User property

1 Authentication_State Event Authentication_State Authentication_State
2 correctedQuery Event correctedQuery correctedQuery
3 endingUrl Event endingUrl endingUrl
4 ga_session_id Event ga_session_id ga_session_id
5 numSearchResults Event numSearchResults numSearchResults
6 Page_Path Event Page_Path Page_Path
7 Page_Path_1 Event Page_Path_1 Page_Path_1








9 searchQuery Event searchQuery searchQuery
10 User_ID Event User_ID User_ID

Save or record the Measurement ID for your new GA4 web property

You will need to reference your Measurement ID in the next two steps of implementation. To find the Measurement ID at any time in the future, follow these steps:

  1. Log into Google Analytics.
  2. Click Admin.
  3. Select the Account and Property associated with your GA4 instance.
  4. Go to Property Data Streams.
  5. Select the Data Stream that is associated with your GA4 implementation. The Measurement ID will appear on the Web stream details page.

You have completed a basic setup for Google Analytics 4. Once you have verified Google Analytics data in Sandbox, you will need to repeat the process for Production. The setup for production will be identical to Sandbox but will have a property.