Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created August 2, 2019 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/eb9ad8053b29b0d2eff322fe9b1dbbd1 to your computer and use it in GitHub Desktop.
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.
<?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