How to Install Google Analytics 4 (GA4) on WooCommerce
Loves Data
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. This guide uses the GTM for WordPress plugin (also known as GTM4WP) to send ecommerce events to Google Analytics.
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. To do this you will need to ensure Google Tag Manager is only used to send the ecommerce events to Google Analytics as Site Kit will already be tracking page view and other events.
Step 2: Add The GTM Plugin to WordPress
Here are the step to install the GTM plugin on WordPress:
- In WordPress, navigate to the 'Plugins' section and select 'Add New'.
- Search for 'Google Tag Manager'.
- Install and activate the 'GTM4WP' plugin.
- Click 'Settings' and enter the container ID from Google Tag Manager. This ID can be found within Google Tag Manager and starts with 'GTM-'.
Important: Make sure the ‘Container Code’ option is set to ‘On’ in the plugin settings. If it's set to ‘Off’, the plugin will add the ecommerce data layer to your site, but it won't add the actual Google Tag Manager container code. This will prevent your tags from firing.
Step 3: Add Google Analytics to Google Tag Manager
To add a Google Analytics tag within Google Tag Manager:
- Select 'Add A New Tag' and name the tag.
- Choose 'Tag Configuration' and select 'Google Tag' as the tag type.
- Create a constant variable for your GA4 measurement ID to reuse it easily across tags.
- Enter the measurement ID, which can be found in Google Analytics by navigating to 'Admin', then 'Data Streams', and selecting the relevant data stream, and copying the 'Measurement ID'.
- Choose 'Triggering' and select the 'Initialization - All Pages' trigger to ensure the Google Analytics tag is applied to all pages.
- Preview the changes, then click 'Submit' and 'Publish' to finalize the GA4 tag in the container.
Step 4: Integrate Google Tag Manager with WooCommerce
Now we need to finish setting the Google Tag Manager plugin on WordPress so it integrates with our WooCommerce store. Here are the steps:
- Copy the container ID from Google Tag Manager.
- Paste the container ID into the GTM4WP plugin settings in WordPress. Ensure there are no spaces at the beginning or end of the ID.
- Ensure the 'Container Code' option is set to 'On' (unless you plan to continue using another plugin in parallel).
- Save the changes.
- Select the 'Integration' tab and choose 'WooCommerce'.
- Ensure 'Track Ecommerce' is enabled.
- Save the changes.
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.
If you haven't already, you can download our pre-configured container and import it into Google Tag Manager by following these steps:
- Select 'Admin' in Google Tag Manager and choose 'Import Container'.
- Select the pre-configured container, and choose 'Existing' to use the current workspace.
- Choose 'Default' and select 'Merge' to keep existing tags, variables, and triggers.
- Confirm the import. This will add a new tag, trigger, and variables to send ecommerce details to Google Analytics.
- Verify that the GA4 ecommerce tag and triggers have been added and configured correctly.
If you don't want to download our pre-configured container, you can create your own ecommerce tag and trigger by following these steps:
- In Google Tag Manager, create a new trigger using the 'Custom Event' type.
- Enter the event name using a regular expression that matches ecommerce events. Here's the regular expression:
view_item|view_item_list|select_item|add_to_cart|remove_from_cart|view_cart|begin_checkout|add_payment_info|add_shipping_info|purchase
- Enable the option to 'Use Regex Matching'.
- Create a new tag using the 'GA4 Event' tag type.
- Select your measurement ID variable.
- Set the event name to use the built-in
{{Event}}
variable. - Under 'More Settings' and then 'Ecommerce', enable 'Send Ecommerce Data' and set the source to 'Data Layer'.
- Select your ecommerce trigger and save the tag.
Testing WooCommerce Ecommerce Events
After configuring the tags, it's important to test the setup:
- Click 'Preview' in Google Tag Manager.
- Enter the WooCommerce store's URL and click 'Connect'.
- 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.
- 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.
- In Google Analytics, navigate to 'Admin', then 'Data Display', and select 'DebugView' to confirm all ecommerce events, including the purchase event, have been recorded.
Tip: If you’re not seeing events in DebugView, double-check that your GTM container is installed correctly and that ‘Container Code’ is enabled in the plugin settings. And if you're still encountering issues, read our ecommerce troubleshooting tips.
Publishing the GTM Container
Once testing is complete and everything is functioning correctly, publish the changes in Google Tag Manager:
- In Google Tag Manager, click 'Submit'.
- Name the version and click 'Publish'.
Your ecommerce tag, triggers, and variables are now live on your 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.
New to Google Tag Manager? Check out our Beginner’s Guide to GTM for a full walkthrough.
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