# C++
最新バージョン:1.2.1
更新時間:2023-01-11
ダウンロード:Source Code (opens new window)
# SDK 実装
- 静的ライブラリを利用(windows10 でモディファイ)
ソースコードをダウンロードし、libs フォルダで include フォルダをプロジェクトへコピーします。
logconsumer
を利用する場合は、libthinkingdata.a
を引用してください
batchconsumer
を利用する場合は、libthinkingdata_batch.a
を引用してください
debugconsumer
を利用する場合は、libthinkingdata_debug.a
を引用してください
- 独自でモディファイ
C++ SDK のソースコードをダウンロードし Clion、VS2019 などの IDE を使用してcpp
フォルダに入ります。
(1)logconsumer
をモディファイする場合、CMakeLists.txt
ファイルを編集
cmake_minimum_required(VERSION 3.12)
project(cpp-server-sdk)
set(CMAKE_CXX_STANDARD 11)
include_directories(include)
# log consumer
add_library(thinkingdata src/ThinkingAnalyticsAPI.cpp src/TAUtils.cpp src/TALoggerConsumer.cpp)
add_executable(program example/program.cpp)
target_link_libraries(program thinkingdata)
example フォルダのprogram.cpp
を実行し、cmake-build フォルダの中からlibthinkingdata.a
を取得します。
(2)batch consumer
をモディファイする場合、CMakeLists.txt
ファイルを編集
cmake_minimum_required(VERSION 3.12)
project(cpp-server-sdk)
set(CMAKE_CXX_STANDARD 11)
include_directories(include)
# batch consumer
add_library(thinkingdata_batch src/ThinkingAnalyticsAPI.cpp src/TAUtils.cpp src/TABatchConsumer.cpp src/TANetwork.cpp)
if(WIN32)
include_directories(thirdParty/curl/include)
link_directories(thirdParty/curl/lib)
target_link_libraries(thinkingdata_batch libcurl)
else ()
target_link_libraries(thinkingdata_batch curl)
endif()
add_executable(batchConsmerDemo example/batchConsmerDemo.cpp)
target_link_libraries(batchConsmerDemo thinkingdata_batch)
example フォルダのbatchConsmerDemo.cpp
を実行し、cmake-build フォルダの中からlibthinkingdata_batch.a
を取得します。
(3)debug consumer
をモディファイする場合、CMakeLists.txt
ファイルを編集
cmake_minimum_required(VERSION 3.12)
project(cpp-server-sdk)
set(CMAKE_CXX_STANDARD 11)
include_directories(include)
# debug consumer
add_library(thinkingdata_debug src/ThinkingAnalyticsAPI.cpp src/TAUtils.cpp src/TADebugConsumer.cpp src/TANetwork.cpp)
if(WIN32)
include_directories(thirdParty/curl/include)
link_directories(thirdParty/curl/lib)
target_link_libraries(thinkingdata_debug libcurl)
else ()
target_link_libraries(thinkingdata_debug curl)
endif()
add_executable(debugConsmerDemo example/debugConsumerDemo.cpp)
target_link_libraries(debugConsmerDemo thinkingdata_debug)
example フォルダのdebugConsumerDemo.cpp
を実行し、cmake-build フォルダの中からlibthinkingdata_debug.a
を取得します。
- Logbus をインストール
TE システムにより迅速かつ正確なデータを転送するために、SDK + LogBus の併用でサーバデータのデータレポートを推奨しております。
# 初期設定
SDK の初期設定のコード例:
// Import header file (adjust the path yourself)
#include "thirdPark/tacpp/include/tacpp/ThinkingDataAnalyticsSDK.h"
string LOG_DIRECTORY = "../trackLog";
TaSDK::LoggerConsumer::Config config = TaSDK::LoggerConsumer::Config(LOG_DIRECTORY);
TaSDK::LoggerConsumer logConsumer = TaSDK::LoggerConsumer(config);
TaSDK::ThinkingDataAnalytics te = TaSDK::ThinkingDataAnalytics(logConsumer);
LOG_DIRECTORY
はローカルアクセスファイルのアドレスとなります。LogBus のモニターアドレスをこのアドレスに設定すれば自動でアップロードされます。
# メイン機能
ゲスト ID とアカウント ID をうまく紐付けるために、もしゲーム内でゲスト ID とアカウント ID 両方を使われる場合は、それらの ID を同時にアップロードするのを推奨しております。同時にアップロードしない場合は、ユーザーを重複にカウントされてしまう可能性があります。
# 3.1 イベント送信
track
を利用してイベントの送信を行います。事前にデータプランをご用意の上、送信してください。以下はモデルコードとなります。
TaSDK::PropertiesNode event_properties;
event_properties.SetString("name1", "XZ_debug");
event_properties.SetString("name2", "logbugs");
event_properties.SetString("name3", "name3");
event_properties.SetString("#uuid", "1234567890");
event_properties.SetNumber("test_number_int", 3);
event_properties.SetNumber("test_number_double", 3.14);
event_properties.SetBool("test_bool", true);
std::string test_string = "test_string";
event_properties.SetString("test_stl_string1", test_string);
event_properties.SetDateTime("test_time1", time(nullptr), 0);
timeb t = {};
ftime(&t);
event_properties.SetDateTime("#time", t.time, t.millitm);
std::vector<std::string> test_list;
test_list.push_back("item11");
test_list.push_back("item21");
event_properties.SetList("test_list1", test_list);
// track event
te.track(accountId, distincId, eventName, event_properties);
- イベント名称は string タイプで、英文字と数字、 "_"を含め、最大 50 文字
- Key は当プロパティの名称で string タイプで、英文字と数字、 "_"を含め、最大 50 文字。TE システムは一律で小英文字に統一されます
- Value は当プロパティの値で、String, Number, Bloon, Time, object, array, list object を対応しております。
ユーザープロパティはイベントプロパティと一致する必要があります
# 3.2 ユーザープロパティを設定
一般のユーザープロパティに関しては、user_set
を利用して設定することができますが、 UserSet は元の値を上書きされます。本来該当プロパティに値がない場合は、プロパティが新規作成されます。以下はコード例となります。
// user_set
TaSDK::PropertiesNode userSet_properties;
userSet_properties.SetString("userName", "test");
te.user_set(accountId, distincId, userSet_properties);
# コード例のまとめ
以下のコード例で全ての操作が含まれます、以下の順で利用推奨しております。
// Import header file (adjust the path yourself)
#include "thirdPark/tacpp/include/tacpp/ThinkingDataAnalyticsSDK.h"
string LOG_DIRECTORY = "../trackLog";
TaSDK::LoggerConsumer::Config config = TaSDK::LoggerConsumer::Config(LOG_DIRECTORY);
TaSDK::LoggerConsumer logConsumer = TaSDK::LoggerConsumer(config);
TaSDK::ThinkingDataAnalytics te = TaSDK::ThinkingDataAnalytics(logConsumer);
// track event
TaSDK::PropertiesNode event_properties;
event_properties.SetString("name1", "XZ_debug");;
event_properties.SetNumber("test_number_int", 3);
event_properties.SetBool("test_bool", true);
te.track(accountId, distincId, eventName, event_properties);
// upload user properties
TaSDK::PropertiesNode userSet_properties;
userSet_properties.SetString("userName", "test");
te.user_set(accountId, distincId, userSet_properties);
// "flush()" is immediately written to the file.
// call "flush()" API is not necessary
te.flush();