Skip to content

Commit

Permalink
Enable ECE Tracks Events when WooPay is disabled (#9793)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelzaleski authored Nov 25, 2024
1 parent b66a6ab commit 4bea82a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-9784-ece-tracks-events
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix ECE Tracks events not triggering when WooPay is disabled.
2 changes: 2 additions & 0 deletions includes/class-woopay-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ public function tracks_record_event( $event_name, $properties = [], $is_admin_ev
return false;
}

$properties = apply_filters( 'wcpay_tracks_event_properties', $properties, $event_name );

if ( isset( $properties['record_event_data'] ) ) {
if ( isset( $properties['record_event_data']['is_admin_event'] ) ) {
$is_admin_event = $properties['record_event_data']['is_admin_event'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public function init() {
add_action( 'woocommerce_pay_order_before_payment', [ $this, 'display_express_checkout_buttons' ], 1 );
}

add_filter( 'wcpay_tracks_event_properties', [ $this, 'record_all_ece_tracks_events' ], 10, 2 );

if ( $this->is_pay_for_order_flow_supported() ) {
add_action( 'wp_enqueue_scripts', [ $this, 'add_pay_for_order_params_to_js_config' ], 5 );
}
Expand Down Expand Up @@ -218,4 +220,27 @@ function ( $js_config ) use ( $order ) {
}
// phpcs:enable WordPress.Security.NonceVerification
}

/**
* Record all ECE tracks events by adding the track_on_all_stores flag to the event.
*
* @param array $properties Event properties.
* @param string $event_name Event name.
* @return array
*/
public function record_all_ece_tracks_events( $properties, $event_name ) {
$tracked_events_prefixes = [
'wcpay_applepay',
'wcpay_gpay',
];

foreach ( $tracked_events_prefixes as $prefix ) {
if ( strpos( $event_name, $prefix ) === 0 ) {
$properties['record_event_data']['track_on_all_stores'] = true;
break;
}
}

return $properties;
}
}

0 comments on commit 4bea82a

Please sign in to comment.