How to ad GTag tracking for form submissions

This is a WordPress site with IS forms embedded in iframes. in Contact Form 7, it’s possible to add event tracking to track when a form’s submit button is clicked.

function track() {
if (is_page(23)) {
?>
    <script>
document.addEventListener( 'wpcf7submit', function( event ) {
gtag('event', 'Click', {'event_category': 'Button Clicks','event_label': 'ContactUs'});
}, false );
</script>
<?php
     }
else {
?>
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
gtag('event', 'Click', {'event_category': 'Button Clicks','event_label': 'CheckAvailability'});
}, false );
</script>
 <?php
     }
}
add_action('wp_head' , 'track');

I want to be able to do the same thing with the IS forms. How can I do this?