Network Tracing

Network tracing allows you to see network activities relating to the Google Mobile Ads SDK. This can be useful in debugging your Google Mobile Ads implementation.

A key reason to use network tracing instead of tools such as Charles Proxy is that it will work on all versions of Android and devices with a supported version of Google play services. This is not the case with proxying tools due to changes in trusted CAs and certificates in place since Android 7.0.

This guide explains how to enable network tracing for debugging purposes.

Enable tracing

To enable network tracing, enable developer options for your device. Then, launch the Google Settings app and select the Ads option:

Assuming you have developer options enabled and the feature is available, you'll see on the screen:

Select the Enable debug logging for ads option. You'll then see the following dialog:

Tap OK and you'll be presented with an advertising identifier that ends with loca1ad1abe1:

You can now see all the output from the network logging in logcat.

A convenient way to view only the log output, and to save to a log file at the same time, is to use the following logcat command:

adb logcat *:S Ads:I | grep "GMA Debug" | tee logs.txt

This will log output to the terminal as well as save all the log output to a logs.txt file.

Output

Standard platform-appropriate console logs are used to output the network logs.

Console log messages always begin with the string GMA Debug BEGIN, GMA Debug CONTENT, or GMA Debug FINISH so that it can be searched for or filtered out. For each network log, the first log message is GMA Debug BEGIN, the last log message is GMA Debug FINISH, and the network log content begins with GMA Debug CONTENT. If a network log content is too long to fit on a line, it is split among multiple lines, each line beginning with GMA Debug CONTENT.

Console output example

I/Ads     ( 4660): GMA Debug BEGIN
I/Ads     ( 4660): GMA Debug CONTENT {"timestamp":1510679993741,...}
I/Ads     ( 4660): GMA Debug FINISH

JSON output example

These sample SDK output are formatted for readability:

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
  }
}

Send feedback about...

Google AdMob > Mobile Ads SDK > Android
Google AdMob > Mobile Ads SDK > Android
Need help? Visit our support page.