• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Advertising ID
2page.tags="Ads","Advertising ID", "ID"
3header.hide=1
4
5@jd:body
6
7<div class="landing-banner">
8
9<div class="col-8">
10
11  <h1 itemprop="name" style="margin-bottom:0;">Advertising ID</h1>
12  <p itemprop="description">The advertising ID is a user-specific, unique,
13  resettable ID for advertising, provided by Google Play services. It gives
14  users better controls and provides developers with a simple, standard system
15  to continue to monetize your apps. It is an anonymous identifier for advertising
16  purposes and enables users to reset their identifier or opt out of interest-based
17  ads within Google Play apps. </p>
18
19<p>The advertising ID is accessible through a straightforward API that you can implement in your apps. For details,
20take a look at the
21<a href="#get_started">overview</a> and the <a
22href="{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html">advertising ID API reference</a>.
23
24</div>
25</div>
26
27<div class="landing-docs">
28  <div class="col-6 normal-links">
29    <h3 style="clear:left">Key Developer Features</h3>
30
31      <h4>Standard, simple ID</h4>
32      <p>The advertising ID is a part of a standard, simple system for serving ads and performing analytics.</p>
33
34      <h4>Giving users control</h4>
35      <p>Users  can reset their advertising ID or opt out of interest-based ads at any time, right from the Google Settings app.
36      Their preferences apply across all ad companies that use the advertising ID.</p>
37
38  </div>
39
40  <div class="col-6 normal-links">
41    <h3 style="clear:left">Getting Started</h3>
42    <h4>1. Get the Google Play services SDK</h4>
43    <p>The advertising ID APIs are part of the Google Play services platform.</p>
44    <p>To get started, <a href="{@docRoot}google/play-services/setup.html">set up</a>
45    the Google Play services SDK. </p>
46
47    <h4>2. Read the docs and example code</h4>
48    <p>Once you've installed the Google Play services package, review the <a href="#get_started">overview</a>
49    below, as well as the <a href="#example">example</a>.</p>
50    <p>
51    For detailed documentation, take a look at the <a href=
52    "{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html">
53    advertising ID API reference documentation</a>.
54    </p>
55  </div>
56</div>
57
58
59<h2 id="get_started">Using the Advertising ID</h2>
60
61<p>
62  The <strong>advertising ID</strong> is a unique but
63  user-resettable string identifier that lets ad networks and other apps anonymously
64  identify a user. The user's advertising ID is made available to apps through APIs
65  provided in Google Play services.
66</p>
67<p>
68  Users can reset their advertising ID at any time, right from the Ads section of the
69  Google Settings app on their devices. From the same app, users can also
70  opt-out of targeted advertising based on the advertising ID by setting the appropriate
71  <strong style="white-space:nowrap">ad tracking preference</strong>. When the
72  user opts-out of targeted ads, this ad tracking preference is made available
73  to apps through a Google Play services API.
74</p>
75<p>
76  Apps making use of the advertising ID <strong>must check for and respect</strong> the
77  user's ad tracking preference. Also please note that any use of the advertising ID
78  must abide by the terms of the <a class="external-link"
79  href="http://play.google.com/about/developer-content-policy.html#ADID">Google Play
80  Developer Content Policies</a>.
81</p>
82
83<h3 id="format">Format of the Advertising ID</h3>
84
85<p>
86  Google Play services APIs expose the user's advertising ID as a string format of UUID,
87  with values similar to this:
88</p>
89<p style="margin-left:1.5em;"><code>“38400000-8cf0-11bd-b23e-10b96e40000d”</code></p>
90
91<h3 id="requirements">Requirements</h3>
92
93<ul>
94  <li>The advertising ID APIs are supported in Google Play services 4.0+</li>
95  <li>Support for the advertising ID on specific devices is based on their installed versions
96  of Google Play services</li>
97</ul>
98
99<h3 id="obtaining">Obtaining the user's advertising ID and ad tracking preference</h3>
100
101<p>
102  If you want to use the advertising ID in your app, you must first install the Google
103  Play services SDK. As noted in the requirements above, you should install the
104  SDK for Google Play services 4.0 or higher if you will develop using the advertising ID
105  APIs. For information about how to get started, see <a href=
106  "{@docRoot}google/play-services/setup.html">Set Up Google Play services</a>.
107</p>
108<p>
109  The advertising ID APIs are available in the <a href=
110  "{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html">
111  <code>com.google.android.gms.ads.identifier</code></a> package in the Google
112  Play Services library. To obtain the user's advertising ID and tracking preference,
113  call the method
114  <a href=
115  "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.html#getAdvertisingIdInfo(android.content.Context)">
116  <code>getAdvertisingIdInfo()</code></a>, which returns an <a href=
117  "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info.html">
118  <code>AdvertisingIdClient.Info</code></a> encapsulating the user's current Advertising ID
119  and tracking preference.
120</p>
121
122<p class="note">
123  <strong>Note:</strong> The <code>getAdvertisingIdInfo()</code> method is a
124  blocking call, so you must not call it on the main (UI) thread. If called on
125  the main thread, the method throws <code>IllegalStateException</code>.
126</p>
127
128<p>
129  Once you've retrieved the <code>AdvertisingIdClient.Info</code> object, you
130  can use it's <a href=
131  "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info.html#getId()">
132  <code>getId()</code></a> and <a href=
133  "{@docRoot}reference/com/google/android/gms/ads/identifier/AdvertisingIdClient.Info.html#isLimitAdTrackingEnabled()">
134  <code>isLimitAdTrackingEnabled()</code></a> methods to access the advertising ID and
135  ad tracking preference.
136</p>
137
138<table>
139<tr>
140<th>Method</th>
141<th>Description</th>
142</tr>
143<tr>
144<td><code>public String getId()</code></td>
145<td style="white-space:nowrap;">Retrieves the advertising ID.</td>
146</tr>
147<tr>
148<td style="white-space:nowrap;"><code>public boolean isLimitAdTrackingEnabled()</code></td>
149<td>Retrieves whether the user has limit ad tracking enabled or not.</td>
150</tr>
151</table>
152
153<p>
154  The advertising ID APIs do not include a "reset" method. Only users can initiate a
155  reset of their own advertising IDs, through the Google Settings application.
156</p>
157<p>
158  For more information about the advertising ID APIs, see the <a href=
159  "{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html">
160  reference documentation</a>.
161</p>
162
163<h3 id="example">Example implementation</h3>
164
165<p>
166  Here's a basic illustration of how you can retrieve the user's advertising ID and ad
167  tracking preference in your app:
168</p>
169
170<pre>
171import com.google.android.gms.ads.identifier.AdvertisingIdClient;
172import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
173import com.google.android.gms.common.GooglePlayServicesAvailabilityException;
174import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
175import java.io.IOException;
176...
177
178// Do not call this function from the main thread. Otherwise,
179// an IllegalStateException will be thrown.
180public void getIdThread() {
181
182  Info adInfo = null;
183  try {
184    adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
185
186  } catch (IOException e) {
187    // Unrecoverable error connecting to Google Play services (e.g.,
188    // the old version of the service doesn't support getting AdvertisingId).
189
190  } catch (GooglePlayServicesAvailabilityException e) {
191    // Encountered a recoverable error connecting to Google Play services.
192
193  } catch (GooglePlayServicesNotAvailableException e) {
194    // Google Play services is not available entirely.
195  }
196  final String id = adInfo.getId();
197  final boolean isLAT = adInfo.isLimitAdTrackingEnabled();
198}</pre>