diff --git a/plugins/woocommerce/client/legacy/js/admin/order-source-attribution-admin.js b/plugins/woocommerce/client/legacy/js/admin/order-source-attribution-admin.js index 7fc9379181f..ba43e453f31 100644 --- a/plugins/woocommerce/client/legacy/js/admin/order-source-attribution-admin.js +++ b/plugins/woocommerce/client/legacy/js/admin/order-source-attribution-admin.js @@ -1,12 +1,17 @@ +/*global woocommerce_admin_meta_boxes, wcTracks */ jQuery( document ).ready( ( $ ) => { 'use strict'; + // Stand-in wcTracks.recordEvent in case tracks is not available (for any reason). + window.wcTracks = window.wcTracks || {}; + window.wcTracks.recordEvent = window.wcTracks.recordEvent || function() { }; + // Handle our details container toggle. $( '.woocommerce-order-source-attribution-details-toggle' ) .on( 'click', function ( e ) { var $this = $( this ); var $container = $this.siblings( '.woocommerce-order-source-attribution-details-container' ); - var $toggle = $this.find( '.toggle-indicator' ); + var toggle = ''; e.preventDefault(); @@ -14,10 +19,17 @@ jQuery( document ).ready( ( $ ) => { $container.removeClass( 'closed' ); $container.fadeIn( 250 ); $this.attr( 'aria-expanded', 'true' ); + toggle = 'opened'; } else { $container.addClass( 'closed' ); $container.fadeOut( 250 ); $this.attr( 'aria-expanded', 'false' ); + toggle = 'closed'; } + + window.wcTracks.recordEvent( 'order_source_attribution_details_toggle', { + order_id: window.woocommerce_admin_meta_boxes.order_id, + details: toggle + } ); } ); } ); diff --git a/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php b/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php index 014470418ab..0b9f8f47fed 100644 --- a/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php +++ b/plugins/woocommerce/src/Internal/Orders/SourceAttributionController.php @@ -357,6 +357,7 @@ class SourceAttributionController implements RegisterHooksInterface { */ private function send_order_tracks( array $source_data, WC_Order $order ) { $tracks_data = array( + 'order_id' => $order->get_id(), 'origin' => $source_data['origin'] ?? '', 'device_type' => $source_data['device_type'] ?? '(unknown)', 'session_pages' => $source_data['session_pages'] ?? 0,