Advertisement
verygoodplugins

Untitled

Nov 10th, 2021
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1.     /**
  2.      * Track event.
  3.      *
  4.      * Track an event with the Bento site tracking API.
  5.      *
  6.      * @since  3.38.16
  7.      *
  8.      * @param  string      $event      The event title.
  9.      * @param  bool|string $event_data The event description.
  10.      * @param  bool|string $email_address The user email address.
  11.      * @return bool|WP_Error True if success, WP_Error if failed.
  12.      */
  13.     public function track_event( $event, $event_data = false, $email_address = false ) {
  14.  
  15.         if ( empty( $email_address ) && ! wpf_is_user_logged_in() ) {
  16.             // Tracking only works if WP Fusion knows who the contact is.
  17.             return;
  18.         }
  19.  
  20.         // Get the email address to track.
  21.         if ( empty( $email_address ) ) {
  22.             $user          = wpf_get_current_user();
  23.             $email_address = $user->user_email;
  24.         }
  25.  
  26.         $site_uuid = wpf_get_option( 'site_uuid' );
  27.  
  28.         $data['events'][] = array(
  29.             'email'   => $email_address,
  30.             'type'    => $event,
  31.             'details' => $event_data,
  32.         );
  33.  
  34.         $request            = $this->url . '/batch/events/?site_uuid=' . $site_uuid;
  35.         $params             = $this->get_params();
  36.         $params['body']     = wp_json_encode( $data );
  37.         $params['blocking'] = false;
  38.  
  39.         $response = wp_safe_remote_post( $request, $params );
  40.  
  41.         if ( is_wp_error( $response ) ) {
  42.             return $response;
  43.         }
  44.  
  45.         return true;
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement