> ## Documentation Index
> Fetch the complete documentation index at: https://docs.adrop.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ターゲティング設定

> REST APIでユーザー属性およびコンテキストターゲティングを設定する方法を案内します。

ターゲティングを使用すると、特定のユーザーグループやコンテキストに合った広告を表示できます。REST APIではオーディエンスターゲティングとコンテキストターゲティングの両方をサポートしています。

## オーディエンスターゲティング

ユーザー属性に基づいて広告をターゲティングします。

### リクエストパラメータ

<ParamField header="Authorization" type="string" required>
  App Key（adrop\_service.jsonで確認）
</ParamField>

<ParamField header="Content-Type" type="string" required>
  `application/json`
</ParamField>

<ParamField body="uid" type="string" required>
  ユーザー固有識別子
</ParamField>

<ParamField body="value" type="string" required>
  属性データ（JSON文字列）。プリセットおよびカスタム属性を含む
</ParamField>

<ParamField body="platform" type="string">
  プラットフォーム。例：`web`、`android`、`ios`
</ParamField>

<ParamField body="adid" type="string">
  広告識別子（ADID/IDFA）
</ParamField>

### レスポンス

<ResponseField name="code" type="integer">
  レスポンスコード。`0`は成功
</ResponseField>

<ResponseField name="msg" type="string">
  レスポンスメッセージ
</ResponseField>

<ResponseExample>
  ```json 成功レスポンス theme={null}
  {
      "code": 0,
      "msg": "OK"
  }
  ```
</ResponseExample>

***

## プリセット属性

Adropで事前に定義された標準属性です。すべてのSDKとREST APIで同じ形式を使用します。

### 生年月日（BIRTH）

| キー      | 値の例        | 形式              |
| ------- | ---------- | --------------- |
| `BIRTH` | `2024`     | yyyy（年のみ）       |
| `BIRTH` | `202401`   | yyyyMM（年月）      |
| `BIRTH` | `20240101` | yyyyMMdd（完全な日付） |

### 性別（GDR）

| キー    | 値   | 意味          |
| ----- | --- | ----------- |
| `GDR` | `M` | 男性（Male）    |
| `GDR` | `F` | 女性（Female）  |
| `GDR` | `U` | 不明（Unknown） |

### 不明な値

| キー  | 値   | 説明                  |
| --- | --- | ------------------- |
| `*` | `U` | すべての属性で「不明」を表す場合に使用 |

<Note>
  プリセット属性キーは大文字を使用します：`BIRTH`、`GDR`
</Note>

***

## カスタム属性

コンソールで定義したカスタム属性を使用できます。

### カスタム属性の設定

1. [Adropコンソール](https://console.adrop.io)で**ターゲティング**メニューに移動
2. **オーディエンスターゲティング**タブでカスタム属性を作成
3. APIでそのキー・値で属性を送信

```javascript theme={null}
const properties = {
    // プリセット属性
    BIRTH: '19931225',
    GDR: 'M',

    // カスタム属性（コンソールで定義）
    membership: 'premium',
    lastPurchaseDate: '2024-01-15',
    favoriteCategory: 'electronics'
};
```

<Warning>
  カスタム属性のすべての値は文字列（STRING）タイプです。
</Warning>

***

## コンテキストターゲティング

ページやコンテンツのコンテキストに応じて広告をターゲティングします。広告リクエスト時に`contextId`パラメータを追加します。

### コンテキストターゲティングの設定

1. [Adropコンソール](https://console.adrop.io)で**ターゲティング**メニューに移動
2. **コンテキストターゲティング**タブでコンテキストを作成
3. 広告リクエスト時に`contextId`パラメータを使用

### 広告リクエストへのコンテキスト適用

```
GET https://api-v2.adrop.io/request?unit=YOUR_UNIT_ID&contextId=sport
```

<CodeGroup>
  ```javascript Node.js theme={null}
  const axios = require('axios');

  const config = {
      method: 'get',
      baseURL: 'https://api-v2.adrop.io',
      url: '/request',
      params: {
          unit: 'YOUR_UNIT_ID',
          uid: 'USER_ID',
          pf: 'web',
          contextId: 'sport'  // コンソールで作成したコンテキストID
      },
      headers: {
          'Authorization': 'YOUR_APP_KEY'
      }
  };

  axios.request(config)
      .then((response) => {
          console.log(JSON.stringify(response.data));
      })
      .catch((error) => {
          console.log(error);
      });
  ```

  ```python Python theme={null}
  import requests

  url = "https://api-v2.adrop.io/request"
  params = {
      "unit": "YOUR_UNIT_ID",
      "uid": "USER_ID",
      "pf": "web",
      "contextId": "sport"
  }
  headers = {
      "Authorization": "YOUR_APP_KEY"
  }

  response = requests.get(url, params=params, headers=headers)
  print(response.json())
  ```

  ```curl cURL theme={null}
  curl -X GET "https://api-v2.adrop.io/request?unit=YOUR_UNIT_ID&uid=USER_ID&pf=web&contextId=sport" \
    -H "Authorization: YOUR_APP_KEY"
  ```
</CodeGroup>

***

## ベストプラクティス

<CardGroup cols={2}>
  <Card title="ユーザーIDの一貫性" icon="fingerprint">
    同じユーザーには常に同じ`uid`を使用してください。一貫したIDは正確なターゲティングの鍵です。
  </Card>

  <Card title="属性の更新" icon="rotate">
    ユーザー情報が変更されたら、すぐに`/property`エンドポイントを呼び出して更新してください。
  </Card>

  <Card title="プリセット形式の遵守" icon="check">
    `BIRTH`と`GDR`属性は、定められた形式を正確に使用する必要があります。
  </Card>

  <Card title="コンテキストの活用" icon="tags">
    ニュース、スポーツ、ショッピングなどのページの特性に合ったコンテキストターゲティングを活用してください。
  </Card>
</CardGroup>

***

## 関連ドキュメント

<CardGroup cols={2}>
  <Card title="オーディエンスターゲティング" icon="users" href="/ja/targeting/audience">
    コンソールでオーディエンスターゲティングを設定
  </Card>

  <Card title="コンテキストターゲティング" icon="tags" href="/ja/targeting/context">
    コンソールでコンテキストターゲティングを設定
  </Card>
</CardGroup>
