1

I have a form which redirects to a third party site. My client wishes to register a conversion when this form is submitted.

I've used the click tracking script as described by Google here.

My form's submit button then has the following code:

<input type="submit" value="SUBMIT &gt;"  onclick="goog_report_conversion('http://www.example.com/conversion')"  />

My assumption was that this would work the same as if someone had landed on http://www.example.com/conversion, without actually going to that page, and thus my client could configure his GA to register hitting that URL as a conversion.

I assumed that http://www.example.com/conversion didn't actually need to exist, but I created it as a blank page to be on the safe side.

However, when this onclick event is triggered, it redirects to http://www.example.com/conversion rather than submitting the form (in Chrome, anyway).

The part of the tracking code causing this seems to be the following:

var opt = new Object();
      opt.onload_callback = function() {
      if (typeof(url) != 'undefined') {
        window.location = url;
      }

Is this because I have misunderstood what goog_report_conversion does, and as such should I be looking at a different way to report a click as a conversion? Or is there a configuration option in GA that says to redirect or not redirect to goog_report_conversion's parameter?

Thanks in advance.

  • Why the conversion is being tracked via an onclick, rather than an onsubmit? – Bronwyn V Oct 6 '17 at 10:33
  • To be honest, that's just because the Google example was onclick and I was sticking to that as much as possible. The order the events loads is the same with either call, though. – Richard B Oct 6 '17 at 10:55
-1

Adding return false; should prevent the link in the onclick from being followed. eg

<input type="submit" value="SUBMIT &gt;"  onclick="goog_report_conversion('http://www.example.com/conversion'); return false;"  />
  • That would stop the form being submitted, but would make no difference to how goog_report_conversion runs. – Richard B Oct 6 '17 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.