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

# Targeting Settings

> Learn how to configure audience targeting and contextual targeting.

## Audience Targeting

You can target ads based on user properties.

### 1. Create Targeting

First, create audience targeting in Ad Control Console.

<Card title="Create Targeting" icon="bullseye" href="/targeting/audience">
  Check how to create audience targeting in the console
</Card>

### 2. Set User ID

You must set `appKey` and `uid` before rendering ads.

```tsx theme={null}
import { Adrop } from '@adrop/ads-web-sdk';

// Set user ID after login
Adrop.instance().setConfig({
  appKey: 'YOUR_APP_KEY',
  uid: 'USER_ID'
});
```

<Note>
  Complete the setup before entering the ad placement for targeted ads to work properly.
</Note>

### 3. Set User Properties

Setting user properties enables more sophisticated targeting.

```tsx theme={null}
const adrop = Adrop.instance();

await adrop.metrics
  .setUserProperties({
    // Built-in properties
    adid: 'ADVERTISING_ID',
    birth: '19931225',        // YYYY, YYYYMM, YYYYMMDD
    gender: 'M',              // M, F, U
    locale: 'ko_KR',          // ISO 639
    timeZone: 'Asia/Seoul',   // ISO 8601

    // Custom properties (must be registered in console)
    membership: 'premium',
    interests: 'tech,gaming'
  })
  .setAppProperties({
    appName: 'com.example.app',
    appVersion: '1.0.0',
    appBundleVersion: 100
  })
  .commit();
```

<Warning>
  You must call `commit()` to save properties to the server. It overwrites rather than merges with existing data, so send all properties together when updating.
</Warning>

### Built-in Properties

| Field      | Description    | Format                 |
| ---------- | -------------- | ---------------------- |
| `adid`     | Advertising ID | String                 |
| `birth`    | Birth date     | YYYY, YYYYMM, YYYYMMDD |
| `gender`   | Gender         | M, F, U                |
| `locale`   | Locale         | ISO 639 (ko\_KR)       |
| `timeZone` | Time zone      | ISO 8601 (Asia/Seoul)  |

### App Properties

| Field              | Description         |
| ------------------ | ------------------- |
| `appName`          | App package ID      |
| `appVersion`       | App version (1.0.0) |
| `appBundleVersion` | App build number    |

### Device Properties (Auto-collected)

The SDK automatically collects the following device properties. You do not need to set these manually.

| Field              | Description          |
| ------------------ | -------------------- |
| `sdkv`             | SDK version          |
| `deviceWidth`      | Device screen width  |
| `deviceHeight`     | Device screen height |
| `osVersion`        | OS version           |
| `webViewUserAgent` | Browser user agent   |
| `platform`         | Platform (web)       |

### Custom Properties

You can set additional properties registered in the console. Values must match the type defined in Ad Control Console.

```tsx theme={null}
await adrop.metrics
  .setUserProperties({
    membership: 'premium',
    lastPurchaseDate: '2024-01-15',
    favoriteCategory: 'electronics'
  })
  .commit();
```

***

## Contextual Targeting

You can target ads based on page or content context.

### 1. Create Targeting

First, create contextual targeting in Ad Control Console.

<Card title="Create Contextual Targeting" icon="tags" href="/targeting/context">
  Check how to create contextual targeting in the console
</Card>

### 2. Set Value on Ad Placement

Pass the Context Value configured in the console when requesting ads.

#### Data Attributes Method

```tsx theme={null}
function BannerAd() {
  return (
    <div
      data-adrop-unit="YOUR_UNIT_ID"
      data-adrop-context-id="sport"
    />
  );
}
```

#### renderAd Method

```tsx theme={null}
import { useEffect, useRef } from 'react';
import { Adrop } from '@adrop/ads-web-sdk';

function BannerAd() {
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const adrop = Adrop.instance();

    if (containerRef.current) {
      adrop.renderAd(containerRef.current, {
        unit: 'YOUR_UNIT_ID',
        contextId: 'sport'
      });
    }

    return () => {
    };
  }, []);

  return <div ref={containerRef} />;
}
```

### Dynamic Context Setting

You can set context dynamically based on page or content.

```tsx theme={null}
import { useEffect, useRef } from 'react';
import { Adrop } from '@adrop/ads-web-sdk';

interface AdProps {
  unitId: string;
  category: string;  // Page category
}

function ContextualAd({ unitId, category }: AdProps) {
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const adrop = Adrop.instance();

    if (containerRef.current) {
      adrop.renderAd(containerRef.current, {
        unit: unitId,
        contextId: category  // Pass dynamically
      });
    }

    return () => {
    };
  }, [unitId, category]);

  return <div ref={containerRef} />;
}

// Usage example
function SportPage() {
  return (
    <div>
      <h1>Sports News</h1>
      <ContextualAd unitId="NEWS_BANNER" category="sport" />
    </div>
  );
}

function TechPage() {
  return (
    <div>
      <h1>Tech News</h1>
      <ContextualAd unitId="NEWS_BANNER" category="tech" />
    </div>
  );
}
```

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Reference > AdropConfig" icon="book" href="/sdk/web/reference#adropconfig">
    Initialization option definitions
  </Card>

  <Card title="Reference > AdropAdRequest" icon="book" href="/sdk/web/reference#adropadrequest">
    Ad request parameter definitions
  </Card>
</CardGroup>
