Skip to content

Instantly share code, notes, and snippets.

@robneu
Last active January 2, 2016 10:19
Show Gist options
  • Save robneu/8289103 to your computer and use it in GitHub Desktop.
Save robneu/8289103 to your computer and use it in GitHub Desktop.
Create an A/B Split test using GravityForms
<?php
/**
* Create a split test using two different GravityForms
*
* Allows you to test the effectiveness of two different forms by displaying each
* one 50% of the time. Tracking CTR using the built-in GravityForms functionality
* should give you an idea of which form is most effective.
*
* @uses GravityForms
* @author FAT Media, LLC
*/
function prefix_setup_gform_test( $id_1, $id_2 ) {
// Do nothing if we have no forms.
if ( ! $id_1 || ! $id_2 ) {
return;
}
// Choose each form 50% of the time.
$gform_id = mt_rand(0, 1) ? $id_1 : $id_2;
// Display Subscribe Form
$gravity_form = do_shortcode( '[gravityform id="' . $gform_id . '" description="false"]' );
return $gravity_form;
}
// Display the forms.
echo prefix_setup_gform_test( 1, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment