Users who know JavaScript can expose an onSuccess event from Virtuous Form submissions. The success event can be used to track an event with platforms like Google Analytics or to display a custom message. In other words, a Form submission can be tracked through Google Analytics, or a custom message can be displayed after a Form has been submitted.
Users who know JavaScript can set up these hooks to transmit information from Virtuous Forms to Google Analytics. The full Form code options (as well as endpoint details) can be accessed here.
First, be sure to load your form embed in the HTML where you would like it displayed.
This is the base set of code used to expose an onSuccess event - this can be loaded in the header or footer:
VirtuousForms.settings = {
onSuccess: function(response) {
//track event here....
}
};
You can also prompt the onSuccess event in the same block you're using to modify Virtuous Forms:
VirtuousForms.settings = {
firstName: 'DEFAULT_VALUE',
lastName: 'DEFAULT_VALUE',
email: 'DEFAULT_VALUE',
onSuccess: function(response) {
//track event here....
}
};
What you add for the event you want to track will depend on where you want to track it. Here are ways to send data to Google Analytics specifically.
What will return: Say, for example, Ron Swanson (rswanson@pawneeparksandrec.org) makes a $50 donation from your online giving form. When the submission is made, this would be posted to Google Analytics:
var response = {
isDonation: true,
amount: 50.00,
formId: "0000-0000-0000-0000-0000",
segment: 'OG2022',
firstName: 'Ron',
lastName: 'Swanson',
email: 'rswanson@pawneeparksandrec.org'
};