Install Google Analytics 4 (GA4) on WooCommerce

For WooCommerce store owners, tracking data is essential for business improvement. Google Analytics 4 (GA4) offers advanced tracking tools and insights. This guide explains how to set up GA4 on a WooCommerce site, including how to track purchases, add-to-cart actions, and other ecommerce events in Google Analytics.

You can also watch our Google Analytics WooCommerce tutorial to walk through the steps:

Want the pre-configured container? Get it here:

Get the pre-configured GTM container

Using a WordPress Plugin to Send Ecommerce Events to Google Analytics

Using a WordPress plugin is the easiest way to send ecommerce events to Google Analytics and gain comprehensive insights through GA4 reports.

Step 1: Check Existing Google Analytics Installation

First, determine if Google Analytics has already been added to the WordPress site. If it has, some adjustments may be necessary. If not, the following steps will guide the installation.

Questions to consider:

  • How has Google Analytics been installed? Is the site using Google's Site Kit plugin, another plugin, or is the Google Analytics tag directly added to the template?
  • Was Google Analytics added using Google Tag Manager or the Google Tag?

This guide uses the 'GTM4WP' plugin to configure Google Tag Manager for sending transaction details to Google Analytics. If Google's Site Kit plugin is in use, it can continue to be used alongside this setup.

Step 2: Add Google Tag Manager to WordPress

The solution described is compatible with Site Kit. If the Google Tag is currently in use, migrating to Google Tag Manager is recommended. The steps for this process are included as well.

  1. In WordPress, navigate to the 'Plugins' section and select 'Add New'.
  2. Search for 'Google Tag Manager'.
  3. Install and activate the 'GTM4WP' plugin.
  4. Click 'Settings' and enter the container ID from Google Tag Manager. This ID can be found within Google Tag Manager and starts with 'GTM-'.

After adding the container ID, the Google Tag Manager container will be empty, with no tags configured yet.

Step 3: Add Google Analytics to Google Tag Manager

To add a Google Analytics tag within Google Tag Manager:

  1. Select 'Add A New Tag' and name the tag.
  2. Choose 'Tag Configuration' and select 'Google Tag' as the tag type.
  3. Enter the measurement ID, which can be found in Google Analytics by navigating to 'Admin' > 'Data Streams' > selecting the relevant data stream, and copying the 'Measurement ID'.
  4. Choose 'Triggering' and select the 'Initialization - All Pages' trigger to ensure the Google Analytics tag is applied to all pages.
  5. Preview the changes, then click 'Submit' and 'Publish' to finalize the GA4 tag in the container.

Step 4: Integrate Google Tag Manager with WooCommerce

To link Google Tag Manager with WooCommerce:

  1. Copy the container ID from Google Tag Manager.
  2. Paste the container ID back into the GTM4WP plugin settings in WordPress. Ensure there are no spaces at the beginning or end of the ID.
  3. If using another plugin, such as Site Kit, to add Google Tag Manager, change the 'Container Code' option to 'Off'. Otherwise, leave it set to 'On'.
  4. Save the changes and select the 'Integration' tab to enable WooCommerce tracking.

Configuring Google Tag Manager for WooCommerce Transactions

To report ecommerce transactions in Google Analytics, it's necessary to configure a tag, trigger, and variables within the Google Tag Manager container.

The GTM4WP plugin adds a data layer in WordPress, which contains details about products viewed, actions taken, and purchases made. Variables can be used to capture this information and pass it to the Google Analytics tag.

A pre-configured container can be downloaded and imported into Google Tag Manager by following these steps:

  1. Select 'Admin' in Google Tag Manager and choose 'Import Container'.
  2. Select the pre-configured container, and choose 'Existing' to use the current workspace.
  3. Choose 'Default' and select 'Merge' to keep existing tags, variables, and triggers.
  4. Confirm the import. This will add a new tag, trigger, and variables to send ecommerce details to Google Analytics.
  5. Verify that the GA4 ecommerce tag and triggers have been added and configured correctly.

Testing WooCommerce Ecommerce Events

After configuring the tags, it's important to test the setup:

  1. Click 'Preview' in Google Tag Manager.
  2. Enter the WooCommerce store's URL and click 'Connect'.
  3. Simulate various actions, such as viewing a product and adding it to the cart.

Before completing a purchase, check the events already sent to Google Analytics by selecting the GA4 measurement ID in the Tag Assistant tab.

  1. Complete a purchase and review the confirmation page in the Tag Assistant tab to verify additional events, including the purchase event, have been sent to Google Analytics.
  2. In Google Analytics, navigate to 'Configure' > 'DebugView' to confirm all ecommerce events, including the purchase event, have been recorded.

Publishing the GTM Container

Once testing is complete and everything is functioning correctly, publish the changes in Google Tag Manager by following these steps:

  1. In Google Tag Manager, click 'Submit'.
  2. Name the version and click 'Publish'.

The ecommerce tag, triggers, and variables are now live on the WooCommerce store.

Conclusion

By following these steps, WooCommerce store owners can effectively use GA4's monetization reports and build custom exploration reports in Google Analytics. GA4 offers valuable insights into customer behavior and sales trends, enabling data-driven improvements to the store.

For those who have added Google Tag Manager and GA4 to their WooCommerce store, feedback is always welcome in the comments. To dive deeper into GA4 and optimize its use for better decision-making, consider joining our GA4 course and our GTM course.

Comments