Created
August 20, 2021 18:53
-
-
Save rdhimanam/ffd644a43dda6bbb7a626d0c23a6cd0f to your computer and use it in GitHub Desktop.
Track Bookings - Simply Schedule Appointments Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function monsterinsights_ssa_track_successfully_booked_appointments( $appointment_id, $data, $data_before, $response ) { | |
if ( ! function_exists( 'ssa' ) ) { | |
return; | |
} | |
if ( empty( $data['status'] ) || $data['status'] !== 'booked' ) { | |
return; | |
} | |
if ( ! function_exists( 'monsterinsights_mp_track_event_call' ) ) { | |
return; | |
} | |
$args = array( | |
't' => 'event', // Required: Change the default type to event | |
'ec' => 'Appointments', // Required: Event Category | |
'ea' => 'Booking', // Required: Event Action | |
'el' => $data['status'], // Required: Event Label (User Input) | |
'ev' => '', // Required: Event Value, Rounded | |
'cid' => ! monsterinsights_get_uuid() ? monsterinsights_generate_uuid() : monsterinsights_get_uuid(), // Required: Google Client ID | |
); | |
monsterinsights_mp_track_event_call( $args ); | |
} | |
add_action( 'ssa/appointment/booked', 'monsterinsights_ssa_track_successfully_booked_appointments', 10, 4 ); | |
function monsterinsights_ssa_track_cancelled_appointments( $appointment_id, $data_after, $data_before, $response ) { | |
if ( ! function_exists( 'ssa' ) ) { | |
return; | |
} | |
if ( empty( $data_before['status'] ) || empty( $data_after['status'] ) ) { | |
return; // we don't want to send a hook if we don't have the pieces we need | |
} | |
if ( $data_after['status'] !== 'canceled' || $data_before['status'] !== 'booked' ) { | |
return; // we only want to send a webhook when an appointment goes from booked -> canceled | |
} | |
if ( ! function_exists( 'monsterinsights_mp_track_event_call' ) ) { | |
return; | |
} | |
$args = array( | |
't' => 'event', // Required: Change the default type to event | |
'ec' => 'Appointments', // Required: Event Category | |
'ea' => 'Booking', // Required: Event Action | |
'el' => $data_after['status'], // Required: Event Label (User Input) | |
'ev' => '', // Required: Event Value, Rounded | |
'cid' => ! monsterinsights_get_uuid() ? monsterinsights_generate_uuid() : monsterinsights_get_uuid(), // Required: Google Client ID | |
); | |
monsterinsights_mp_track_event_call( $args ); | |
} | |
add_action( 'ssa/appointment/canceled', 'monsterinsights_ssa_track_cancelled_appointments', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment