I am attempting to fire a script once a users clicks on a submit button for a registration form on our website so that I can send that information back to Google Tag Manager and Google Analytics as an event. My goal is to track SUCCESSFUL registrations on our website. The script I have on my registration is as follows:
<script>
jQuery(document).ready(function() {
jQuery('body #gform_page_4_7').on('click', '#gform_submit_button_4', function() {
if (jQuery('#gform_submit_button_4').is(':visible')) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'successfulSubmission',
'FORM_ID': 'full_application'
});
}
});
});
</script>
This script is installed directly on my registration page www.x3tradesmen.com/registration and tracks when someone clicks on the submit button and sends that information back to Google Analytics. The issue with the script is that it fires each time someone clicks on the button and it does not look for successful submissions, therefore, if someone clicks on the submit button without filling the form out successfully it will track that as a successful form submission.
I know that I could create a private landing page to redirect to for successful submissions and fire the script only on that page, however, when a user successfully registers on our website, we need to redirect them to a public page.
Does anyone know if there is a way to have this script check and see if the form is successfully submitted before firing the script? If so, can you assist me with the proper script I need to implement?
I am using Wordpress as my CMS and Gravity Forms as my form plugin. Thanks in advance for any advice!
In case of successful registration on your site some parameters are added to URL:
https://www.x3tradesmen.com/candidate-dashboard/?email=test15%40test.com®istration=successful&eid=y1m%2BW%2FKY7opOBLAWMlzeEoq8q22Dt0TLcj9XbGJhza8%3D
You can use registration=successful
to send an event or create a goal.
For event in GTM you should to create a trigger: if URL contains registration=successful
.
Note: It's better don't add emails in URL, see GA Support about personal data: https://support.google.com/analytics/answer/6366371?hl=en.