How to track successfully submitted forms which use inline feedback
I need to track AdWords Conversions whenever a form is successfully submitted. A couple of points:
I can’t use GTM
The form doesn’t re-direct to a thank you page
I have a solution but looking at Google’s tag tool I’m sometimes getting a “No HTTP response detected” error. I can submit the form and it works fine, then I’ll submit it again two minutes later and I see an error.
Okay, here’s the code:
<script type="text/javascript">
var url = window.location.href
var index = url.indexOf("submissionGuid")
var track = index>=0 ? true : false;
console.log("track: " + track)
/* <![CDATA[ */
goog_snippet_vars = function() {
var w = window;
w.google_conversion_id = 10000095;
w.google_conversion_label = "MxO00000000wM";
w.google_remarketing_only = false;
}
// DO NOT CHANGE THE CODE BELOW.
goog_report_conversion = function(url) {
goog_snippet_vars();
window.google_conversion_format = "3";
var opt = new Object();
opt.onload_callback = function() {
if (typeof(url) != 'undefined') {
window.location = url;
}
}
var conv_handler = window['google_trackConversion'];
if (typeof(conv_handler) == 'function') {
conv_handler(opt);
}
}
/* ]]> */
if(track){
goog_report_conversion(url)
}
</script>
<script type="text/javascript"
src="//www.googleadservices.com/pagead/conversion_async.js">
</script>
Logic:
When the form is submitted a “submissionGuid” is added to the URL.
Check “submissionGuid” is present, fire the tracking code if so
Use the code AdWords provides for onClick() events, but wrap in an if so it instead runs when the “submissionGuid” is present
Sounds pretty straight forward, yes!? I also tried the default AdWords Tracking code but see the same issue.
This is a list of options that you can use if you just need to tweak a default hubspot form. If you need complete control over the styles and actions of your form, you will still want to use the Forms API.