> For the complete documentation index, see [llms.txt](https://app.developers.karte.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://app.developers.karte.io/android-sdk-appendix/appendix-aaid-android-sdk.md).

# \[Android]広告ID（AAID）を送信する

KARTE SDKによる広告ID（AAID）の送信を有効にしたい場合は、本記事を参考に設定をしてください。

{% hint style="warning" %}
**広告IDの送信について**

広告IDの送信にはいくつか注意事項がございます。\
送信処理を実装する前に、まず [こちら](https://support.karte.io/post/13v6pgNyNKtrxyIvYZcnAs) の記事をご覧ください。
{% endhint %}

## 事前準備

FirebaseやGMSなどのライブラリを参照していない場合は、広告IDを取得するためのライブラリを個別に追加する必要があります。\
[こちら](https://developer.android.com/training/articles/ad-id?hl=ja)を参考に、広告IDを取得するためのライブラリを追加して下さい。

アプリの `build.gradle` を任意のエディタで開き、`dependencies` ブロックにライブラリを追加します。

{% code title="build.gradle" overflow="wrap" %}

```groovy
dependencies {
  implementation 'com.google.android.gms:play-services-ads-identifier:17.0.0'
}
```

{% endcode %}

現在、SDK内部では以下のライブラリでの広告IDの取得に対応しています。

* `com.google.android.gms:play-services-ads-identifier:17.0.0`

{% hint style="warning" %}
**API レベル31以上を対象とするアプリの場合**

アプリのtargetSdkVersionが31(Android 12)の場合、デバイスの広告IDを読み取るにはパーミッション `com.google.android.gms.AD_ID` を追加する必要があります。\
参考：[広告 ID - Play Console ヘルプ](https://support.google.com/googleplay/android-developer/answer/6048248?hl=ja)
{% endhint %}

## 設定

初期化オプションを指定してSDKの初期化を行います。

{% tabs %}
{% tab title="Kotlin" %}
{% code title="YourApplication.kt" overflow="wrap" %}

```kotlin
class YourApplication : Application() {
  override fun onCreate() {
    super.onCreate()
    KarteApp.setup(this, "アプリケーションキー", Config.build { enabledTrackingAaid = true })
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code title="YourApplication.java" overflow="wrap" %}

```java
public class YourApplication extends Application {
  @Override
  public void onCreate() {
    super.onCreate();
    KarteApp.setup(this, "アプリケーションキー", new Config.Builder().enabledTrackingAaid(true).build());
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 確認

任意のイベントの `app_info.system_info.aaid` フィールドに値が含まれていれば、正しく実装されております。

詳細な確認方法については、[こちら](https://support.karte.io/post/2KR0mMpfIE74RrEihDUTv0) をご覧ください。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://app.developers.karte.io/android-sdk-appendix/appendix-aaid-android-sdk.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
