SDK Integration

Follow below steps to start SDK integration.

  • Step 1: Add Dependencies
  • Step 2: Initialize the SDK
  • Step3 : A/B test, Feature Flag
  • Step4 : Send customer event

Step 1: Add Dependencies

Think of this step as importing our SDK into your codebase. To use our Hackle services add the following dependency code and import our SDK.

php composer.phar require hackle/hackle-php-sdk:{sdk_version}

//OR
composer require hackle/hackle-php-sdk:{sdk_version}

then autoload as below.

require 'vendor/autoload.php';

Step 2: Initialize the SDK

Once you have imported the dependencies, in order to start using the Hackle SDK you must initialize the SDK. During this step, we get the information needed for SDK integration from the Hackle Server and store it in the SDK.

Instantiate

Instantiate Hackle Client by passing the SDK key. HackleClient periodically caches the data to files when using the methods provided by Hackle to obtain necessary information. (Cached information is stored in /tmp/hackle/.)

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

The SDK key can be found in the SDK integration in the dashboard of Hackle service. Copy and use the Server SDK key.

Step 3. Sending Events

The Hackle SDK provides functionality to send user events to Hackle. By utilizing this feature at points where user behavior changes, you can gather meaningful data about user actions and perform user behavior analysis based on the collected data.

track

You can use the track() method to send user events by providing the event key and user identifier. If needed, you can also include a numeric value in the value parameter to be sent along with the user event.

  • Only number type values can be included in the value parameter.

Example

Suppose you have defined an event key called 'purchase' to collect events when the user presses the buy button. At this time, you may want to collect the purchase price together. In this case, you can also receive the purchase amount in 'value'.

<?php
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae2182e0");

$event = \Hackle\Common\HackleEvent::builder("purchase")
    ->property("pay_method", "CARD")
    ->property("discount_amount", 800)
    ->property("is_discount", true)
    ->build();

$client->track($event, $user);
?>

Verifying User Event Transmission

You can verify whether the user events sent from the SDK are being collected successfully. In the Hackle dashboard, navigate to [Left Menu] - [Event Management] to find the events sent via the SDK and check the real-time event collection status.

Step4. A/B test, Feature Flag

A/B test

Before running an A/B test, you must distribute users to the test group and create the logic corresponding to each test group.
User distribution can then be carried out through the hackle SDK.

📘

Test Group

The test group refers to the existing one (control group) and improvement one (treatment group) to be tested, and there may be more than one treatment group. You can configure in the dashboard and for information on how to manage test groups, visit see the document A/B setting.

variation

Input Experiment key and user identifier to the 'variation()' method to distribute users and receive results. You can implement logic by test group afterwards.

The experiment key is a unique number for each A/B test and can be found on the dashboard within the Hackle service.

The example code below inputs the experiment key 42.

<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae2182e0");

$variation = $client->variation(42 , $user);

if($variation == \Hackle\Common\Variation::A) {
    // Group A logic
}
else if($variation == \Hackle\Common\Variation::B) {
    // Group B logic
}

?>

Feature Flag

The feature flags are in the ON state and the OFF state. Different features will be set for each state.
When a user accesses a function with a feature flag applied, the user must be able to receive an on or off state. This status determination can be made via the hackle SDK.

isFeatureOn

Input Flag key to the 'isFeatureOn()' method to receive status results for the user. Implement logic based on subsequent states.

The Feature key is a unique number for each Feature Flag and can be found on the dashboard within the Hackle service.

The example code below input the function key 42.

<?php
  
require 'vendor/autoload.php';

$client = \Hackle\HackleClients::create("YOUR_SERVER_SDK_KEY");

$user = \Hackle\Common\HackleUser::of("ae2182e0");

$isFeatureOn = $client->isFeatureOn(42, $user);

if ($isFeatureOn) {
    // ON Feature
} else {
    // OFF Feature
}

?>

Check the exposure results

On the [Dashboard Left Menu Bar] - [A/B Test] or [Feature Flag] page, browse to the detail page for the list of exposed A/B tests or feature flags, and click the Real-Time Exposure tab in the middle of the page to view the distribution results from integrated SDK.