How to Solve the Issue of Not Sending GA4 Events in WordPress/WooCommerce?

fix ga4 events not sending wordpress woocommerce
10 November 2024

If you are using Google Analytics 4 (GA4) on your WordPress website or WooCommerce store, you may encounter the issue of not sending events. This problem can arise due to various reasons, including incorrect plugin configurations or lack of browser updates. Here are a few simple methods to resolve this issue.

First, ensure that the plugin used for connecting GA4 to WordPress is updated and compatible with the latest versions. Many of these plugins are regularly updated to reflect changes in Google API seamlessly.

The second step is to review the event configurations, including the tracking code, to ensure it has been correctly implemented on the website. A correct tracking code can help connect events appropriately to Google Analytics.

In some cases, you may want to manually add events in the code snippet. This method can provide greater control over how and what data is sent to Google. For example, the following code outlines how to implement this:

Additionally, make use of Google Tag Manager as it allows you to manage codes on the site without manual intervention, adding or removing various events easily.


<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'GA_MEASUREMENT_ID');
  gtag('event', 'purchase', {
    'transaction_id': '24.031608523954162',
    'affiliation': 'Google online store',
    'value': 23.07,
    'currency': 'USD',
    'tax': 1.24,
    'shipping': 0,
    'items': [{
      'id': 'P12345',
      'name': 'Android Warhol T-Shirt',
      'list_name': 'Search Results',
      'brand': 'Google',
      'category': 'Apparel/T-Shirts',
      'variant': 'Black',
      'list_position': 1,
      'quantity': 2,
      'price': '14.99'
    }]
  });
</script>

Explanation of the Code Line by Line:


<!-- Global site tag (gtag.js) - Google Analytics -->
This line signifies that the Google tag file is integrated into the site.
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
This is the asynchronous Google tag script file that allows GA4 functionalities.
window.dataLayer = window.dataLayer || [];
A dataLayer array is defined in memory to hold event information.
function gtag(){dataLayer.push(arguments);}
A function is defined which adds data to the dataLayer array.
gtag('js', new Date());
The current date and time is sent to Google to register the session.
gtag('config', 'GA_MEASUREMENT_ID');
The measurement ID is sent to Google to direct event data to your specific property.
gtag('event', 'purchase', {...})
An event named purchase is described along with details such as type, price, and item ID sent to Google.

FAQ

?

Why aren't GA4 events sent in WordPress?

?

Can I send events without coding?

?

How can I manually add GA4 events to the site?