Skip to content

Instantly share code, notes, and snippets.

@benheu
Last active July 3, 2022 14:25
Show Gist options
  • Save benheu/47aae6c48c642826a844685d39355bd2 to your computer and use it in GitHub Desktop.
Save benheu/47aae6c48c642826a844685d39355bd2 to your computer and use it in GitHub Desktop.
Track appointment bookings with Google Tag for Google analytics
<?php
function my_wappo_analytics_appointment_confirmed()
{
echo '<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>';
echo "<script>
window.dataLayer = window.dataLayer || [];
function gtag(){window.dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GA_MEASUREMENT_ID');
</script>";
echo '<script>';
echo "document.addEventListener('wappo_confirmed', function (e) {
gtag('event', 'wappointment', {'status': 'confirmed'});
}, false);";
echo '</script>';
}
add_action('wp_print_footer_scripts', 'my_wappo_analytics_appointment_confirmed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment