the custom permalink and the core endpoint key.
* To avoid triggering the event twice, we skip the core one and only track the custom one.
* Tracking the custom endpoint is safer than hoping the duplicated, redundant core endpoint is always present.
*/
if ( isset( $core_endpoints[ $key ] ) && $core_endpoints[ $key ] !== $key ) {
continue;
}
/**
* $core_endpoints is an array of core_permalink => custom_permalink,
* query_vars gives us the custom_permalink, but we want to track it as core_permalink.
*/
if ( array_search( $key, $core_endpoints, true ) ) {
$key = array_search( $key, $core_endpoints, true );
}
$this->record_event( 'woocommerceanalytics_my_account_page_view', array( 'tab' => $key ) );
}
}
}
/**
* Track address save events, this can only come from the my account page.
*
* @param int $customer_id The customer id.
* @param string $load_address The address type (billing, shipping).
*/
public function track_save_address( $customer_id, $load_address ) {
$this->queue_event( 'woocommerceanalytics_my_account_address_save', array( 'address' => $load_address ) );
}
/**
* Track payment method add events, this can only come from the my account page.
*/
public function track_add_payment_method() {
if ( isset( $_POST['woocommerce_add_payment_method'] ) && isset( $_POST['payment_method'] ) ) {
$nonce_value = wc_get_var( $_REQUEST['woocommerce-add-payment-method-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated,WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.ValidatedSanitizedInput.MissingUnslash
if ( ! wp_verify_nonce( $nonce_value, 'woocommerce-add-payment-method' ) ) {
return;
}
$this->queue_event( 'woocommerceanalytics_my_account_payment_save' );
return;
}
}
/**
* Track payment method delete events.
*/
public function track_delete_payment_method() {
global $wp;
if ( isset( $wp->query_vars['delete-payment-method'] ) ) {
$this->queue_event( 'woocommerceanalytics_my_account_payment_delete' );
return;
}
}
/**
* Track order cancel events.
*/
public function track_order_cancel_event() {
if ( isset( $_GET['_wca_initiator'] ) && ( isset( $_GET['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_GET['_wpnonce'] ), 'woocommerce-cancel_order' ) ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$this->queue_event( 'woocommerceanalytics_my_account_order_action_click', array( 'action' => 'cancel' ) );
}
}
/**
* Track order pay events.
*/
public function track_order_pay_event() {
if ( isset( $_GET['_wca_initiator'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended
$this->record_event( 'woocommerceanalytics_my_account_order_action_click', array( 'action' => 'pay' ) );
}
}
/**
* Track account details save events, this can only come from the my account page.
*/
public function track_save_account_details() {
$this->queue_event( 'woocommerceanalytics_my_account_details_save' );
}
/**
* Track logout events.
*/
public function track_logouts() {
$common_props = $this->render_properties_as_js(
$this->get_common_properties()
);
wc_enqueue_js(
"
jQuery(document).ready(function($) {
// Attach event listener to the logout link
jQuery('.woocommerce-MyAccount-navigation-link--customer-logout').on('click', function() {
_wca.push({
'_en': 'woocommerceanalytics_my_account_tab_click',
'tab': 'logout'," .
$common_props . '
});
});
});
'
);
}
/**
* Add referrer prop to my account action links
*
* @param array $actions My account action links.
* @return array
*/
public function add_initiator_prop_to_my_account_action_links( $actions ) {
foreach ( $actions as $key => $action ) {
if ( ! isset( $action['url'] ) ) {
continue;
}
// Check if the action key is view, pay, or cancel.
if ( ! in_array( $key, array( 'view', 'pay', 'cancel' ), true ) ) {
continue;
}
$url = add_query_arg( array( '_wca_initiator' => 'action' ), $action['url'] );
$actions[ $key ]['url'] = $url;
}
return $actions;
}
/**
* Add an initiator prop to the order url.
*
* The get_view_order_url is used in a lot of places,
* so we want to limit it just to my account page.
*/
public function add_initiator_prop_to_order_urls() {
add_filter(
'woocommerce_get_view_order_url',
function ( $url ) {
return add_query_arg( array( '_wca_initiator' => 'number' ), $url );
},
10,
1
);
add_filter(
'woocommerce_get_endpoint_url',
function ( $url, $endpoint ) {
if ( 'edit-address' === $endpoint ) {
return add_query_arg( array( '_wca_initiator' => 'action' ), $url );
}
return $url;
},
10,
2
);
}
/**
* Add initiator to query vars
*
* @param array $query_vars Query vars.
* @return array
*/
public function add_initiator_param_to_query_vars( $query_vars ) {
$query_vars[] = '_wca_initiator';
return $query_vars;
}
/**
* Record all queued up events in session.
*
* This is called on every page load, and will record all events that were queued up in session.
*/
public function trigger_queued_events() {
if ( is_object( WC()->session ) ) {
$events = WC()->session->get( 'wca_queued_events', array() );
foreach ( $events as $event ) {
$this->record_event(
$event['event_name'],
$event['event_props']
);
}
// Clear data, now that these events have been recorded.
WC()->session->set( 'wca_queued_events', array() );
}
}
/**
* Queue an event in session to be recorded later on next page load.
*
* @param string $event_name The event name.
* @param array $event_props The event properties.
*/
protected function queue_event( $event_name, $event_props = array() ) {
if ( is_object( WC()->session ) ) {
$events = WC()->session->get( 'wca_queued_events', array() );
$events[] = array(
'event_name' => $event_name,
'event_props' => $event_props,
);
WC()->session->set( 'wca_queued_events', $events );
}
}
}
Fatal error: Uncaught Error: Class "Automattic\Woocommerce_Analytics\My_Account" not found in /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/woocommerce-analytics/src/class-woocommerce-analytics.php:43
Stack trace:
#0 /htdocs/wp-content/plugins/jetpack/modules/woocommerce-analytics.php(21): Automattic\Woocommerce_Analytics::init()
#1 /htdocs/wp-content/plugins/jetpack/class.jetpack.php(1834): include_once('/htdocs/wp-cont...')
#2 /htdocs/wp-includes/class-wp-hook.php(324): Jetpack::load_modules('')
#3 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#4 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#5 /htdocs/wp-settings.php(578): do_action('plugins_loaded')
#6 /htdocs/wp-config.php(85): require_once('/htdocs/wp-sett...')
#7 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...')
#8 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...')
#9 /htdocs/index.php(17): require('/htdocs/wp-blog...')
#10 {main}
thrown in /htdocs/wp-content/plugins/jetpack/jetpack_vendor/automattic/woocommerce-analytics/src/class-woocommerce-analytics.php on line 43