Initialization of PHP SDK

Initialization of PHP SDK

The PageSenseClient class is the main interface provided by the PageSense PHP SDK to run Full Stack A/B Testing experiments for the users. Before serving variations or tracking goals, the client must be initialized with your project’s configuration, known as the Project Settings.

Project Settings contain metadata about all active experiments within your project, including the details of all variations, targeting conditions, goals and environment keys. Initializing the SDK ensures your PHP application has the latest experiment definitions and runs them correctly.

Initialization Overview  

Initialization of the PageSense PHP SDK involves two steps:

  1. Fetching the Project Settings from the PageSense server.

  2. Creating a PageSenseClient instance using those settings.

1. Get the Project Settings  

The Project Settings contains the details of all the A/B Test experiments that are active (Running, Paused and Scheduled) in your project, their configurations, variations, goals, and targeting rules, etc. Project Settings can be fetched directly from the PageSense servers using the getProjectSettings() method.

Calling the Method

Add the following code to your application to get the Project Setting file for your PageSense account.

 

  1. use Zoho\PageSense\PageSenseClientBuilder;
  2. // Get the Project Settings
  3. $projectSettings = PageSenseClientBuilder::getProjectSettings( 'accountId-DC','sdkKey',   'projectName' );
Method Parameters

Parameter

Type

Description

accountId

string

Your unique PageSense account ID with Data Center Code.

sdkKey

string

Unique key corresponding to your SDK environment. Available under the Environment tab in your Full Stack project settings.

projectName

string

Name of your Full Stack project.


Notes
Note: This function will return the Project Settings if present in the Stringified JSON format. If there are no project settings available, this function will return null.

2. Create the PageSenseClient Instance  

Once you’ve fetched the Project Settings, you can initialize the PageSenseClient. The client uses these settings to determine which experiments and variations apply to each user session.

Calling the Method

  1. // Create the PageSense Client instance
  2. $pageSenseClient = PageSenseClientBuilder::getBuilder($projectSettings)->buildClient();

After Initialization  

Your PageSenseClient instance is now ready to:

  • Activate experiments

  • Fetch variation names

  • Track goals and conversions

  • Manage project-level settings

You can create a single instance of the PageSenseClient during your application startup and use it for all the users using your application to run the A/B Test, deliver the variations and track the goal conversions and send the tracking details to PageSense.


NotesNote: Implement robust error-handling procedures to safely manage cases where the PageSenseClient fails to initialize and results in a null instance. Your application should handle this condition gracefully to avoid unexpected runtime errors.