jetpack_tracks_get_identity

Get the identity to send to tracks.

Description

(array) jetpack_tracks_get_identity( (int) $user_id ); 

Returns (array)

$identity

Parameters (1)

0. $user_id (int)
The user id of the local user

Usage

  1. if ( !function_exists( 'jetpack_tracks_get_identity' ) ) { 
  2. require_once '/_inc/lib/tracks/client.php'; 
  3.  
  4. // The user id of the local user 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = jetpack_tracks_get_identity($user_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/_inc/lib/tracks/client.php  
  1. function jetpack_tracks_get_identity( $user_id ) { 
  2.  
  3. // Meta is set, and user is still connected. Use WPCOM ID 
  4. $wpcom_id = get_user_meta( $user_id, 'jetpack_tracks_wpcom_id', true ); 
  5. if ( $wpcom_id && Jetpack::is_user_connected( $user_id ) ) { 
  6. return array( 
  7. '_ut' => 'wpcom:user_id',  
  8. '_ui' => $wpcom_id 
  9. ); 
  10.  
  11. // User is connected, but no meta is set yet. Use WPCOM ID and set meta. 
  12. if ( Jetpack::is_user_connected( $user_id ) ) { 
  13. $wpcom_user_data = Jetpack::get_connected_user_data( $user_id ); 
  14. add_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'], true ); 
  15.  
  16. return array( 
  17. '_ut' => 'wpcom:user_id',  
  18. '_ui' => $wpcom_user_data['ID'] 
  19. ); 
  20.  
  21. // User isn't linked at all. Fall back to anonymous ID. 
  22. $anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true ); 
  23. if ( ! $anon_id ) { 
  24. $anon_id = Jetpack_Tracks_Client::get_anon_id(); 
  25. add_user_meta( $user_id, 'jetpack_tracks_anon_id', $anon_id, false ); 
  26.  
  27. if ( ! isset( $_COOKIE[ 'tk_ai' ] ) && ! headers_sent() ) { 
  28. setcookie( 'tk_ai', $anon_id ); 
  29.  
  30. return array( 
  31. '_ut' => 'anon',  
  32. '_ui' => $anon_id 
  33. ); 
  34.