PHP code example of tixelrocks / abtest

1. Go to this page and download the library: Download tixelrocks/abtest library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tixelrocks / abtest example snippets



// config/ab.php

return [
    [
        // A/B testing a piece of text
        'control' => 'Continue',
        'treatment' => 'Finish',
        'name' => 'Purchase Button Test'
    ],
    [
        // A/B testing two view templates
        // We will try to use common.welcome-control and common.welcome-treatment templates
        'view' => 'common.welcome',
        'name' => 'Purchase Button Test'
    ]
];


    // somewhere in app\Http\Kernel.php
    protected $middlewareGroups = [
        'web' => [
            SetAbTestCookie::class,
            ...
    ]

    <button>
        {{ abTest('Purchase Button Test') }}
    </button>

    <button>
        @abTest('Purchase Button Test')
    </button>

    @

   <button
    data-ga="event"
    data-event-category="{{ abTest('Purchase Button Test')->id() }}"
    data-event-action="Clicked"
    data-event-label="{{ abTest('Purchase Button Test')->description() }}"
   >
     @abTest('Purchase Button Test')
   </button>

   <h3>
    @abTest('Purchase Button Headline')
   </h3>
   
   <button
    data-ga="event"
    data-event-category="{{ abTest('Purchase Button Headline')->id() }}"
    data-event-action="Clicked"
    data-event-label="{{ abTest('Purchase Button Headline')->description() }}"
   >
    Buy
   </button>

// Somewhere in our Blade template
<x-abtest-ga-event
    category="{{ abTest('Purchase Button Test')->id() }}"
    action="Opened"
    label="{{ abTest('Purchase Button Test')->description() }}"
></x-abtest-ga-event>

Route::get('/ab', function () {
    Artisan::call('abtest:find-files');

    return '<pre>'. Artisan::output() . '</pre>';
});