> ## 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.

# リファレンス

> Adrop Web SDKのクラス、インターフェース、定数、タイプ定義です。

## クラス

### Adrop

SDKのメインクラスです。シングルトンパターンで動作します。

#### 静的メソッド

| メソッド              | 戻り値     | 説明                 |
| ----------------- | ------- | ------------------ |
| `observe(config)` | `Adrop` | SDK初期化およびDOM自動検出開始 |
| `instance()`      | `Adrop` | 既存インスタンスを返す        |

#### インスタンスメソッド

| メソッド                            | 戻り値                         | 説明               |
| ------------------------------- | --------------------------- | ---------------- |
| `renderAd(container, request?)` | `Promise<void>`             | 広告レンダリング         |
| `requestAd(request)`            | `Promise<AdropAdResponse>`  | 広告データのみリクエスト（単一） |
| `requestAds(request)`           | `Promise<AdropAdsResponse>` | 複数広告データリクエスト     |
| `clear(container)`              | `void`                      | 広告削除             |
| `setConfig(config)`             | `void`                      | 設定変更             |
| `on(event, callback, filter?)`  | `void`                      | イベントリスナー登録       |
| `off(event, callback)`          | `void`                      | イベントリスナー解除       |

#### インスタンスプロパティ

| プロパティ     | タイプ            | 説明                      |
| --------- | -------------- | ----------------------- |
| `uid`     | `string`       | ユーザー識別子 (getter/setter) |
| `appKey`  | `string`       | API認証キー (getter/setter) |
| `metrics` | `AdropMetrics` | ユーザー属性管理                |

### AdropMetrics

ユーザー属性管理クラスです。

#### メソッド

| メソッド                       | 戻り値             | 説明                     |
| -------------------------- | --------------- | ---------------------- |
| `setUserProperties(props)` | `AdropMetrics`  | ユーザー属性を設定（チェーン可能）      |
| `setAppProperties(props)`  | `AdropMetrics`  | アプリ属性を設定（チェーン可能）       |
| `commit()`                 | `Promise<void>` | 属性をサーバーに保存             |
| `properties()`             | `Properties`    | 現在設定されている属性を返す         |
| `clear()`                  | `void`          | 設定された属性をクリア（デバイス属性は保持） |

***

## インターフェース

### AdropConfig

SDK初期化オプションです。

```typescript theme={null}
interface AdropConfig {
  appId: string;             // アプリID（必須）
  uid?: string;              // ユーザー識別子
  appKey?: string;           // API認証キー
  debug?: boolean;           // デバッグログ（デフォルト: false）
  backfillMode?: BackfillMode; // グローバルバックフィルレンダリングモード（1.2.3+、デフォルト: 'responsive'）
}
```

### AdropAdRequest

広告リクエストパラメータです。

```typescript theme={null}
interface AdropAdRequest {
  unit: string;              // ユニットID（必須）
  uid?: string;              // ユーザー識別子
  contextId?: string;        // コンテキストターゲティングID
  trackMode?: 0 | 1;         // 0: 自動, 1: 手動（ネイティブ）
  isEntireClick?: boolean;   // 全領域クリック（ネイティブ）
  theme?: AdTheme;           // テーマ
  useCustomClick?: boolean;  // カスタムクリック処理
  backfillMode?: BackfillMode; // スロット単位のバックフィルレンダリングモード上書き（1.2.3+）
  adId?: string;             // 広告識別子 — デバイスで表示時に必須
}
```

<Note>
  `adId`は**デバイスで表示**機能で登録済みテストデバイスからドラフトクリエイティブをプレビューするときに使用する広告識別子です。設定方法は[テストデバイスでクリエイティブをプレビュー](/ja/management/support#テストデバイスでクリエイティブをプレビュー)ガイドを参照してください。本番環境に `adId` をハードコードしたままデプロイしないでください。
</Note>

### AdropAdResponse

広告レスポンスオブジェクトです（単一広告）。

```typescript theme={null}
interface AdropAdResponse {
  code: AdropErrorCode;  // レスポンスコード
  msg: string;           // レスポンスメッセージ
  result?: AdData;       // 広告データ（成功時）
}
```

### AdropAdsResponse

広告レスポンスオブジェクトです（複数広告）。

```typescript theme={null}
interface AdropAdsResponse {
  code: AdropErrorCode;  // レスポンスコード
  msg: string;           // レスポンスメッセージ
  results?: AdData[];    // 広告データ配列（成功時）
}
```

### AdData

広告データオブジェクトです。

```typescript theme={null}
interface AdData {
  // 共通
  format: AdFormat;       // 広告フォーマット
  unit: string;           // ユニットID
  ad: string;             // 広告HTMLコンテンツ
  w: number;              // 広告幅
  h: number;              // 広告高さ
  type?: string;          // 広告タイプ
  target?: string;        // ターゲットURL開き方

  // ネイティブ広告フィールド
  headline?: string;      // 広告タイトル
  body?: string;          // 広告説明
  callToAction?: string;  // CTAボタンテキスト
  asset?: string;         // メイン画像URL
  destinationURL?: string; // クリック時遷移URL

  // 識別子フィールド
  id?: string;            // 広告ID
  cpId?: string;          // キャンペーンID
  creativeId?: string;    // クリエイティブID
  accountTag?: string;    // アカウントレベルタグ
  creativeTag?: string;   // クリエイティブレベルタグ

  // トラッカーフィールド (trackMode=1)
  pixelTracker?: string;  // ピクセルトラッカーURL（1x1画像、インプレッション追跡）
  imprTracker?: string;   // インプレッショントラッカーURL
  clickTracker?: string;  // クリックトラッカーURL

  // 広告主プロフィール
  profile?: {
    displayLogo?: string;  // 広告主ロゴURL
    displayName?: string;  // 広告主名
    link?: string;         // 広告主プロフィールリンク
  };

  // 追加テキスト項目
  extra?: Record<string, string>;
}
```

### AdropEventFilter

イベントフィルターオプションです。

```typescript theme={null}
interface AdropEventFilter {
  unit?: string;  // 特定ユニットのみフィルタリング
}
```

***

## 定数

### Adrop.Events

イベント定数です。`Adrop.Events`でアクセスします。

| 定数                    | 値                    | 説明         |
| --------------------- | -------------------- | ---------- |
| `AD_RECEIVED`         | `'adReceived'`       | 広告受信成功     |
| `AD_NO_FILL`          | `'adNoFill'`         | 直接広告なし     |
| `AD_IMPRESSION`       | `'adImpression'`     | 広告表示       |
| `AD_CLICKED`          | `'adClicked'`        | 広告クリック     |
| `AD_FAILED`           | `'adFailed'`         | 広告リクエスト失敗  |
| `AD_BACKFILL_NO_FILL` | `'adBackfillNoFill'` | バックフィル広告なし |
| `AD_VIDEO_START`      | `'adVideoStart'`     | 動画広告の再生開始  |
| `AD_VIDEO_END`        | `'adVideoEnd'`       | 動画広告の再生完了  |

### Adrop.ErrorCode

エラーコードです。`Adrop.ErrorCode`でアクセスします。

| 定数                          | 値      | 説明             |
| --------------------------- | ------ | -------------- |
| `OK`                        | `0`    | 成功             |
| `ERROR_CODE_INVALID_UNIT`   | `4000` | 無効なユニットID      |
| `ERROR_CODE_AD_INACTIVE`    | `4001` | アクティブなキャンペーンなし |
| `ERROR_CODE_AD_NO_FILL`     | `4002` | マッチする広告なし      |
| `ERROR_CODE_INVALID_PARAMS` | `4003` | 無効なパラメータ       |

***

## タイプ

### AdFormat

広告フォーマットタイプです。

```typescript theme={null}
type AdFormat = 'banner' | 'nativeAd' | 'backfill';
```

### AdTheme

テーマタイプです。

```typescript theme={null}
type AdTheme = 'light' | 'dark';
```

### BackfillMode

バックフィル広告レンダリングモードタイプです。（SDK 1.2.3+）

```typescript theme={null}
type BackfillMode = 'responsive' | 'fixed';
```

詳細な動作と選択基準は[バックフィルレンダリングモード](/ja/sdk/web/backfill)ガイドを参照してください。

***

## イベントコールバック

各イベントのコールバックシグネチャです。

```typescript theme={null}
// 広告受信、インプレッション、クリック
type AdReceivedCallback = (unit: string, adData: AdData) => void;
type AdImpressionCallback = (unit: string, adData: AdData) => void;
type AdClickedCallback = (unit: string, adData: AdData) => void;

// 広告なし、失敗、バックフィル広告なし
type AdNoFillCallback = (unit: string) => void;
type AdFailedCallback = (unit: string) => void;
type AdBackfillNoFillCallback = (unit: string) => void;

// 動画
type AdVideoStartCallback = (unit: string, adData: AdData) => void;
type AdVideoEndCallback = (unit: string, adData: AdData) => void;
```

<Note>
  すべてのイベントコールバックは最初の引数として`unit`を受け取ります。`AD_RECEIVED`、`AD_IMPRESSION`、`AD_CLICKED`、`AD_VIDEO_START`、`AD_VIDEO_END`イベントは2番目の引数として`adData`も受け取ります。
</Note>
