In this feature, we will use google analytics universal gtag. So make sure you are using gtag.js on your site.
You can follow this tutorial to add custom js code to your site
How to Add Custom JavaScript to Your WordPress Site
Another source:
Option 1: Track per form basis
Add the following code to your site. You have to change YOUR-FORM-ID by your Form Id and you can change the event_category or event_label value based on your needs.
Option 2: Track Events For All Forms
Add the following code to your site. You can change the event_category or event_label value based on your needs.