menu
Is this helpful?

# PHP

최신 버전:v3.0.0

업데이트 날짜:2023-10-08

다운로드:Source Code (opens new window)

# 1. SDK 구현

  1. composer를 이용하여 액세스합니다
{
    "require": {
        "thinkinggame/ta-php-sdk": "v3.0.0"
    }
}
  1. 또는 GitHub (opens new window)에서 SDK의 소스 코드를 가져와 프로젝트에 액세스할 수 있습니다. TaPhpSdk.php를 해당 프로젝트의 카탈로그에 넣어주세요. 본 SDK는 PHP >5.5를 지원하며, 일부 기능은 curl 확장을 요구합니다.
  2. Logbus 설치

TE 시스템을 통해 빠르고 정확한 데이터 전송을 위해, SDK와 LogBus를 함께 사용하여 서버 데이터의 데이터 리포트를 권장합니다.

# 2. 초기 설정

다음은 SDK의 초기 설정 포맷 코드입니다:

require_once "vendor/autoload.php";

use Exception;
use ThinkingData\TDLog;
use ThinkingData\TDAnalytics;
use ThinkingData\TDFileConsumer;
use ThinkingData\TDDebugConsumer;
use ThinkingData\TDBatchConsumer;
use ThinkingData\ThinkingDataException;

TDLog::$enable = true;

$consumer = new TDFileConsumer("LOG_DIRECTORY", 200, true, "te");
$teSDK = TDAnalytics($consumer, true);

LOG_DIRECTORY는 로컬 액세스 파일의 주소가 됩니다. LogBus의 모니터 주소를 이 주소로 설정하면 자동으로 업로드됩니다.

# 3. 주요 기능

게스트 ID와 계정 ID를 정확하게 연동하기 위해, 게임 내에서 게스트 ID와 계정 ID를 모두 사용하는 경우, 이들 ID를 동시에 업로드하는 것을 권장합니다. 동시에 업로드하지 않을 경우, 유저가 중복으로 계산될 수 있습니다.

# 3.1 이벤트 전송

track을 사용하여 이벤트 전송을 합니다. 사전에 데이터 트래킹 정책을 준비한 후, 전송해 주세요. 다음은 모델 코드입니다.

$account_id = 2121;
$distinct_id = 'SJ232d233243';
$properties = array();
$properties['age'] = 20;
$properties['Product_Name'] = 'c';
$properties['update_time'] = date('Y-m-d H:i:s', time());
$json = array();
$json['a'] = "a";
$json['b'] = "b";
$jsonArray = array();
$jsonArray[0] = $json;
$jsonArray[1] = $json;
$properties['json'] = $json;
$properties['jsonArray'] = $jsonArray;

try {
    $teSDK->track($distinct_id, $account_id, "viewPage", $properties);
} catch (Exception $e) {
    echo $e;
}
  • 이벤트 이름은 string 타입으로, 영문자와 숫자, "_"를 포함하며 최대 50자입니다.
  • Key는 해당 속성의 이름으로 string 타입이며, 영문자와 숫자, "_"를 포함하여 최대 50자입니다. TE 시스템은 일괄적으로 소문자로 통일됩니다.
  • Value는 해당 속성의 값으로, String, Number, Bloon, Time, object, array, list object를 지원합니다.

유저 속성은 이벤트 속성과 일치해야 합니다.

# 3.2 유저 속성 설정

일반적인 유저 속성에 대해서는 userSet을 사용하여 설정할 수 있으며, UserSet은 기존의 값을 덮어씁니다. 원래 해당 속성에 값이 없는 경우, 속성이 새로 생성됩니다. 다음은 코드 예시입니다.

$properties = array();
$properties['once_key'] = 'twice';
$properties['age'] = 10;
$properties['money'] = 300;
$properties['array1'] = ['str1', 'str2'];
try {
    $teSDK->user_set($distinct_id, $account_id, $properties);
} catch (Exception $e) {
    //handle except
    echo $e;
}

# 4. 코드 예시 (Example Code)

아래의 코드 예시에 모든 작업이 포함되어 있으며, 아래 순서대로 사용하는 것을 권장합니다:

require_once "vendor/autoload.php";

use Exception;
use ThinkingData\TDLog;
use ThinkingData\TDAnalytics;
use ThinkingData\TDFileConsumer;
use ThinkingData\TDDebugConsumer;
use ThinkingData\TDBatchConsumer;
use ThinkingData\ThinkingDataException;

TDLog::$enable = true;

$consumer = new TDFileConsumer("LOG_DIRECTORY", 200, true, "te");
$teSDK = TDAnalytics($consumer, true);

$account_id = 2121;
$distinct_id = 'SJ232d233243';
$properties = array();
$properties['age'] = 20;
$properties['Product_Name'] = 'c';
$properties['update_time'] = date('Y-m-d H:i:s', time());
$json = array();
$json['a'] = "a";
$json['b'] = "b";
$jsonArray = array();
$jsonArray[0] = $json;
$jsonArray[1] = $json;
$properties['json'] = $json;
$properties['jsonArray'] = $jsonArray;

try {
    $teSDK->track($distinct_id, $account_id, "viewPage", $properties);
} catch (Exception $e) {
    echo $e;
}

$properties = array();
$properties['once_key'] = 'twice';
$properties['age'] = 10;
$properties['money'] = 300;
$properties['array1'] = ['str1', 'str2'];
try {
    $teSDK->user_set($distinct_id, $account_id, $properties);
} catch (Exception $e) {
    //handle except
    echo $e;
}

$teSDK->flush();