メインコンテンツまでスキップ

リアルタイムデバッグ

最終更新 2026/10/02
注意

SDKのデバッグモードは、接続時のデバッグ専用です。本番環境では絶対に使用しないでください。

ログ出力の有効化​

td_enableLog(1);

DebugConsumerの使用​

SDKの接続中は、AEのDebug機能を使用してリアルタイムにデバッグできます。Debug機能を使用するには、次の2つの手順が必要です:

  1. DebugConsumerを使用する
  • debugConsumerの機能を含む.aファイルをビルドします。CMakeLists.txtの変更例は次のとおりです:
# Debug Library: debug consumer
if(WIN32)
add_compile_definitions(USE_WIN)
set(CMAKE_C_FLAGS "-std=c99 -pedantic-errors -m64")
else()
add_compile_definitions(USE_POSIX)
set(CMAKE_C_FLAGS "-std=c99")
endif()
SET(TE_LIB_NAME thinkingDataDebug)
add_library(${TE_LIB_NAME} src/thinkingdata.c src/td_json.c src/td_list.c src/td_util.c src/td_debug_consumer.c src/td_http_client.c)
if(WIN32)
add_compile_definitions(BUILDING_LIBCURL)
include_directories(thirdparty/pcre/include thirdparty/curl/include)
link_directories(thirdparty/pcre/lib thirdparty/curl/lib)
target_link_libraries(${TE_LIB_NAME} pcre_x64 libcurl)
else()
target_link_libraries(${TE_LIB_NAME} curl)
endif()
  • DebugConsumerを使用するサンプルコードは次のとおりです:
struct TDAnalytics* ta = NULL;
struct TDConsumer* consumer = NULL;
/*
* DebugConsumer:データを1件ずつ送信します。問題が発生した場合は、ログと例外でユーザーに通知します。本番環境での使用はお勧めしません
*/
TDConfig *config = td_init_config();
// debug_mode:0の場合はデータを格納し、それ以外の場合は格納しない
TD_ASSERT(TD_OK == td_add_int("debug_mode", 0, config));
// AE管理画面のテストデバイスのid: 123456789
TD_ASSERT(TD_OK == td_add_string("device_id", "123456789", strlen("123456789"), config));
// appidとurlを設定
char* appid = "APPID";
char* serverURL = "SERVER_URL";
TD_ASSERT(TD_OK == td_add_string("push_url", serverURL, strlen(serverURL), config));
TD_ASSERT(TD_OK == td_add_string("appid", appid, strlen(appid), config));

//SDKインスタンスを生成
if (TD_OK != td_init_consumer(&consumer, config)) {
fprintf(stderr, "Failed to initialize the consumer.");
return 1;
}
td_free_properties(config);
if (TD_OK != td_init(consumer, &ta)) {
fprintf(stderr, "Failed to initialize the SDK.");
return 1;
}

// カスタムプロパティを生成
TDProperties *properties = td_init_properties();
// デバイスIDプロパティを追加。デバイスIDの値はtd_device_id
TD_ASSERT(TD_OK == td_add_string("#device_id", "td_device_id", strlen("td_device_id"), properties));
//カスタムプロパティ付きのイベントデータを送信。同様に、account_idとdistinct_idの少なくとも一方を設定する必要があります
TD_ASSERT(TD_OK == td_track("account_id", "distinct_id", "test", properties, ta));
td_free_properties(properties);
  1. AE管理画面でDebugデバイスを追加する

デバッグモードが本番環境で有効になるのを防ぐため、指定したデバイスでのみデバッグモードを有効にできます。クライアントでデバッグモードを有効にし、かつAE管理画面の「データ」→「データ収集管理」→「デバッグモード」ページにデバイスIDが追加されているデバイスのみ、デバッグモードを有効にできます。追加方法:このページで右上の「デバイスに接続」をクリックし、「デバイスの選択」ドロワーで「デバイスを追加」をクリックして、デバイスIDを入力します。

Debugモードはデータ収集の品質やAppの安定性に影響する可能性があります。統合段階でのデータ検証にのみ使用し、本番環境では使用しないでください。

このページは役に立ちましたか?