Initialization

To create a VWO Client instance, you need to initialize the VWO FE Php SDK. This client instance serves as the core interface for conducting Feature Experimentation(A/B and personalization) within your application.

Usage

$vwoClient = VWO::init([
       'accountId' => your_account_id,
       'sdkKey' => your_sdk_key,
  ]);

The init() function is called with the sdkKeyand accountId. It initializes and returns a VWO Client ObjectvwoClient, which can be used to perform feature
This client object allows you to run experiments, track events, and enable/disable feature flags.

Parameter Definitions

Paramter

Type

Description

accountId Required

Integer

Your VWO application's Account ID.

sdkKey Required

String

A unique environment key is provided to you inside the Websites & Apps section in the VWO application, under Default Project.

logger Optional

Object

An optional logger object that defines the logging behavior. For more details, please check - Logger

storage Optional

Object

Storage Service, if required, can be implemented using this parameter. For more details, please check - Storage Service

gatewayService Optional

Object

If using the FE Gateway Service, this object will specify the location and port of where the gateway service is deployed on your servers.

integrations Optional

Object

A callback function that receives data which can be pushed to any external tool that you need to integrate with. For more details, please check - Integrations

Logger

VWO by default logs all ERROR level messages to your server console. To gain more control over VWO's logging behavior, you can use the logger parameter in the init configuration.

// Init options with logger
$vwoClient1 = VWO::init([
  'sdkKey' => '32-alpha-numeric-sdk-key',
  'accountId' => '123456',
  'logger' => [
    'level' => 'DEBUG',
  ],
]);

Please click here for more advanced logger options.

Storage

By default, the SDK operates in stateless mode, evaluating flags on each getFlag call. To improve performance and consistency, you can use a custom storage mechanism to cache decisions, ensuring stable user experiences and reducing application load.

// Init options with storage
$vwoClient = VWO::init([
  'sdkKey' => '32-alpha-numeric-sdk-key',
  'accountId' => '123456',
  'storage' => $storageConnector,
]);

Please click here to learn more about storage implementation.

Gateway Service

The VWO FE Gateway Service enhances Feature Experimentation (FE) SDKs by enabling pre-segmentation based on user location and user agent. It ensures minimal latency and improved security. The service can be customized via the gatewayService parameter during initialization.

// Init options with gatewayService
$vwoClient = VWO::init([
  'sdkKey' => '32-alpha-numeric-sdk-key',
  'accountId' => '123456',
  'gatewayService' => [
    'url' => 'https://custom.gateway.com',
  ],
]);

Please click here to learn more about gateway service.

Integrations

VWO FE SDKs provide seamless integration with third-party tools like analytics platforms, monitoring services, customer data platforms (CDPs), and messaging systems. This is achieved through a simple yet powerful callback mechanism that receives VWO-specific properties and can forward them to any third-party tool of your choice.

// Init options with integrations
$vwoClient = VWO::init([
  'sdkKey' => '32-alpha-numeric-sdk-key',
  'accountId' => '123456',
  'integrations' => [
      'callback' => function ($properties) {
          echo "Integrations callback: " . json_encode($properties) . PHP_EOL;
      }
   ]
]);

Please click here to learn more about Integrations,.

Initialization with Explicit Settings

The SDK provides the ability to reduce initialization time by allowing users to explicitly pass in settings instead of fetching them automatically. This can be especially useful in environments where you need to optimize for faster setup or if you already have the necessary settings retrieved from a remote server.
Please refer to this document for more information on retrieving settings.

$settingsStringified = '{
    "accountId": 123456,
    "sdkKey": "32-alpha-numeric-sdk-key",
    "features": {
    },
    "campaigns": {
    },
    "version": 1,
}';


$settings = json_decode($settingsStringified, true);

$vwoClient = VWO::init([
  'sdkKey' => '32-alpha-numeric-sdk-key',
  'accountId' => '123456',
  'integrations' => $settings
]);

What’s Next