Last active
July 3, 2022 14:25
-
-
Save benheu/47aae6c48c642826a844685d39355bd2 to your computer and use it in GitHub Desktop.
Track appointment bookings with Google Tag for Google analytics
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 | |
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