Created
August 2, 2019 18:41
-
-
Save joshfeck/eb9ad8053b29b0d2eff322fe9b1dbbd1 to your computer and use it in GitHub Desktop.
Tracking code example for Event Espresso 4. Adds event-specific tracking code to the thank you page if "tracking_value" custom field is set in event.
This file contains 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
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
add_action( | |
'AHEE__thank_you_page_overview_template__top', | |
'my_custom_tracking_code_function' | |
); | |
function my_custom_tracking_code_function($transaction) { | |
if ( $transaction instanceof EE_Transaction ) { | |
$registrations = $transaction->registrations(); | |
$registration = reset($registrations); | |
if ( $registration instanceof EE_Registration ) { | |
$event = $registration->event(); | |
if ( $event instanceof EE_Event ) { | |
$tracking_value = get_post_meta( $event->ID(), 'tracking_value', true ); | |
if ( $tracking_value != '' ) { | |
$tracking_code = '<script>/* JavaScript tracking code begin'; | |
$tracking_code .= $tracking_value; | |
$tracking_code .= 'end of tracking code */</script>'; | |
echo $tracking_code; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment