Add tracks using JS
This commit is contained in:
parent
edfe2896b4
commit
2ef7df465a
|
@ -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
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue