การติดตามเครือข่าย
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เลือกแพลตฟอร์ม
Android
iOS
การติดตามเครือข่ายช่วยให้คุณเห็นกิจกรรมของเครือข่ายที่เกี่ยวข้องกับ SDK โฆษณาในอุปกรณ์เคลื่อนที่ของ Google
ซึ่งจะเป็นประโยชน์ในการแก้ไขข้อบกพร่องในการติดตั้งใช้งานโฆษณาในอุปกรณ์เคลื่อนที่ของ Google
สาเหตุสำคัญในการใช้การติดตามเครือข่ายแทนการใช้เครื่องมืออย่าง Charles
Proxy คือการติดตามเครือข่ายทำงานได้ใน Android ทุกเวอร์ชันและอุปกรณ์ที่ใช้บริการ Google Play เวอร์ชันที่รองรับ แต่เครื่องมือพร็อกซีไม่เป็นเช่นนั้นเนื่องจากมีการเปลี่ยนแปลงในCA และใบรับรองที่เชื่อถือได้ตั้งแต่ Android 7.0
คู่มือนี้จะอธิบายวิธีเปิดใช้การติดตามเครือข่ายเพื่อวัตถุประสงค์ในการแก้ไขข้อบกพร่อง
Enable tracing
หากต้องการเปิดใช้การติดตามเครือข่าย ให้เปิดใช้ตัวเลือกสำหรับนักพัฒนาแอปสำหรับอุปกรณ์
จากนั้นเปิดแอปการตั้งค่า 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
ตัวอย่างเอาต์พุต JSON จาก Logcat มีดังนี้
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 Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-05 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-09-05 UTC"],[[["\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 developer options in the Google Settings app, selecting "Ads" and then "Enable debug logging for ads".\u003c/p\u003e\n"],["\u003cp\u003eNetwork logs, viewable in logcat, are identified by "GMA Debug BEGIN," "GMA Debug CONTENT," and "GMA Debug FINISH" markers and provide detailed request and response information in JSON format.\u003c/p\u003e\n"],["\u003cp\u003eThe JSON output includes timestamps, event types (like onNetworkRequest, onNetworkResponse, onNetworkResponseBody), and relevant parameters such as URLs, headers, response codes, and body details.\u003c/p\u003e\n"]]],["Network tracing for the Google Mobile Ads SDK enables debugging by viewing network activities, which works across all Android versions unlike proxying tools. To enable it, activate developer options on your device, then in the Google Settings app, select the \"Ads\" option and \"Enable debug logging for ads.\" Network logs are outputted to the console, starting with \"GMA Debug BEGIN,\" followed by \"GMA Debug CONTENT\" for the content, and ending with \"GMA Debug FINISH\", which are filterable. JSON output examples include `onNetworkRequest`, `onNetworkResponse`, and `onNetworkResponseBody`.\n"],null,["Select platform: [Android](/admob/android/network-tracing \"View this page for the Android platform docs.\") [iOS](/admob/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 }"]]