Home Forums Add-ons Repeater Field Use repeater field for percentage based A/B testing


Use repeater field for percentage based A/B testing

  • I am currently using the ACF repeater field for A/B testing and am using several different text options for a newsletter signup form on my client’s website. And then I am tracking each of the various options and their success using Google Analytics. This all works great.

    However, I am wondering if there are any recommendations of how I could add another field to each repeater field/option where I could add in a percentage so that the options would be displayed on the site based on the percentage (right now it is just randomized). So, for example, if I had three options and one should be shown 80% of time on the site and then 10% and 10% for the other two.

    It seems like I would have to somehow write to the database every time the repeater field was shown on the site so that I could log which option was shown and then check against that to determine which one to show so the percentage based usage could be adhered to.

    Does that seem correct? Any recommendations would be appreciated.

  • You would need to have at least 2 other fields, or ways to store the information. You would need a field to set % of time to show a row and you would need some way to store how many times that row was shown and this field would need to be updated every time that row was shown.

    Code your currently using would be helpful for someone that wanted to help you figure it out.

  • No problem.

    Below is the code I am using to grab a random selection from a repeater field (‘after_options’).

    	$options = get_field( 'after_options', 'option' );
    	if( is_array( $options ) ) {
    		$option = array_rand( $options ); 
    		$signupHTML = $options[$option]['html'];
    <div class="signupAfter">
    	<div class="signupText">
    		<?php echo $signupHTML; ?>
    	<div class="signupForm">
    		<input type="text" name="fname" class="fname" placeholder="First">
    		<input type="text" name="lname" class="lname" placeholder="Last">
    		<input type="text" name="email" class="email" placeholder="Email">		 
                    <span class="button">Subscribe</span>
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.