PHP code example of pivotalso / pivotal-ab

1. Go to this page and download the library: Download pivotalso/pivotal-ab 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/ */

    

pivotalso / pivotal-ab example snippets


    'providers' => ServiceProvider::defaultProviders()->merge([
        ...
        pivotalso\PivotalAb\PivotalAbServiceProvider::class,
    ]),

  ....
  use pivotalso\PivotalAb\Events\Track;
  use pivotalso\PivotalAb\Listeners\TrackerLogger;
  
  class EventServiceProvider extends ServiceProvider {
       protected $listen = [
        ...,
        Track::class => [
            TrackerLogger::class,
        ],
    ];
bash
php artisan vendor:publish --tag="ab-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="ab-config"

/// ab.php
return [
    'cache_key' => 'laravel_ab_user',
    'request_param'=> env('LARAVEL_AB_REQUEST_PARAM', 'abid'), /// listen for query string param to override instance id
    'allow_param'=> env('LARAVEL_AB_ALLOW_PARAM', false), /// allows for the use of request param
    'api_key' => env('LARAVEL_AB_API_KEY', ''), // the api key for pivotal intelligence
];

 welcome.blade.php
bash 
class PagesController extends Controller
{
    public function welcome()
    {
       $option =  
       Ab::choice('kind of homepage', ['control', 'variant'])->track('go-to-ab');
       if ($option === 'variant') {
           return view('variant-welcome');
        }
       return view('welcome');
    }
 register.blade.php
RegistrationController.php

    public function store(Request $request)
    {
        .... store logic
        PivotalAb::goal('sign up');
        if($request->has('free_trial')) {
            PivotalAb::goal('free trial');
        }
    }
bash
php artisan ab:report