网络跟踪
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助网络跟踪功能,您可以查看与 Google 移动广告 SDK 相关的网络活动,该功能非常适合调试 Google 移动广告的实现。
使用网络跟踪功能而非 Charles Proxy 等工具的主要原因是:网络跟踪功能适用于所有 Android 版本以及运行受支持的 Google Play 服务版本的设备。由于自 Android 7.0 以来受信任的 CA 及相关证书发生变化,代理工具并不具备如此广泛的适用性。
本指南介绍了如何出于调试目的而启用网络跟踪功能。
启用跟踪功能
如需启用网络跟踪功能,请为您的设备启用开发者选项。
然后,启动 Google 设置应用,并选择广告选项:

假设您已启用开发者选项并且该功能可用,则您的屏幕将如下所示:

选择启用广告调试日志功能选项,以显示以下对话框:

点按确定,就会看到一个以 10ca1ad1abe1
结尾的广告标识符:

现在,您可以在 logcat 中看到网络日志记录的所有输出。如需仅将信息级广告输出过滤到屏幕和文件,请发出以下命令:
adb logcat '*:S' Ads:I Ads-cont:I | tee logs.txt
输出
适用于标准平台的控制台日志用于输出网络日志。
控制台日志消息始终以字符串 GMA Debug BEGIN
、GMA Debug CONTENT
或 GMA Debug FINISH
开头,因此您可以搜索或过滤这些字符串。对于每个网络日志,第一条日志消息为 GMA Debug BEGIN
,最后一条日志消息为 GMA Debug FINISH
,并且网络日志内容以 GMA Debug CONTENT
开头。如果网络日志内容过长,无法完全显示在一行中,则会将其拆分为多行,且每一行都以 GMA Debug CONTENT
开头。
控制台输出示例
I/Ads ( 4660): GMA Debug BEGIN
I/Ads ( 4660): GMA Debug CONTENT {"timestamp":1510679993741,...}
I/Ads ( 4660): GMA Debug FINISH
JSON 输出示例
以下是 logcat 的一些 JSON 输出示例:
onNetworkRequest
{
"timestamp": 1510679994904,
"event": "onNetworkRequest",
"components": [
"ad_request_cf5ab185-3c3f-4f01-9f56-33da2ae110f2",
"network_request_6553bc32-1d44-4f18-9dd0-5c183abbeb90"
],
"params": {
"firstline": {
"uri": "http://googleads.g.doubleclick.net/pagead/ads?carrier=....",
"verb": "GET"
},
"headers": [
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Linux; Android 5.0.2;..."
}
]
}
}
onNetworkResponse
{
"timestamp": 1510679995295,
"event": "onNetworkResponse",
"components": [
"ad_request_cf5ab185-3c3f-4f01-9f56-33da2ae110f2",
"network_request_6553bc32-1d44-4f18-9dd0-5c183abbeb90"
],
"params": {
"firstline": {
"code": 200
},
"headers": [
{
"name": null,
"value": "HTTP/1.1 200 OK"
},
{
"name": "X-Google-DOS-Service-Trace",
"value": "main:pagead"
},
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
},
...
]
}
}
onNetworkResponseBody
{
"timestamp": 1510679995375,
"event": "onNetworkResponseBody",
"components": [
"ad_request_cf5ab185-3c3f-4f01-9f56-33da2ae110f2",
"network_request_6553bc32-1d44-4f18-9dd0-5c183abbeb90"
],
"params": {
"bodydigest": "B2520049D02F3C70A12AD1BC0D1B58A4",
"bodylength": 122395
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eNetwork tracing provides insights into network activities related to the Google Mobile Ads SDK, aiding in debugging your implementation.\u003c/p\u003e\n"],["\u003cp\u003eIt's compatible with all Android versions and devices running supported Google Play services, unlike some proxy tools.\u003c/p\u003e\n"],["\u003cp\u003eEnable tracing through the Google Settings app after activating developer options on your device.\u003c/p\u003e\n"],["\u003cp\u003eNetwork logs, identifiable by strings like "GMA Debug BEGIN," are viewable in logcat and can be filtered for analysis.\u003c/p\u003e\n"],["\u003cp\u003eThe logs provide detailed information on network requests, responses, and response bodies in JSON format for comprehensive debugging.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/network-tracing \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/network-tracing \"View this page for the iOS platform docs.\")\n\n\u003cbr /\u003e\n\nNetwork tracing lets you see network activities relating to the Google Mobile\nAds SDK. This can be useful in debugging your Google Mobile Ads implementation.\n\nA key reason to use network tracing instead of tools such as [Charles\nProxy](//www.charlesproxy.com) is that it works with **all** versions of\nAndroid and devices running a supported version of Google play services. This\nisn't the case with proxying tools due to changes in\n[trusted CAs and certificates in place since Android 7.0](//developer.android.com/about/versions/nougat/android-7.0#default_trusted_ca).\n\nThis guide explains how to enable network tracing for debugging purposes.\n\nEnable tracing\n\nTo enable network tracing, [enable developer\noptions](//developer.android.com/studio/debug/dev-options) for your device.\nThen, launch the **Google Settings** app and select the **Ads** option:\n\nAssuming you have developer options enabled and the feature is available, your\nscreen would then look like this:\n\nSelect the **Enable debug logging for ads** option to bring up following dialog:\n\nTap **OK** and you're then presented with an advertising identifier that ends\nwith `10ca1ad1abe1`:\n\nYou are now able to see all the output from the network logging in logcat. To\nfilter only Information-level Ads output to both the screen and a file, issue\nthe following command: \n\n adb logcat '*:S' Ads:I Ads-cont:I | tee logs.txt\n\nOutput\n\nStandard platform-appropriate console logs are used to output the network logs.\n\nConsole log messages always begin with the string `GMA Debug BEGIN`,\n`GMA Debug CONTENT`, or `GMA Debug FINISH`, so you can search or filter on these\nstrings. For each network log, the first log message is `GMA Debug BEGIN`,\nthe last log message is `GMA Debug FINISH`, and the network log content begins\nwith `GMA Debug CONTENT`. If content is too long to fit on a line, it is split\namong multiple lines, each line beginning with `GMA Debug CONTENT`.\n\nConsole output example \n\n I/Ads ( 4660): GMA Debug BEGIN\n I/Ads ( 4660): GMA Debug CONTENT {\"timestamp\":1510679993741,...}\n I/Ads ( 4660): GMA Debug FINISH\n\nJSON output example\n\nHere are some samples of JSON output from logcat:\n\nonNetworkRequest \n\n {\n \"timestamp\": 1510679994904,\n \"event\": \"onNetworkRequest\",\n \"components\": [\n \"ad_request_cf5ab185-3c3f-4f01-9f56-33da2ae110f2\",\n \"network_request_6553bc32-1d44-4f18-9dd0-5c183abbeb90\"\n ],\n \"params\": {\n \"firstline\": {\n \"uri\": \"http://googleads.g.doubleclick.net/pagead/ads?carrier=....\",\n \"verb\": \"GET\"\n },\n \"headers\": [\n {\n \"name\": \"User-Agent\",\n \"value\": \"Mozilla/5.0 (Linux; Android 5.0.2;...\"\n }\n ]\n }\n }\n\nonNetworkResponse \n\n {\n \"timestamp\": 1510679995295,\n \"event\": \"onNetworkResponse\",\n \"components\": [\n \"ad_request_cf5ab185-3c3f-4f01-9f56-33da2ae110f2\",\n \"network_request_6553bc32-1d44-4f18-9dd0-5c183abbeb90\"\n ],\n \"params\": {\n \"firstline\": {\n \"code\": 200\n },\n \"headers\": [\n {\n \"name\": null,\n \"value\": \"HTTP/1.1 200 OK\"\n },\n {\n \"name\": \"X-Google-DOS-Service-Trace\",\n \"value\": \"main:pagead\"\n },\n {\n \"name\": \"Content-Type\",\n \"value\": \"text/html; charset=UTF-8\"\n },\n ...\n ]\n }\n }\n\nonNetworkResponseBody \n\n {\n \"timestamp\": 1510679995375,\n \"event\": \"onNetworkResponseBody\",\n \"components\": [\n \"ad_request_cf5ab185-3c3f-4f01-9f56-33da2ae110f2\",\n \"network_request_6553bc32-1d44-4f18-9dd0-5c183abbeb90\"\n ],\n \"params\": {\n \"bodydigest\": \"B2520049D02F3C70A12AD1BC0D1B58A4\",\n \"bodylength\": 122395\n }\n }"]]