jetpack_tracks_build_event_obj

Procedurally build a Tracks Event Object.

Description

(Jetpack_Tracks_Event|WP_Error) jetpack_tracks_build_event_obj( $user, (string) $event_name, (array) $properties = array(), (bool) $event_timestamp_millis = false ); 

NOTE: Use this only when the simpler jetpack_tracks_record_event() function won't work for you.

Returns (Jetpack_Tracks_Event|WP_Error)

Parameters (4)

0. $user
WP_user object
1. $event_name (string)
The name of the event
2. $properties — Optional. (array) => array()
Custom properties to send with the event
3. $event_timestamp_millis — Optional. (bool) => false
The time in millis since 1970-01-01 00:00:00 when the event occurred

Usage

  1. if ( !function_exists( 'jetpack_tracks_build_event_obj' ) ) { 
  2. require_once '/_inc/lib/tracks/client.php'; 
  3.  
  4. // WP_user object 
  5. $user = null; 
  6.  
  7. // The name of the event 
  8. $event_name = ''; 
  9.  
  10. // Custom properties to send with the event 
  11. $properties = array(); 
  12.  
  13. // The time in millis since 1970-01-01 00:00:00 when the event occurred 
  14. $event_timestamp_millis = false; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = jetpack_tracks_build_event_obj($user, $event_name, $properties, $event_timestamp_millis); 
  18.  

Defined (1)

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

/_inc/lib/tracks/client.php  
  1. function jetpack_tracks_build_event_obj( $user, $event_name, $properties = array(), $event_timestamp_millis = false ) { 
  2.  
  3. $identity = jetpack_tracks_get_identity( $user->ID ); 
  4.  
  5. $properties['user_lang'] = $user->get( 'WPLANG' ); 
  6.  
  7. $blog_details = array( 
  8. 'blog_lang' => isset( $properties['blog_lang'] ) ? $properties['blog_lang'] : get_bloginfo( 'language' ) 
  9. ); 
  10.  
  11. $timestamp = ( $event_timestamp_millis !== false ) ? $event_timestamp_millis : round( microtime( true ) * 1000 ); 
  12. $timestamp_string = is_string( $timestamp ) ? $timestamp : number_format( $timestamp, 0, '', '' ); 
  13.  
  14. return new Jetpack_Tracks_Event( array_merge( $blog_details, (array) $properties, $identity, array( 
  15. '_en' => $event_name,  
  16. '_ts' => $timestamp_string 
  17. ) ) );