tring( $timestamp ) ? $timestamp : number_format( $timestamp, 0, '', '' ); return new \Jetpack_Tracks_Event( array_merge( $blog_details, (array) $properties, $identity, array( '_en' => $event_name, '_ts' => $timestamp_string, ) ) ); } /** * Get the identity to send to tracks. * * @param int $user_id The user id of the local user. * * @return array $identity */ public function tracks_get_identity( $user_id ) { // Meta is set, and user is still connected. Use WPCOM ID. $wpcom_id = get_user_meta( $user_id, 'jetpack_tracks_wpcom_id', true ); if ( $wpcom_id && $this->connection->is_user_connected( $user_id ) ) { return array( '_ut' => 'wpcom:user_id', '_ui' => $wpcom_id, ); } // User is connected, but no meta is set yet. Use WPCOM ID and set meta. if ( $this->connection->is_user_connected( $user_id ) ) { $wpcom_user_data = $this->connection->get_connected_user_data( $user_id ); update_user_meta( $user_id, 'jetpack_tracks_wpcom_id', $wpcom_user_data['ID'] ); return array( '_ut' => 'wpcom:user_id', '_ui' => $wpcom_user_data['ID'], ); } // User isn't linked at all. Fall back to anonymous ID. $anon_id = get_user_meta( $user_id, 'jetpack_tracks_anon_id', true ); if ( ! $anon_id ) { $anon_id = \Jetpack_Tracks_Client::get_anon_id(); add_user_meta( $user_id, 'jetpack_tracks_anon_id', $anon_id, false ); } if ( ! isset( $_COOKIE['tk_ai'] ) && ! headers_sent() ) { setcookie( 'tk_ai', $anon_id, 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), false ); // phpcs:ignore Jetpack.Functions.SetCookie -- This is a random string and should be fine. } return array( '_ut' => 'anon', '_ui' => $anon_id, ); } }