Setting Up WooCommerce Event Tracking & Analytics

Alpha Insights Documentation

Custom WooCommerce Event Tracking

The Settings

Enable WooCommerce Analaytics

This setting will simply enable the tracking functionality, if this is set to true it will track the analytics and log them, and if it is set to false it will simply not do any tracking.

Reports will still be displayed regardless of this setting so you can still view your data regardless of this setting.

Display Analytics In WordPress Admin Tables

This will extend the WordPress Admin Products Table and Orders Table.

For the products table it will display a number of useful metrics so you can see how your products are performing when viewing your products in the WordPress admin area.

For the Orders table it will display the Acquisition Channel and the Campaign if found for the session. The Campaign will only be displayed if Alpha Insights has found a utm_campaign parameter in the landing page.

Exclude These Roles From Tracking

This one’s self explanatory, it will exclude all logged in users from being tracked whom have the role(s) specified in your setting.

Once the data has been captured though, it’s in the reports, this is a non-destructive setting. We may build a tool to filter out further data, such as IP Address, and also offer the functionality to remove the data from your reports if it’s already been captured. Shoot us an email if this is of high priority.

Disable Extension

The Analytics module can be quite intensive if you have a very high traffic website and will generate considerable amounts of data.

If you have no interest in this feature, this setting will completely disable every piece of code to do with the WooCommerce Events Tracking, so if you are noticing any performance issue this may be an option to consider.

Important Notes

If You Are Using A Caching Plugin

If you are using a caching plugin it is recommended to exclude the tracking script from your caching plugin.

If the Alpha Insights WooCommerce Event Tracking is being minified, cached or combined, there is a good chance it won’t fire.

We for example use our plugin on our own website (duh), and also use WP Fastest Cache Pro to offer a speedy experience.

We had to exclude the tracking script from the Cache in order to capture all requests.

The script we want to exclude is called wpd-alpha-insights-event-tracking, so our exclusion rule looks like this:

Adding Your Own Custom Events

Alpha Insights tracks WooCommerce Events and interactions both on the frontend and on the server side.

The reports are configured to display some metrics against custom events, with added support planned for the future.

So if you would like to track custom events, much like you would using Google Analytics or Facebook Pixel, you can do so with the following instructions

Javascript Custom Events – Register Your File With The Dependency

The first thing you will want to do is to declare a script that comes after the Alpha Insights WooCommerce Event Tracking Script:

							wp_register_script( 'your-custom-js-file', '/path/to/your/jsfile.js', array( 'jquery', 'wpd-alpha-insights-event-tracking' ), false, true );


And then you need to trigger the event in your custom JS, below is an example of the JS used to track product clicks which is built into Alpha Insights.

					jQuery(document).ready(function($) {
	$('.products .product a').click(function() {
		var product_id = 0;
		var pid = $(this).closest('.product').find('.wpd-ai-event-tracking-product-id').data('product-id');
		if ( pid ) {
			product_id = pid;
		var payload = {
			event_type: 	'product_click', // Required
			event_quantity: 1,
			event_value: 	0,
			object_id: 		product_id,
			object_type: 	'product',
			product_id: 	product_id,
			variation_id: 	0,
		var product_click = WpdAiEventTracking( payload );

The only required parameter is the event_type, although we recommend you set values for each parameter as it will enrich the database.

Your JS file must be loaded after the woocommerce event tracking file otherwise you will not have access to the event tracking function WpdAiEventTracking.