PHP code example of taplytics / taplytics-php

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

    

taplytics / taplytics-php example snippets


$client = new TaplyticsLib\TaplyticsClient();

$client = $client->getClient();

function createGetVariables(
        $token,
        $userId,
        $body = null)

$token = 'token';
$userId = 'user_id';
$body = new Body();

$result = $client->createGetVariables($token, $userId, $body);


function createGetVariationForExperiment(
        $token,
        $userId,
        $experimentName,
        $body = null)

$token = 'token';
$userId = 'user_id';
$experimentName = 'experimentName';
$body = new Body();

$result = $client->createGetVariationForExperiment($token, $userId, $experimentName, $body);


function createGetVariableValue(
        $token,
        $userId,
        $varName,
        $defaultValue,
        $body = null)

$token = 'token';
$userId = 'user_id';
$varName = 'varName';
$defaultValue = 'defaultValue';
$body = new Body();

$result = $client->createGetVariableValue($token, $userId, $varName, $defaultValue, $body);


function createGetBucketing(
        $token,
        $userId,
        $body = null)

$token = 'token';
$userId = 'user_id';
$body = new Body();

$result = $client->createGetBucketing($token, $userId, $body);


function postEvent(
        $token,
        $userId,
        $body = null)

$token = 'token';
$userId = 'user_id';
$body = array(
	'events' => array(
	        		array('eventName' => 'event name!', 'eventValue' => 5)
				)
);

$result = $client->postEvent($token, $userId, $body);


function createGetConfig(
        $token,
        $userId,
        $body = null)

$token = 'token';
$userId = 'user_id';
$body = new Body();

$result = $client->createGetConfig($token, $userId, $body);


function createGetFeatureFlags(
        $token,
        $userId,
        $body = null)

$token = 'token';
$userId = 'user_id';
$body = new Body();

$result = $client->createGetFeatureFlags($token, $userId, $body);
foreach($result as $flagObj) {
        // $flagObj->name to get the name of the feature flag
        // $flagObj->keyName to get the key of the feature flag
}

function isFeatureFlagEnabled(
        $token,
        $userId,
        $keyName,
        $body = null)

$token = 'token';
$userId = 'user_id';
$keyName = 'featureFlagKey';
$body = new Body();

$result = $client->isFeatureFlagEnabled($token, $userId, $keyName, $body);
if ($result) {
        showFeature();
}