Getting Started

The Taplytics PHP SDK can be found through the Taplytics PHP GitHub repository. This SDK enables the delivery of server-side experiments, feature flags and functionality at edge.

📘

The generated code has dependencies over external libraries like UniRest. These dependencies are defined in the composer.json file that comes with the SDK. To resolve these dependencies, we use the Composer package manager which requires PHP greater than 5.3.2 installed in your system. Visit https://getcomposer.org/download/ to download the installer file for Composer and run it in your system. Open command prompt and type composer --version. This should display the current version of the Composer installed if the installation was successful.

Using command line, navigate to the directory containing the generated files (including composer.json) for the SDK.

Run the command composer install. This should install all the required dependencies and create the vendor directory in your project directory.

Initialization

API client can be initialized as following.

$client = new TaplyticsLib\TaplyticsClient();

Identification

All method calls to Taplytics require a user id. This is to ensure that the user will always receive the correct experiments and variations across all platforms.

Custom User Data

To set custom user data for the current user, add an array associated to the key "customData" with all custom user attributes that you'd like to include.

Example:

$userId = 'test_user';

$body = [
    "attributes" => array(
        "email" => "[email protected]",
        "customData" => array(
            "employee" => true,
            "numberOfVisits" => 8
        )
    )
];

Class Reference

APIController

Get singleton instance

The singleton instance of the APIController class can be accessed from the API Client.

$client = $client->getClient();

createGetVariables

All variables and their values for the given user

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for given user
bodyOptionalAll relevant attributes associated with the user

Example Usage

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

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

createGetVariationForExperiment

For a given experiment, determine whether or not a user is in the experiment, and in which variation

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for given user
experimentNameRequiredName of an Experiment
bodyOptionalAll relevant attributes associated with the user

Example Usage

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

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

createGetVariableValue

Value for given Taplytics Dynamic Variable. If a user is not in an experiment containing the variable, the response be the provided default value in the query params.

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for given user
varNameRequiredname of variable
defaultValueRequireddefault value to be used if user does not have variable available.
bodyOptionalAll relevant attributes associated with the user

Example Usage

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

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

createGetBucketing

Returns a key/value pairing of all experiments that the user has been segmented into, as well as the variation the users are assigned.

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for current user
bodyOptionalProvide all relevant attributes associated with the user

Example Usage

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

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

createGetConfig

Returns the entire configuration for the project. This is the document that informs the experiment information such as segmentation. Extremely verbose and should be used for debugging.

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for given user
bodyOptionalAll relevant attributes associated with the user

Example Usage

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

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

createGetFeatureFlags

Returns the list of feature flags with names and key names.

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for given user
bodyOptionalAll relevant attributes associated with the user

Example Usage

$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
}

isFeatureFlagEnabled

Returns true or false based on if the keyName passed in is an enabled feature flag.

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

Parameters

ParameterTagsDescription
tokenRequiredSDK token for the project
userIdRequiredID for given user
keyNameRequiredkey name for the feature flag
bodyOptionalAll relevant attributes associated with the user

Example Usage

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

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

Did this page help you?