WC_Tracks_Client::get_identity( int $user_id )
Get a user’s identity to send to Tracks. If Jetpack exists, default to its implementation.
Description Description
Parameters Parameters
- $user_id
-
(Required) User id.
Return Return
(array) Identity properties.
Source Source
File: includes/tracks/class-wc-tracks-client.php
public static function get_identity( $user_id ) { $jetpack_lib = '/tracks/client.php'; if ( class_exists( 'Jetpack' ) && Constants::is_defined( 'JETPACK__VERSION' ) ) { if ( version_compare( Constants::get_constant( 'JETPACK__VERSION' ), '7.5', '<' ) ) { if ( file_exists( jetpack_require_lib_dir() . $jetpack_lib ) ) { include_once jetpack_require_lib_dir() . $jetpack_lib; if ( function_exists( 'jetpack_tracks_get_identity' ) ) { return jetpack_tracks_get_identity( $user_id ); } } } else { $tracking = new Automattic\Jetpack\Tracking(); return $tracking->tracks_get_identity( $user_id ); } } // Start with a previously set cookie. $anon_id = isset( $_COOKIE['tk_ai'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['tk_ai'] ) ) : false; // If there is no cookie, apply a saved id. if ( ! $anon_id ) { $anon_id = get_user_meta( $user_id, '_woocommerce_tracks_anon_id', true ); } // If an id is still not found, create one and save it. if ( ! $anon_id ) { $anon_id = self::get_anon_id(); update_user_meta( $user_id, '_woocommerce_tracks_anon_id', $anon_id ); } return array( '_ut' => 'anon', '_ui' => $anon_id, ); }