menu
Is this helpful?

# 实时调试

在SDK接入过程中,您可以通过使用TE的Debug功能,进行实时调试。使用Debug功能需要如下两步操作:

  1. 使用DebugConsumer

以下使用DebugConsumer的示例代码:

%% 配置上报地址
ServerUrl = "server_url",
%% 配置app_id
AppID = "app_id",
%% 配置是否写入数据库
IsWrite = true,
%% 配置device_id,用来在TE后台实时查看上报数据
DeviceId = "123456789",

%% init consumer
Consumer = td_debug_consumer:init_with_config(ServerUrl, AppID, IsWrite, DeviceId),
%% init SDK with consumer
TE_SDK = td_analytics:init_with_consumer(Consumer),

AccountId0 = "account_id_Erlang_0",

%% ordinary event
td_analytics:track_instance(TE_SDK, AccountId0, "distinct_logbus", "ViewProduct", #{"#key_1" => "🚓🦽🦼🚲🚜🚜🦽", "key_2" => 2.2, "key_array" => ["🚌", "🏍", "😚😊"]}),

%% 关闭SDK时候需要调用。如果关闭后,需要再开启SDK时,必须重新执行上文的初始化代码。
td_analytics:close_instance(TE_SDK).
  1. TE后台添加Debug设备

为了避免 Debug 模式在生产环境上线,规定只有指定的设备才能开启 Debug 模式。只有在客户端开启了 Debug 模式,并且设备 ID 在 TE 后台的"埋点管理"页的"Debug 数据"板块中配置了的设备才能开启 Debug 模式。

Debug 模式可能会影响数据采集质量和 App 的稳定性,只用于集成阶段数据验证,不要在线上环境使用。