Javascript in Rails remote_form_for partial

I have a contact form on my site that works with remote_form_for rails. After someone submits the form, the html in that div will be replaced with a success message and not the whole page reload (the reasons for this aren't overly relevant ... but basically this contact form is below the fold and I don't want to so that the page refreshes to the top if there are any error / success messages, etc.).

I'm trying to track Google AdWords conversions to see how many visitors submit to a contact form. The javascript he provided looks like this:

<!-- Google Code for Contact Tutor Conversion Page -->
<script type="text/javascript">
var google_conversion_id = SOME_NUMBER;
var google_conversion_language = "en_US";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "SOME_LABEL";
<script type="text/javascript" src="">
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src=";guid=ON&amp;script=0"/>


The problem is I am putting this in the partial for the "success" message for remote_form_for, not tracking any conversions!

I guess my question is, how will browsers execute javascript in an Ajax call like where the html in the div gets replaced with the new html?

I tested it a bit by putting a "warning (" hey ") in the first javascript block. It gets executed. Then I tried to extract the javascript from that url and paste it directly into. .. it seems to be running now and is tracking some conversions - but appears to be under reporting. I also tried commenting everything out and just using the image tag to track the conversions. This also gets some, but appears to be under report.

It is difficult to measure under the reporting part, but it seems to be very significant ... 50% maybe? I am wondering if this is the difference in the way the browser executes javascript. I wouldn't mind setting up my own conversion tracking so I can be more confident about it ... but I need to figure out how to define an adwords ad set, etc.

Any ideas?


source to share

1 answer

If the image is under-rendered at the same rate as Javascript, I would conclude that your code is working correctly, but the report is not what you expect. What metric are you using for validation?

Try to call the image through your site url which redirects the google image.


class TrackingController < ApplicationController
  def track
    redirect_to "http://googleadwordsimage.png"


Then you can compare what the analytics shows to what your internal database is showing. This will determine if the problem is that your code is not being called in all browsers, or the analytics are simply wrong. If they are not correct, perhaps it is due to some setting to stop double counting for the same user or something else? It's hard to know without knowing more about your metrics, etc.



All Articles