Skip to content

Instantly share code, notes, and snippets.

@freezvd
Forked from robneu/gform-split-test.php
Last active August 29, 2015 14:24
Show Gist options
  • Save freezvd/29776909bc3efe1aeb7e to your computer and use it in GitHub Desktop.
Save freezvd/29776909bc3efe1aeb7e to your computer and use it in GitHub Desktop.
<?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