How to Capture AdWords leads in Salesforce – Use a Little Gravity

January 14, 2014 | Posted in Software & Services, Technology and tagged , ,

gfgasf

When I first heard about Gravity Forms for WordPress, I thought to myself, who would ever need anything other than a contact form on their site. This software looked so difficult to employ and really useful features were mostly undocumented. But soon I realized that this is THE software to use for extensive form data collection and calculable results. With a little elbow grease, you can create incredible layouts, conditional displays, multi-page forms, pre-populate hidden fields, collect valuable Google AdWords data and track your leads in SalesForce. This article will touch upon undocumented ways to make your forms collect and disseminate accurate data to various touch points.

A solid marketing plan is only as good as the software used to collect results. Businesses can spend thousands of dollars trying to get a good lead, and finding a suite of products that will help you turn those leads into a sale should is paramount. Small businesses can use fairly simple efforts to turn a search result into a click-through, into a lead, into a sale; and it starts with advertising, reaching the consumer, collecting information, and acting upon it.

Grab Your Tools!

Google AdWords is a great platform for targeting keywords and audiences. Salesforce is a great way to collect leads and keep track of customer information. Gravity Forms brings these two together to create your complete sales circle.

This lesson assumes you’ve signed up for these services and you’ve purchased, installed and activated your Gravity Forms software and installed and activated the free Salesforce Add-on plugin.

Now let’s start out with some fairly simple code which will help store keyword data from a paid Google advertisement that you have setup.

You can give a mouse Cookies then he’s going to want a Querystring

Mom’s and Dad’s know the story, and it holds true for website developers. One always follows the other. Let’s say you created a Landing Page of some sort that you want your search engine advertisement to link through to. You’ll notice that on the end of the URL (applies to Google AdWords in this case) there is a querystring parameter which contains something along the lines of this: ?src=the+keywords+i+searched+for

This is what we’ll need to ‘get’ into the WordPress site, and eventually into a Gravity Forms hidden field to pass along to Salesforce. The first thing you’ll want to do is ‘cookie’ that term, so in case people click around on your website after they’ve reached the Landing Page, this value will be stored for a set amount of time that you determine.

// Referral src cookie - must be called before everything!
if(isset($_GET['src']) && !empty($_GET['src'])) {
	//first, delete cookie
	setcookie('adwords_src', '', time() - 3600, '/');

	//then, set cookie
	$ref = trim($_GET['src']);
	setcookie('adwords_src', $ref, time() + 86400, '/');
}

You’ll need to place this code before everything, at the top of the header.php file, even before your DOCTYPE. This will first delete any cookies with the ‘adwords_src’ value, then set the cookie with the new value from the querystring. But wait, this doesn’t actually GET the src parameter into the Gravity Forms because even though a cookie gets set before the web page is rendered, it actually can’t be retrieved in a Gravity Forms function until after the page loads.

I’d like to Dynamically Populate your Hidden Field

Now for some fun! Gravity Forms offers a filter for pre-populating any type of field, BEFORE the form renders, with a value from just about anywhere, including your WordPress pages or posts (even custom fields) or from a querystring. The filter is named ‘gform_pre_render’. To use it, you simply create a hidden field in your form; in the Properties tab add a Field Label (something easily viewable/readable), click on the Advanced tab and activate the checkbox next to ‘Allow field to be populated dynamically’. In the Parameter Name type any text that you will use to denote the type of field you’d like to see populated. In my example, I’ll be tracking the src parameter so my Parameter Name will be ‘adwords_src’ (note: you can use underscores but don’t use spaces). Here’s how it would look:

add_filter("gform_pre_render", "my_populate_adwords_src_field");
add_filter("gform_admin_pre_render", "my_populate_adwords_src_field");
function my_populate_adwords_src_field($form){
   //Adding items to field based on inputName (Parameter Name).
   if($form["id"] == 1 && !is_admin()) {
      foreach($form["fields"] as &$field) :
         //Get src from google adwords url, or get cookie into gravity forms
         if($field["inputName"] == 'adwords_src') {
            if(isset($_GET['src']) && !empty($_GET['src'])) {
               $field['defaultValue'] = trim($_GET['src']);
            } else {
               $field['defaultValue'] = $_COOKIE['adwords_src'];
            }
         }
   }
   endforeach;
   return $form;
}

Here’s what this does: It goes through all the forms on the Landing Page as it renders. If it finds Gravity Forms ID 1, and the form is not on the admin dashboard (more on this later), then it goes through all the fields in that form and checks if the field’s inputName equals the Parameter Name ‘adwords_src’. If so, then if the URL has a querystring src value (or is not empty), we populate the hidden field with that value [defaultValue]. And since we already stored the value in a cookie (previous example), if the visitor proceeds to go to another page on your website, and comes back to your Landing Page, since it won’t have a querystring value anymore, it will use the value stored in the cookie. Smart!

One more thing, you’ll notice the ‘gform_admin_pre_render’ filter. You might have other fields that you want pre-populated within the form editor in the WordPress admin, like a dropdown that needs conditional statements, so we use this filter to run the same function. And if we don’t want a field pre-populated in the admin, you can just use the if(!is_admin()) function to bypass it. This is especially necessary because if you decide to re-save the form you are editing in the admin, it will actually save that data for EVERY visitor, which is what you don’t want to occur when dynamically storing the querystring variable.

I’m About To Take The Lead, Catch Me If You Can

Now that you’ve successfully stored the keyword value, it’s up to the visitor to fill out your form and submit it so that you can capture the lead in Salesforce and act accordingly. The Salesforce Add-on does just that for you, automatically. Just set up a your Salesforce Web-To-Lead settings with your Salesforce Org ID, and go to your Form Settings -> Salesforce Web-To-Lead section and add a new ‘feed’. Map your fields, including the hidden one to a custom field ID/Name which you setup in Salesforce (the good folks at Salesforce will be happy to discuss how to do that). Save your settings and that’s all! Now when a searcher clicks through from your paid Google ad to your website, lands on your Landing Page, and fills out the form, you will have received the lead in Salesforce, at which time it’s up to you to act upon it and “catch that customer”.

About Scott Weiss

Scott Weiss is the founder of Somethumb, a creative services agency focused on web design and development. "Like" us on Facebook, "Follow" us on Twitter, "Plus-One" us on Google+, "Connect" with us on LinkedIn, and view our portfolio on Somethumb.com.

Comments are closed.

Industries

© 2003-2019 Somethumb™ Company2244 Oak Grove Rd, #30030, Walnut Creek, CA 94598 925­-695-7925Contact Us

Creative Ideas. Intelligent Solutions. Lasting Impressions.™
Local. Personal. Service.