Simple Split Testing with Gravity Forms

Which version of your form performs the best? Split Testing for Gravity Forms will help you find out.

March 5th, 2014: Fixed issue where validation errors would sometimes result in another form being loaded. Byproduct of this fix: multi-page forms are now supported.

Matt Medeiros wrote an awesome article about A/B Testing with Gravity Forms (also known as split testing). Matt shared a small function which accepts two Gravity Form IDs. The provided form IDs are randomly alternated so each form is displayed about half of the time. A handy little function!

Feeling a bit inspired, I thought it might be easier for user’s to implement if this were available as part of the [gravityform] shortcode. I also figured it couldn’t hurt to add support for more than two forms.

How do I get started?

  1. Copy and paste the snippet into your theme’s functions.php file.
  2. Configure the shortcode via the instructions below.

The Shortcode

[gravityforms action="split_test" ids="1,2"]

Shortcode Parameters

  • action
    Use “split_test” to activate the split test functionality.
  • ids
    A comma-delimited list of form IDs which should be displayed.

Learn about the split test shortcode and other Gravity Forms shortcodes in our comprehensive guide.

Function Call

If you need to implement this in a template file or other advanced usage, you can make use of the function call.

if ( function_exists( 'gw_split_testing' ) ) {
	echo gw_split_testing()->get_split_test_form( $form_ids, $attributes );
}

Function Parameters

  • $form_ids (array) An array of form IDs that should be randomly alternated for display.
  • $attributes (array) An array of settings used to configure form properties. Settings include:
    • title: (bool) Whether to display the form title. Defaults to true.
    • description: (bool) Whether to display the form description. Defaults to true.
    • ajax: (bool) Whether to enable AJAX for the displayed form. Defaults to false.
    • tabindex: (int) The starting tab index for displayed form.

Basic Usage

In this example, we pass form IDs “1” and “2” to the split testing function.

if ( function_exists( 'gw_split_testing' ) ) {
	echo gw_split_testing()->get_split_test_form( array( 1, 2, ) );
}

Advanced Usage

In this example, we pass form IDs “1” and “2” and set the title, description and ajax options.

if ( function_exists( 'gw_split_testing' ) ) {
	echo gw_split_testing()->get_split_test_form( 
		array( 1, 2, ),
		array( 
			'title'       => 'true', 
			'description' => 'false',
			'ajax'        => 'true',
		)
	);
}

How do I measure the effectiveness of the forms?

Gravity Forms has built-in conversion tracking for all your forms. You can see how many views each form has and how many entries. In the far right column, you can see the “Conversion” percentage. The higher the percentage the more effective the form is at getting users to fill it out.

split-testingExample of Gravity Forms Forms List View Conversion Column

Summary

For more details on the benefits of split testing, make sure you check out Matt’s original article.

Have suggestions to improve this functionality? Let me know in the comments!

Comments

    1. Clay Griffiths
      Clay Griffiths Staff August 30, 2023 at 11:03 am

      Hi Lev,

      Thanks for the heads-up!

      Our caching was a bit too aggressive on the demo. It should be working now. 😃

  1. Simon
    Simon August 6, 2021 at 11:08 am

    It would be great if we could A/B split test on individual form elements rather than switching out entire forms.

    So for example ‘show field X’ to half my users and not the other half – and compare the results.

    This would make it easy for example to tell marketing teams:

    “We added in the 5 pieces of personal info you want and guess what, the conversion rate dropped by 99%”. Instead of having to duplicate an entire form and manage both. Would that be possible with some wiz magic?

    Reply
    1. David Smith
      David Smith Staff August 6, 2021 at 9:40 pm

      Definitely see lots of potential for this but would take a good bit of effort to build. My hot thought here for an immediate solution would be to add all possible fields and then use something like Google Optimize to remove those fields as a variation. This would give you some pretty robust results and a number of different ways to measure how well the form is converting and where it’s falling short.

  2. Crisanne Glasser
    Crisanne Glasser January 12, 2021 at 11:25 am

    Hey David,

    This code works awesome!

    I’m noticing though that if my theme has an update, the update clears the PHP snippet out with the update. Has anybody found a workaround for that through the years? I didn’t realize for a few hours and because the code cleared I had no contact form at all on my site.

    Reply
  3. Mason Lawlor
    Mason Lawlor April 1, 2016 at 1:32 am

    Hey David! Love this script and got it working on one of my sites earlier this week. I’m trying to think of how to extend it’s usability.

    I would love the ability to generate dynamic content based on which form is showing.

    For example:

    Let’s say I have a toll-free number on my page and I’d like to link up 2 #s to test which one converts best when a particular form is shown. Maybe my long form has a better call-in conversion rate.

    Or say I have a heading above the form that says something different based on which form is showing. (i.e. “Enter your phone number below” vs. “Enter your email and phone number below”.

    Would love to know if this is even feasible. Thanks! Mason

    Reply
    1. David Smith
      David Smith Staff April 1, 2016 at 9:03 am

      Hi Mason, I took a look through the code to see if this is something that could be easily implemented but it just isn’t set up very well for anything besides split testing the Gravity Forms themselves. You might need a more robust split testing solution for your goals.

  4. zak loh
    zak loh July 19, 2014 at 5:38 pm

    Hi, I cannot get this to work. Am I supposed to paste the code shown at

    https://gist.githubusercontent.com/spivurno/8292521/raw/gw-gravity-forms-split-testing.php

    and then paste the following code below the above:

    Basic Function Usage

    if( function_exists( ‘gw_split_testing’ ) ) { echo gw_split_testing()->get_split_test_form( array( 1, 2, ) ); }

    I’m guessing (noobie here) that if I paste this at the bottom of my functions file that it shoudl be before

    <?php
    

    }

    Would so appreciate your help.

    Thanks

    Zak

    Reply
  5. John Kirker
    John Kirker June 19, 2014 at 9:09 pm

    Hi David,

    I’m digging this. I’ve got it working if I use a shortcode, however if I use the advanced PHP function I’m not getting any output.

    I’ve done an echo ‘hello’; after the IF condition and that part is passing – however I’m not getting any love beyond that.

    No errors – nothing strange with debug turned on.

    Form at top: http://windoronline.com/win-dor-locations

    Happy to pay for your time for some help.

    I’ll email the pastie link as I don’t want to expose it publicly.

    Reply
    1. David Smith
      David Smith Staff June 22, 2014 at 2:10 pm

      Per our email exchange, I’ve updated the function usage examples to indicate that you need to echo the results of the function out. Thanks for confirming that this worked for you, John.

  6. Damien
    Damien March 28, 2014 at 6:59 pm

    Thanks for this tutorial. Maybe you could offer it as an extension for GF somehow :)

    I’m with WPE too — it would be good if they made it possible to exclude URLs from caching in the dashboard somehow rather than having to email support.

    Reply
    1. David Smith
      David Smith Staff March 29, 2014 at 7:46 am

      Thanks for the feedback. I definitely wouldn’t mind offering this as a perk. And HUGE second on being able to exclude URLs from caching in the dashboard… I hate to have to contact them every time, but at least they are quick to respond.

  7. Alex
    Alex February 21, 2014 at 12:08 pm

    I’m noticing a problem using your snippet with multi-page, non-ajax enabled forms. When I submit one of those forms, the snippet code seems to run for some reason instead of actually submitting, so that final submission button is taking me back to page 1 of whatever form wins the random roll. It’s odd, but seems to not be a problem when ajax is enabled.

    Reply
    1. David Smith
      David Smith Staff March 5, 2014 at 10:40 pm

      Hi Alex, I’ve updated this snippet to resolve this issue. See the March 5th update at the top of the post for more details.

  8. Adam W. Warner
    Adam W. Warner January 9, 2014 at 9:46 am

    Hi David, just came here from Matt’s article. Great stuff:)

    Tried viewing your demo and refreshing (a lot) and never saw Form A, only B.

    Tried in several browsers.

    Can you confirm your demo is working as expected?

    Reply
    1. David Smith
      David Smith Staff January 9, 2014 at 9:51 am

      Hey Adam, I realized last night that my host’s caching was preventing this demo from working. I’ve got a support ticket in with them and anticipate the demo will be working correctly very soon. I’ll post a follow up once I’ve confirmed. Thanks for checking up!

    2. David Smith
      David Smith Staff January 9, 2014 at 2:10 pm

      I’m with WP Engine as well. They’ve removed the demo page from the cache and it’s working correctly for me. Looks like you will need to have any page you’re using this on excluded from WPE’s caching. Assuming it wouldn’t be a problem to include it in the cache again after your A/B testing is complete.

      Also, will send you an email shortly. :)

    3. Adam W. Warner
      Adam W. Warner January 9, 2014 at 10:58 am

      Good to know David, who’s your host?

      I ask because we’re using WPE and have had to have several urls excluded from their caching (for eCommerce) so I’m wondering if the caching will be an ongoing issues with this script that will affect the actual A/B intent. Know what I mean?

  9. Nate
    Nate January 7, 2014 at 3:47 pm

    This is awesome! I’m excited to test this on a new site we just created using Gravity Forms as the ordering process. Thanks!

    Reply
    1. David Smith
      David Smith Staff January 7, 2014 at 6:30 pm

      Glad to hear it, Nate! Let me know how it works for you and any suggestions you have to improve it.

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.

Download Plugin

Simple Split Testing with Gravity Forms

This field is for validation purposes and should be left unchanged.