Start a free 14-day trial by December 1 on a wide range of WooCommerce Marketplace extensions and themes. Explore products

Track custom events with Google Analytics Pro

Use this reference to send custom events from WooCommerce Google Analytics Pro to a GA4 property. Set up GA4 tracking in WooCommerce before adding a site-specific plugin that calls the event API. Test with an approved test property and fictional activity.

Note:

This is a developer-level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customization work. We are unable to provide support for customization under our Support Policy.

Record a custom event

↑ Back to top

This example registers a callback for a store-specific WordPress action. Replace my_store_size_guide_opened with an action that runs once when the behavior occurs on your site. The action in the example is a placeholder and your implementation must supply it.

add_action( 'my_store_size_guide_opened', function () {
    if ( ! function_exists( 'wc_google_analytics_pro' ) ) {
        return;
    }

    wc_google_analytics_pro()
        ->get_tracking_instance()
        ->get_event_tracking_instance()
        ->custom_event(
            'store_size_guide_opened',
            array( 'guide_location' => 'product_page' )
        );
} );

Pass an event name and, optionally, an array of event properties. Follow Google’s event naming rules. Use nonpersonal values and avoid names already used by the integration.

Verify the event

↑ Back to top

With a test property connected, enable Debug Mode temporarily and trigger your chosen action. Open DebugView to confirm that the expected event and parameters appear once. If the event is missing, verify the hook runs and check the tracking settings and connection. Disable debug mode when finished.

Check other tracking integrations

↑ Back to top

Use the WooCommerce guide’s purchase and referral reporting and duplicate-tracking guidance when Google Tag Manager is also installed. Legacy Universal Analytics pageview snippets do not configure GA4 pageview tracking.

Questions and support

↑ Back to top

Something missing from this documentation? Still have questions and need assistance?

  • If you have a question about a specific extension or theme you’d like to purchase, contact us to get answers.
  • If you already purchased this product and need some assistance, get in touch with a Happiness Engineer via our support page and select this product’s name from the Product dropdown.

Related Products

Advanced, flexible shipping. Define multiple shipping rates based on location, price, weight, shipping class...

Protect your eCommerce store from malicious and automated attacks by using reCaptcha/Cloudflare...

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.