Keep Track of that Form Submission

This is the tale of a sites with their own classified ads, when they wanted to track how often users who post a classified, were "contacted". Their goal was to be able to see if the classified were successful, based on the volume of responses to the classified ads. A great idea... now I have to implement it.

The setup and layout for this content type is pretty basic.. The Classified Listing is displayed as a panel. The top half is info about the listing (node), and the bottom half is a contact form (send user email form), that sends and email to the user who posted the listing, from the logged in user.

What Should I Do

My first idea was to find a module that already did it all for me.... no luck...

Next I thought I would try to use watchdog, and create some type of report... but I didn't want to go that route...

Then I decided to find a way to leverage the power of google analytics... a method that has been used many times... so why not.

As I entered this phase of discovery, I realized that the UX that was happening, when the logged in user responded to a post, was pretty bad... It was currently (i believe by default function of the 'send user email form') re-directing the user (who sent the form) to the profile page, of the user, who they just sent the email too... a pretty useless and unnecessary UX in this situation.

This further clarified to me that I needed a landing page, and would use google to track it. I was planning to use some kind of hook and redirect after submit. Something like Brian Vuyk suggested here http://www.brianvuyk.com/story-type/changing-redirect-value-drupal-node-... .

I decided to take one more look at the Rules module, and I was pretty impressed with what I found I could do. It took a little getting used to, but the end result was with the effort. Here's what I did, and some description about using Rules Forms Support.

The Set-up

Navigated to Rules -> For Events

I enabled:
[X] Enable event activation messages on forms

I wasn't sure what was happening, but I realized that in the button I enabled, specifically says "message on forms", which is exactly what it did. It provided a link, that would activate a rule, for the form on the page that I was viewing.

So, once you find the form you want to add actions to, you use the link, give it a label for use in rules... and you're ready to go. Oh, yeah, you'll want to remember to go back to Form Events and disable the messages.

For This Instance

In this specific situation, the form was the contact_user_form, and it is available in different places, I only wanted to track it from the classifieds.

I started by adding an "IF"
and used Execute custom PHP code, where I entered.....

$node = node_load(arg(1));
return $node->type == 'classified_listing';

What this did was it was able to verify that the node type was a classified_listing.
This meant that when the user contact form was executed from anywhere other than on a classified_listing, the resulting actions would NOT occur.

Lastly I added by "DO"
and used Page redirect
in the To: section, i added.... /node/{node#} (the node that serves at the "Thank You for Sending This Classified Poster a Message" page.

This combination of rules has accomplished two goals for the site. First, it has dramatically improved the user experience and provided quality feedback for their interaction. Secondly, it creates a page, specific to classified listings that can be tracked configured within google analytics as a goal, and provide some valuable information for the site owners.

This Just In

A great anonymous comment came in, and I wanted to add it here so it could be formatted.

/**
* Implementation of hook_form_FORM_ID_alter().
*/
function MYMODULE_form_contact_user_form_alter(&$form, $form_state) {
$form['#submit'][] = 'MYMODULE_count_classified_contact';
}

/**
* Submit callback to count classified contact.
*/
function MYMODULE_count_classified_contact($form, $form_state) {
$node = menu_get_object();
if ($node->type == 'classified_listing') {
drupal_goto('node/NID'); //or record in the database, which is what I would have done
}
}
?>

Comments

2

A great comment about doing this with php was posted, I added it to the post so it could be fomatted a little cleaner, thanks to whom ever left it here.. it's above if you are looking for it.

Hi, I have been looking around without finding the answer to a simple question: if I just want to track in Google Analytics, as a "goal", the submission of whatever contact form request, what is the easiest road? I'd need to do it without any programming though... thanks for your very useful blog! Luca