Real-time debugging
The SDK Debug mode is only for debugging during integration. Never use it in the production environment.
Enable log printing
td_enableLog(1);
Use DebugConsumer
During SDK integration, you can use the AE Debug feature for real-time debugging. To use the Debug feature, complete the following two steps:
- Use DebugConsumer
- Build a .a file that includes the debugConsumer feature. The following is an example of the changes to
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()
- The following sample code uses DebugConsumer:
struct TDAnalytics* ta = NULL;
struct TDConsumer* consumer = NULL;
/*
* DebugConsumer: reports data one record at a time. When a problem occurs, the user is notified through logs and exceptions. Not recommended for the production environment
*/
TDConfig *config = td_init_config();
// debug_mode: 0 means the data is ingested; any other value means it isn't
TD_ASSERT(TD_OK == td_add_int("debug_mode", 0, config));
// ID of the test device in the AE backend: 123456789
TD_ASSERT(TD_OK == td_add_string("device_id", "123456789", strlen("123456789"), config));
// Configure appid and 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));
//Create the SDK instance
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;
}
// Create custom properties
TDProperties *properties = td_init_properties();
// Add the device ID property; the device ID value is td_device_id
TD_ASSERT(TD_OK == td_add_string("#device_id", "td_device_id", strlen("td_device_id"), properties));
//Report event data with custom properties. Likewise, at least one of account_id and distinct_id must be set
TD_ASSERT(TD_OK == td_track("account_id", "distinct_id", "test", properties, ta));
td_free_properties(properties);
- Add a Debug device in the AE backend
To prevent Debug mode from going live in the production environment, Debug mode can only be enabled on specified devices. Debug mode can be enabled only on devices that have Debug mode enabled on the client and whose device IDs have been added on the Data → Tracking → Debugger page in the AE backend. To add a device, click Add test device in the upper-right corner of the page, click New device in the Select device drawer, and enter the device ID.
Debug mode may affect data collection quality and App stability. Use it only to verify data during integration, and don't use it in the production environment.

