vwo/vwo-php-sdk

VWO 服务器端 SDK


README

Latest Stable Version CI Coverage StatusLicense

这个开源库为您提供了服务器端测试功能。

要求

PHP >= 5.6

安装

使用以下命令安装最新版本

composer require vwo/vwo-php-sdk

基本用法

使用以下代码进行初始设置。

<?php
require_once('vendor/autoload.php');
require_once('userStorage.php'); // Optional :if you are using UserStorage service feature
require_once('customLogger.php');// Optional :if you are using custom logging feature

use vwo\VWO;

$accountId = REPLACE_WITH_VWO_ACCOUNT_ID; // eg: 123456
$sdkKey = 'REPLACE_WITH_TOKEN'; // eg: can be found in VWO app - FullStack project
$campaignKey = 'CAMPAIGN_UNIQUE_TEST_KEY';
$userId = 'USER_ID';
$goalIdentifier = 'REPLACE_WITH_CAMPAIGN_GOAL_IDENTIFIER';

// to fetch the settings i.e campaigns, variations and goals
$settingsFile = VWO::getSettingsFile($accountId, $sdkKey);

$sdkConfig = [
  'settingsFile' => $settingsFile,
  'isDevelopmentMode' => 0,  // optional: 1 to enable the dev mode
  'logging' => new CustomLogger(), // optional
  'userStorageService' => new userStorageService() // optional
];

$vwoClient = new VWO($sdkConfig);

// to get the variation name along with add a visitor hit to vwo app stats
$variation = $vwoClient->activate($campaignKey, $userId, $options);
// Or, to get the variation name
$variation = $vwoClient->getVariationName($campaignKey, $userId, $options);

// add code here to use variation
//...

/**
*send the track api hit to the vwo app stats to increase conversions
* $revenue is optional send in case if there is any revenue inside $options
*/

$vwoClient->track($campaignKey, $userId, $goalIdentifier, $options);

实现用户存储服务的代码

<?php
require_once('vendor/autoload.php');
use vwo\Utils\UserStorageInterface;
Class UserStorage implements UserStorageInterface{
  /**
    * @param $userId
    * @param $campaignKey
    *
    * @return array
    */
  public function get($userId, $campaignKey) {
    // search in DB/Storage system
    $variation = $db->fetch($userId, $campaignKey); // replace with your implementation

    return[
      'userId' => $userId,
      'campaignKey' => $campaignKey,
      'variationName' => $variation
    ];
  }

  /**
    * @param $campaignUserMapping
    * @return bool - could be changed
    */
  public function set($campaignUserMapping) {
    // S...code to store in DB/storage system
    return True;
  }
}

实现自定义日志记录器的代码

<?php
require_once('vendor/autoload.php');
use vwo\Logger\LoggerInterface;

/**
 * Class CustomLogger
 */
Class CustomLogger implements LoggerInterface{
  /**
    * @param $message
    * @param $level
    *
    * @return
    */
  public function log($message, $level){
    // use $level and log $message to either print or store them for later use
  }

}

文档

参考官方 VWO 文档

第三方资源和致谢

参考third-party-attributions.txt

变更日志

参考CHANGELOG.md

开发和测试用例

  1. 设置开发环境
composer run-script start
  1. 运行测试用例
composer run-script test
  1. 运行代码检查器
composer run-script test
  1. 运行代码美化器
composer run-script phpcbf

许可证

Apache License, Version 2.0

版权所有 2019-2022 Wingify Software Pvt. Ltd.