blob: 43d1809a2d2e917b803f0d625935885e8f68afa1 [file] [log] [blame]
page.title=Advertising ID
page.tags=Ads,Advertising ID,ID
<div class="landing-banner">
<div class="col-8">
<h1 itemprop="name" style="margin-bottom:0;">Advertising ID</h1>
<p itemprop="description">The advertising ID is a user-specific, unique,
resettable ID for advertising, provided by Google Play services. It gives
users better controls and provides developers with a simple, standard system
to continue to monetize your apps. It is an anonymous identifier for advertising
purposes and enables users to reset their identifier or opt out of interest-based
ads within Google Play apps. </p>
<p>The advertising ID is accessible through a straightforward API that you can implement in your apps. For details,
take a look at the
<a href="#get_started">overview</a> and the <a
href="{@docRoot}reference/com/google/android/gms/ads/identifier/package-summary.html">advertising ID API reference</a>.
<div class="landing-docs">
<div class="col-6 normal-links">
<h3 style="clear:left">Key Developer Features</h3>
<h4>Standard, simple ID</h4>
<p>The advertising ID is a part of a standard, simple system for serving ads and performing analytics.</p>
<h4>Giving users control</h4>
<p>Users can reset their advertising ID or opt out of interest-based ads at any time, right from the Google Settings app.
Their preferences apply across all ad companies that use the advertising ID.</p>
<div class="col-6 normal-links">
<h3 style="clear:left">Getting Started</h3>
<h4>1. Get the Google Play services SDK</h4>
<p>The advertising ID APIs are part of the Google Play services platform.</p>
<p>To get started, <a href="{@docRoot}google/play-services/setup.html">set up
the Google Play services SDK</a>. </p>
<h4>2. Read the docs and example code</h4>
<p>Once you've installed the Google Play services package, review the <a href="#get_started">overview</a>
below, as well as the <a href="#example">example</a>.</p>
For detailed documentation, take a look at the <a href=
advertising ID API reference documentation</a>.
<p class="caution" style=
As a reminder, please note that starting <strong>1 August 2014</strong>, new
apps and app updates distributed through Google Play must use the advertising
ID in lieu of any other persistent identifiers for any advertising purposes,
on devices that support the advertising ID.<br>
To learn how to check your app's compliance through the Developer Console, or
for details on the associated developer policy changes, please see the
<a href=
ID topic</a> in the Google Play developer help center.
<h2 id="get_started">Using the Advertising ID</h2>
The <strong>advertising ID</strong> is a unique but
user-resettable string identifier that lets ad networks and other apps anonymously
identify a user. The user's advertising ID is made available to apps through APIs
provided in Google Play services.
Users can reset their advertising ID at any time, right from the Ads section of the
Google Settings app on their devices. From the same app, users can also
opt-out of targeted advertising based on the advertising ID by setting the appropriate
<strong style="white-space:nowrap">ad tracking preference</strong>. When the
user opts-out of targeted ads, this ad tracking preference is made available
to apps through a Google Play services API.
Apps making use of the advertising ID <strong>must check for and respect</strong> the
user's ad tracking preference. Also please note that any use of the advertising ID
must abide by the terms of the <a class="external-link"
href="">Google Play
Developer Content Policies</a>.
<h3 id="format">Format of the Advertising ID</h3>
Google Play services APIs expose the user's advertising ID as a string format of UUID,
with values similar to this:
<p style="margin-left:1.5em;"><code>ā€œ38400000-8cf0-11bd-b23e-10b96e40000dā€</code></p>
<h3 id="requirements">Requirements</h3>
<li>The advertising ID APIs are supported in Google Play services 4.0+</li>
<li>Support for the advertising ID on specific devices is based on their installed versions
of Google Play services</li>
<h3 id="obtaining">Obtaining the user's advertising ID and ad tracking preference</h3>
If you want to use the advertising ID in your app, you must first install the Google
Play services SDK. As noted in the requirements above, you should install the
SDK for Google Play services 4.0 or higher if you will develop using the advertising ID
APIs. For information about how to get started, see <a href=
"{@docRoot}google/play-services/setup.html">Set Up Google Play services</a>.
The advertising ID APIs are available in the <a href=
<code></code></a> package in the Google
Play Services library. To obtain the user's advertising ID and tracking preference,
call the method
<a href=
<code>getAdvertisingIdInfo()</code></a>, which returns an <a href=
<code>AdvertisingIdClient.Info</code></a> encapsulating the user's current Advertising ID
and tracking preference.
<p class="note">
<strong>Note:</strong> The <code>getAdvertisingIdInfo()</code> method is a
blocking call, so you must not call it on the main (UI) thread. If called on
the main thread, the method throws <code>IllegalStateException</code>.
Once you've retrieved the <code>AdvertisingIdClient.Info</code> object, you
can use it's <a href=
<code>getId()</code></a> and <a href=
<code>isLimitAdTrackingEnabled()</code></a> methods to access the advertising ID and
ad tracking preference.
<td><code>public String getId()</code></td>
<td style="white-space:nowrap;">Retrieves the advertising ID.</td>
<td style="white-space:nowrap;"><code>public boolean isLimitAdTrackingEnabled()</code></td>
<td>Retrieves whether the user has limit ad tracking enabled or not.</td>
The advertising ID APIs do not include a "reset" method. Only users can initiate a
reset of their own advertising IDs, through the Google Settings application.
For more information about the advertising ID APIs, see the <a href=
reference documentation</a>.
<h3 id="example">Example implementation</h3>
Here's a basic illustration of how you can retrieve the user's advertising ID and ad
tracking preference in your app:
// Do not call this function from the main thread. Otherwise,
// an IllegalStateException will be thrown.
public void getIdThread() {
Info adInfo = null;
try {
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
} catch (IOException e) {
// Unrecoverable error connecting to Google Play services (e.g.,
// the old version of the service doesn't support getting AdvertisingId).
} catch (GooglePlayServicesAvailabilityException e) {
// Encountered a recoverable error connecting to Google Play services.
} catch (GooglePlayServicesNotAvailableException e) {
// Google Play services is not available entirely.
final String id = adInfo.getId();
final boolean isLAT = adInfo.isLimitAdTrackingEnabled();