WC_Site_Tracking::add_tracking_function()public staticWC 1.0

Adds the tracking function to the admin footer.

{} Это метод класса: WC_Site_Tracking{}

Хуки из метода

Возвращает

null. Ничего.

Использование

$result = WC_Site_Tracking::add_tracking_function();

Код WC_Site_Tracking::add_tracking_function() WC 6.9.4

<?php
public static function add_tracking_function() {
	$user           = wp_get_current_user();
	$server_details = WC_Tracks::get_server_details();
	$blog_details   = WC_Tracks::get_blog_details( $user->ID );

	$client_tracking_properties = array_merge( $server_details, $blog_details );
	/**
	 * Add global tracks event properties.
	 *
	 * @since 6.5.0
	 */
	$filtered_properties = apply_filters( 'woocommerce_tracks_event_properties', $client_tracking_properties, false );
	?>
	<!-- WooCommerce Tracks -->
	<script type="text/javascript">
		window.wcTracks = window.wcTracks || {};
		window.wcTracks.isEnabled = <?php echo self::is_tracking_enabled() ? 'true' : 'false'; ?>;
		window.wcTracks.recordEvent = function( name, properties ) {
			if ( ! window.wcTracks.isEnabled ) {
				return;
			}

			const eventName = '<?php echo esc_attr( WC_Tracks::PREFIX ); ?>' + name;
			let eventProperties = properties || {};
			eventProperties = { ...eventProperties, ...<?php echo json_encode( $filtered_properties ); ?> };
			if ( window.wp && window.wp.hooks && window.wp.hooks.applyFilters ) {
				eventProperties = window.wp.hooks.applyFilters( 'woocommerce_tracks_client_event_properties', eventProperties, eventName );
				delete( eventProperties._ui );
				delete( eventProperties._ut );
			}
			// Verify the event name is correct
			if ( ! <?php echo esc_js( WC_Tracks_Event::EVENT_NAME_REGEX ); ?>.test( eventName ) ) {
				console.error( `A valid event name must be specified. The event name: "${ eventName }" is not valid.` );
			}
			// Verify the properties are correct
			for( prop in eventProperties ) {
				if ( ! <?php echo esc_js( WC_Tracks_Event::PROP_NAME_REGEX ); ?>.test( prop ) ) {
					console.error( `A valid prop name must be specified. The property name: "${ prop }" is not valid.` );
				}
			}
			window._tkq = window._tkq || [];
			window._tkq.push( [ 'recordEvent', eventName, eventProperties ] );
		}
	</script>
	<?php
}