Download the PHP package absmartly/php-sdk without Composer

On this page you can find all versions of the php package absmartly/php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-sdk

A/B Smartly SDK

A/B Smartly PHP SDK

Compatibility

The A/B Smartly PHP SDK is compatible with PHP versions 7.4 and later. For the best performance and code readability, PHP 8.1 or later is recommended. This SDK is being constantly tested with the nightly builds of PHP, to ensure it is compatible with the latest PHP version.

Getting Started

Install the SDK

A/B Smartly PHP SDK can be installed with composer:

Import and Initialize the SDK

Once the SDK is installed, it can be initialized in your project.

You can create an SDK instance using the API key, application name, environment, and the endpoint URL obtained from A/B Smartly.

Note that the above example uses named parameters introduced in PHP 8.0. Although it is strongly recommended to use the latest PHP version, PHP 7.4 is supported as well. On PHP 7.4, parameters are only passed in their order, as named parameters are not supported.

Example:

The above is a short-cut that creates an SDK instance quickly using default values. If you would like granular choice of individual components (such as a custom event logger), it can be done as following:

SDK Options

Config Type Required? Default Description
endpoint string undefined The URL to your API endpoint. Most commonly "your-company.absmartly.io"
apiKey string undefined Your API key which can be found on the Web Console.
environment "production" or "development" undefined The environment of the platform where the SDK is installed. Environments are created on the Web Console and should match the available environments in your infrastructure.
application string undefined The name of the application where the SDK is installed. Applications are created on the Web Console and should match the applications where your experiments will be running.
retries int 5 The number of retries before the SDK stops trying to connect. timeout int 3000 An amount of time, in milliseconds, before the SDK will stop trying to connect.
eventLogger \ABSmartly\SDK\Context\ContextEventLogger null, See Using a Custom Event Logger below A callback function which runs after SDK events.

Using a Custom Event Logger

The A/B Smartly SDK can be instantiated with an event logger used for all contexts. In addition, an event logger can be specified when creating a particular context in the ContextConfig.

Alternately, it is possible to implement \ABSmartly\SDK\Context\ContextEventLogger interface with handleEvent() method that receives the Context object itself, along with a ContextEventLoggerEvent object as shown below:

The data parameter depends on the type of event. Currently, the SDK logs the following events:

eventName when data
"Error" Context receives an error Exception object thrown
"Ready" Context turns ready ContextData object used to initialize the context
"Refresh" Context->refresh() method succeeds ContextData used to refresh the context
"Publish" Context->publish() method succeeds PublishEvent data sent to the A/B Smartly event collector
"Exposure" Context->getTreatment() method succeeds on first exposure Exposure data enqueued for publishing
"Goal" Context->Track() method succeeds GoalAchivement goal data enqueued for publishing
"Close" Context->lose() method succeeds the first time null

Create a New Context Request

Synchronously

With Prefetched Data

Refreshing the Context with Fresh Experiment Data

For long-running contexts, the context is usually created once when the
application is first started. However, any experiments being tracked in your production code, but started after the context was created, will not be triggered.

To mitigate this, we can use the Context->refresh() method on the Context.

The Context->refresh() method pulls updated experiment data from the A/B Smartly collector and will trigger recently started experiments when Context->getTreatment is called again.

Setting Extra Units

You can add additional units to a context by calling the Context->setUnit or Context->setUnits methods. These methods may be used, for example, when a user logs in to your application, and you want to use the new unit type in the context.

Please note, you cannot override an already set unit type as that would be a change of identity and would throw an exception. In this case, you must create a new context instead. The Context->setUnit and
Context->setUnits methods can be called before the context is ready.

Basic Usage

Selecting A Treatment

Treatment Variables

Peek at Treatment Variants

Although generally not recommended, it is sometimes necessary to peek at a treatment or variable without triggering an exposure. The A/B Smartly SDK provides a Context->peekTreatment() method for that.

Peeking at variables

Overriding Treatment Variants

During development, for example, it is useful to force a treatment for an
experiment. This can be achieved with the Context->setOverride() and/or Context->setOverrides() methods. These methods can be called before the context is ready.

Advanced

Context Attributes

Attributes are used to pass meta-data about the user and/or the request.
They can be used later in the Web Console to create segments or audiences.
They can be set using the Context->setAttribute() or Context->setAttributes() methods, before or after the context is ready.

Custom Assignments

Sometimes it may be necessary to override the automatic selection of a variant. For example, if you wish to have your variant chosen based on data from an API call. This can be accomplished using the Context->setCustomAssignment() method.

If you are running multiple experiments and need to choose different custom assignments for each one, you can do so using the Context->setCustomAssignments() method.

Publish

Sometimes it is necessary to ensure all events have been published to the A/B Smartly collector, before proceeding. You can explicitly call the Context->publish() method.

Finalize

The close() method will ensure all events have been published to the A/B Smartly collector, like Context->publish(), and will also "seal" the context, throwing an error if any method that could generate an event is called.

Tracking Goals


All versions of php-sdk with dependencies

PHP Build Version
Package Version
Requires php-64bit Version ^7.4 || ^8.0
lastguest/murmurhash Version ~2.1.1
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package absmartly/php-sdk contains the following files

Loading the files please wait ....