jetpack_tracks_record_event

Record an event in Tracks - this is the preferred way to record events from PHP.

Description

jetpack_tracks_record_event( (mixed) $user, (string) $event_name, (array) $properties = array(), (bool) $event_timestamp_millis = false ); 

Parameters (4)

0. $user (mixed)
Username, user_id, or 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_record_event' ) ) { 
  2. require_once '/_inc/lib/tracks/client.php'; 
  3.  
  4. // username, user_id, or 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_record_event($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_record_event( $user, $event_name, $properties = array(), $event_timestamp_millis = false ) { 
  2.  
  3. // We don't want to track user events during unit tests/CI runs. 
  4. if ( $user instanceof WP_User && 'wptests_capabilities' === $user->cap_key ) { 
  5. return false; 
  6.  
  7. $event_obj = jetpack_tracks_build_event_obj( $user, $event_name, $properties, $event_timestamp_millis ); 
  8.  
  9. if ( is_wp_error( $event_obj->error ) ) { 
  10. return $event_obj->error; 
  11.  
  12. return $event_obj->record();