Integrating Gravity Forms and KISSmetrics

Recently I had to implement KISSmetrics with Gravity Forms for a client. Now as both of these are quite popular services, one would have thought there would be extensive documentation on how to best combine the two. Well, you’d be wrong…until now. Let me present my quick guide to integrating KISSmetrics and Gravity Forms!

KISSmetrics + Gravity FormsPlease note that while KISSmetrics does have default form tracking, it does not work well with Gravity Forms since you need to be able to specify field names. Unfortunately, one of the limitations of Gravity Forms is that field names are dynamically generated and cannot be specified. Using the KISSmetrics default form tracking only gives you field names like Input 1, Input 2, etc. (not very useful). And, as you cannot tag an email field as “email” KISSmetrics is unable to identify and track the user as anything but their standard anonymous ID.

So, that leaves us with having to set up the KISSmetrics API and the documentation on this is a bit lacking. Initially I tried to set it up with only the JavaScript API, but quickly ran into some limitations. It became apparent that using the PHP API was the way to go. Here are the steps to do that:

1. Install the KISSmetrics Javascript Tracking Code

Using the default Javascript tracking code for your site will create the anonymized identities that you need to track new users. I recommend using Google Tag Manager for this. Be sure to test this in the KISSmetrics Live tracking section of the admin to make sure it is properly installed.

2. Install the KISSmetrics PHP API code

At this time, KISSmetrics seems to be between two versions of their PHP API code. Their website documentation refers to the old API interface while their Github page refers to the new API. It’s a bit confusing. I’m going to use the old km.php file for these examples.

First, create a directory called “KISSmetrics” under your active theme and copy the km.php file to that folder. Make sure that the directory and file have read permissions.

3. Modify WordPress to call the KISSmetrics API on Gravity Form submission

The main file you will be changing is functions.php under your active theme. You’ll need to use the Gravity Forms hook “gform_after_submission” to call the KISSmetrics API after the form is submitted.

First, add your KISSmetrics API key to the end of your wp-config.php file. You’ll find your API key in the KISSmetrics admin for your account.

define('ENV_KS_APIKEY','XXXXYYYYXYXXYXYYXYXYXYXYXY');

Next, edit the functions.php file under the active theme. First, you’ll want to include the KISSmetrics API, so add this line near the top of the file:

require_once 'KISSmetrics/km.php';

Now, you’ll need to add both a call to the function as well as the function itself to the bottom of the functions.php file:


// Member Signup Form (Form ID 3)
add_action( 'gform_after_submission_3', 'form3_handler', 10, 1);

function form3_handler($entry){
	KM::init(ENV_KS_APIKEY);	
	$email = $entry['2'];
	
	$data  = array('First Name'=>$entry['6'],'Last Name'=>$entry['7'],'Email'=>$email,'Phone'=>$entry['3'],'Heard About'=>$entry['5']);
		
	if (isset($_COOKIE['km_ai'])) {
		KM::alias($_COOKIE['km_ai'], $email);
		KM::identify($email);
		KM::record('Member Signup Form Completed',$data);
	}
}

Some notes on this code:

  1. You’ll need to look up the form id under Gravity Forms. Use this ID for the add_action call as well as the handler (gform_after_submission_#, form#_handler). If you have multiple forms, you’ll need to duplicate this code using the different form IDs.
  2. You can access the form fields with the $entry[‘#’] where the # is the ID of that form field. Use a code inspector to find the form field ids for each form.
  3. The $data variable builds a list of all the form fields you want to submit to KISSmetrics. Edit as appropriate for your forms.
  4. You want to both alias and identify the user by email in KISSmetrics. You can read more about this in “Understanding Identities.”
  5. KM::record will record an event (name it what you want) and pass all  the data from the form to KISSmetrics.
  6. You can test that this is working in the KISSmetrics admin under the “Live” section. Please note that if using the “My Activity” tracking section, once you identify yourself, your activity no longer appears there due to a bug on their site. This can lead to hours of wasted debugging (personal experience). Use the main Live tracking feature for all people. It will make results much clearer.

That’s it. Hopefully these examples save you a few days of trial and error, but hey someone had to do it!

0

Feedly RSS Expander

Feedly Full RSS ExpanderWith the coming demise of Google Reader, it seems that there are only three real choices: Feedly, Digg Reader and AOL Reader. After trying out all of them, Feedly won me over  (Digg was a better experience, but too buggy at this time.).

That being said, none of them are a perfect replacement. I have found that Feedly is missing one of the things that I and many others used with Google Reader – the Super Full Feeds extension. This extension allowed you to take short RSS feeds (RSS snippets) and turn them into full content RSS feeds right in the browser. This made reading things much easier and snappier.

So, until there is a Super Full Feeds Extension for Feedly, the next best thing may be the Full Text RSS Feed website. This site allows you to input any RSS feed and get a new RSS link that contains the full feed. You can then add that URL to Feedly and get full content rather than just excerpts.

It’s not as simple as the Chrome extension was, but it will work for now…

 

 

1

Welcome To Spreadsave, A Social Coupon and Deals Site

I wanted to invite everyone to check out Spreadsave, a social online coupons and deals site, that I’ve been lucky to be a part of. We have a talented team based in New York, Berlin and Buenos Aires and just pushed out the beta version of the site.

Spreadsave is the world’s first truly social shopping site. While we’re still working on a lot of the best features of the site, we wanted to push the first version of the site out there for everyone to check out. You can sign up using Facebook connect, view daily deals across a variety of sites, and then when you use or share the coupons or deals earn “gold coins” that can be redeemed in our award store for cash and prizes.

Be sure to check out the best coupons and deals now as well as find us on Facebook and Twitter.

0