Ajax Form and Google Conversion Code

Permalink Browser Info Environment
Does anyone know of a way to get the Google AdWords conversion code to come up upon a successful form submission (if not redirected to another page -- the "success" message is loaded dynamically into the very same page)?

Thanks!
Darren

Type: Discussion
Status: New
dihakz
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
What is the "Google AdWords conversion code"? Is it the same code every time or different for each page view?
If it's different every time, I'm assuming it's somehow available via javascript -- do you know how to access it?

If you look at the top of the templates (packages/ajax_form/blocks/form/templates/ajax_default_layout.php or packages/ajax_form/blocks/form/templates/ajax_tableless_layout.php), you'll see some javascript code that runs after various circumstances. Look at this one:
function <?php echo $template_onsuccess_funcname; ?>(form, thanks) {

...and notice how it's taking the thanks message and putting it into the success div. If you know how to retrieve the conversion code then you could add a line here to append it to the thanks message.
dihakz replied on at Permalink Reply
dihakz
Well, yes, it cannot (should not) be visible to your browser at ALL before a form is submitted. That way, Google can track the visitor coming in and whether or not they FULLY completed and submitted a form. Typically, then, the code would ONLY appear on a page that is generally only accessible after submitting a form (often called the "success" page.)

The code is as follows:
<!-- Google Code for Lead Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 5555555555; // these are usually the correct numbers, but hiding them for the sake of demonstration only!
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "XXXXXXXXXXXXXX"; // again, not the correct label, used only to demonstrate
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
jordanlev replied on at Permalink Reply
jordanlev
GACK!!! The forum is flipping out on me. I posted the reply twice already but it kept getting messed up (in case you're just reading these responses via email).

Here is the full correct response:


There's probably a "best" way to do it with javascript but I couldn't tell you what that is without spending a decent amount of time looking into it. Instead I think if you use the "noscript" method they've provided that should be easier to implement (although it doesn't appear to send as much information, and also will make google think everyone has javascript disabled -- not sure if this is important to your metrics or not).

This is how you would do it. Find this line of code at the top of the template:
$(form).find('div.success').html(thanks).show();

...and replace it with this code:
var conversion_id = 5555555555;
var conversion_label = 'XXXXXXXXXX';
var gacode = '<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/' + conversion_id + '/?label=' + conversion_label + '&amp;guid=ON&amp;script=0"/>';
$(form).find('div.success').html(thanks + gacode).show();
dihakz replied on at Permalink Reply
dihakz
Thank you so much for this! I'll check it out, and see if it works, and report back! ;-)

Thanks again... I love the c5 community!!
dihakz replied on at Permalink Reply
dihakz
I did notice that, yes... the only problem I have is I do not know JavaScript at ALL! PHP is rough for me, but I can feel my way around, but I've never gotten around to learning JS.

Sooooo... I would not know how to properly format anything to be used for output there (especially so many lines of code!)
vbwebsites replied on at Permalink Reply
vbwebsites
I know this topic is a bit old but you can simply apply the conversion code to the Form > Edit Form > Options > Message displayed when completed (Paste here)
nyaaawn replied on at Permalink Reply
nyaaawn
I know this is an old thread, but perhaps you can help me with a similar problem. Having completely no background on AJAX, PHP, Javascript and the like, I really don't know how I should integrate the code suggested by jordan.

If it would of any help, here is the code for my site's contact form.

$("#contact_form").submit(function(e) {
      e.preventDefault();
      var contactId = $("#contact_form").attr('id');
      if ($("#contact_form").validate().form())   {
      $.php('/ajax/contact/submitEmailAjax',$("#contact_form").serialize());
      php.error = function(xmlEr, typeEr, except) {}
      php.complete = function(XMLHttpRequest, textStatus){
         alert('Message sent!');
         resetForm(contactId);
      }}
   });


Thanks in advance!

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.