Protect _ui and _ut props, move JS filter below product count

This commit is contained in:
Timmy Crawford 2020-03-16 17:00:25 -07:00
parent 2c8195ca8a
commit 356e5a562f
2 changed files with 10 additions and 4 deletions

View File

@ -68,11 +68,13 @@ class WC_Site_Tracking {
window.wcTracks.recordEvent = function( name, properties ) {
var eventName = '<?php echo esc_attr( WC_Tracks::PREFIX ); ?>' + name;
var eventProperties = properties || {};
if ( window.wp && window.wp.hooks && window.wp.hooks.applyFilters ) {
eventProperties = window.wp.hooks.applyFilters( 'woocommerceTracksEventProperties', eventProperties, eventName );
}
eventProperties.url = '<?php echo esc_html( home_url() ); ?>'
eventProperties.products_count = '<?php echo intval( WC_Tracks::get_products_count() ); ?>';
if ( window.wp && window.wp.hooks && window.wp.hooks.applyFilters ) {
eventProperties = window.wp.hooks.applyFilters( 'woocommerceTracksEventProperties', eventProperties, eventName );
delete( eventProperties._ui );
delete( eventProperties._ut );
}
window._tkq = window._tkq || [];
window._tkq.push( [ 'recordEvent', eventName, eventProperties ] );
}

View File

@ -98,7 +98,11 @@ class WC_Tracks {
$blog_details = self::get_blog_details( $user->ID );
// Allow event props to be filtered to enable adding site-wide props.
$filtered_properties = apply_filters( 'woocommerce-tracks-event-properties', $properties, $prefixed_event_name );
$filtered_properties = apply_filters( 'woocommerce_tracks_event_properties', $properties, $prefixed_event_name );
// Delete _ui and _ut protected properties.
unset( $filtered_properties['_ui'] );
unset( $filtered_properties['_ut'] );
$event_obj = new WC_Tracks_Event( array_merge( $data, $server_details, $identity, $blog_details, $filtered_properties ) );