Custom WooCommerce Event Tracking
This feature turns your WooCommerce store into your very own Google Analytics type suite.
Out of the box, Alpha Insights will track all event and session data from your visitors, including shop activity & page activity.
You can also extend the reporting with custom events.
The Settings
To update the analytics settings, you can go to Alpha Insights > General Settings and scroll down to the section labelled Alpha Analytics & Event Tracking.
By default, it will be configured to operate correctly and immediately start to collect and report on data.
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.
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.
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.