> ## 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 display customized ads to specific user groups through targeting in Android SDK.

## Overview

Through targeting settings, you can display customized ads to specific user groups. The Adrop SDK provides two targeting methods:

* **Audience Targeting**: Display ads based on user properties.
* **Contextual Targeting**: Display ads based on content context (category, topic, etc.).

<Note>
  To collect targeting data, UID and properties must be set before loading ads.
</Note>

***

## UID Setting

Set a user identifier (UID) to distinguish users. UID is the foundation for targeted advertising.

### Usage

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.Adrop

  // After user login
  Adrop.setUID("user_123")
  ```

  ```java Java theme={null}
  import io.adrop.ads.Adrop;

  // After user login
  Adrop.INSTANCE.setUID("user_123");
  ```
</CodeGroup>

### Parameters

| Parameter | Type     | Description                                      |
| --------- | -------- | ------------------------------------------------ |
| `uid`     | `String` | User unique identifier (e.g., service member ID) |

<Warning>
  UID is hashed with SHA-256 before transmission. Do not pass personal information (email, phone number, etc.) directly.
</Warning>

***

## Audience Targeting

Collect user property information to display ads to specific user groups.

### Setting Properties

Use the `AdropMetrics.setProperty()` method to collect user property information.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics

  // String property
  AdropMetrics.setProperty("membership_level", "premium")

  // Numeric property
  AdropMetrics.setProperty("booking_count", 15)

  // Boolean property
  AdropMetrics.setProperty("is_subscriber", true)

  // Pass null (remove property)
  AdropMetrics.setProperty("membership_level", null)
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;

  // String property
  AdropMetrics.setProperty("membership_level", "premium");

  // Numeric property
  AdropMetrics.setProperty("booking_count", 15);

  // Boolean property
  AdropMetrics.setProperty("is_subscriber", true);

  // Pass null (remove property)
  AdropMetrics.setProperty("membership_level", null);
  ```
</CodeGroup>

### Parameters

| Parameter | Type     | Description                                               |
| --------- | -------- | --------------------------------------------------------- |
| `key`     | `String` | Property key (max 64 characters)                          |
| `value`   | `Any?`   | Property value (String, Int, Double, Long, Boolean, null) |

<Warning>
  * Property key is limited to 64 characters maximum.
  * String values are limited to 256 characters maximum.
  * Numeric values are limited to 9007199254740991 maximum.
  * Up to 256 properties can be set.
</Warning>

### Default Properties

The Adrop SDK provides default properties for targeting. Use the `AdropKey` and `AdropValue` classes to set values.

#### Age (Birthday)

When birthday information is provided, age is automatically calculated.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics
  import io.adrop.ads.model.AdropKey
  import io.adrop.ads.model.AdropValue

  // Year only (yyyy)
  AdropMetrics.setProperty(AdropKey.BIRTH, "1990")

  // Year and month (yyyyMM)
  AdropMetrics.setProperty(AdropKey.BIRTH, "199003")

  // Year, month, and day (yyyyMMdd)
  AdropMetrics.setProperty(AdropKey.BIRTH, "19900315")
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;
  import io.adrop.ads.model.AdropKey;
  import io.adrop.ads.model.AdropValue;

  // Year only (yyyy)
  AdropMetrics.setProperty(AdropKey.BIRTH, "1990");

  // Year and month (yyyyMM)
  AdropMetrics.setProperty(AdropKey.BIRTH, "199003");

  // Year, month, and day (yyyyMMdd)
  AdropMetrics.setProperty(AdropKey.BIRTH, "19900315");
  ```
</CodeGroup>

**Date Format Constants**

| Constant                                   | Value        | Description                             |
| ------------------------------------------ | ------------ | --------------------------------------- |
| `AdropValue.AdropBirth.formatYear`         | `"yyyy"`     | Year only (e.g., "1990")                |
| `AdropValue.AdropBirth.formatYearMonth`    | `"yyyyMM"`   | Year and month (e.g., "199003")         |
| `AdropValue.AdropBirth.formatYearMonthDay` | `"yyyyMMdd"` | Year, month, and day (e.g., "19900315") |

#### Gender

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics
  import io.adrop.ads.model.AdropKey
  import io.adrop.ads.model.AdropValue

  // Male
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.AdropGender.MALE)

  // Female
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.AdropGender.FEMALE)

  // Other
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.AdropGender.OTHER)

  // Unknown
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.UNKNOWN)
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;
  import io.adrop.ads.model.AdropKey;
  import io.adrop.ads.model.AdropValue;

  // Male
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.AdropGender.MALE);

  // Female
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.AdropGender.FEMALE);

  // Other
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.AdropGender.OTHER);

  // Unknown
  AdropMetrics.setProperty(AdropKey.GENDER, AdropValue.UNKNOWN);
  ```
</CodeGroup>

**Gender Value Constants**

| Constant                        | Value | Description |
| ------------------------------- | ----- | ----------- |
| `AdropValue.AdropGender.MALE`   | `"M"` | Male        |
| `AdropValue.AdropGender.FEMALE` | `"F"` | Female      |
| `AdropValue.AdropGender.OTHER`  | `"O"` | Other       |
| `AdropValue.UNKNOWN`            | `"U"` | Unknown     |

#### Setting Age Directly

You can also set age directly instead of birthday.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics
  import io.adrop.ads.model.AdropKey

  AdropMetrics.setProperty(AdropKey.AGE, 30)
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;
  import io.adrop.ads.model.AdropKey;

  AdropMetrics.setProperty(AdropKey.AGE, 30);
  ```
</CodeGroup>

<Note>
  You only need to set either `BIRTH` or `AGE`. If both are set, `BIRTH` takes precedence.
</Note>

### Custom Properties

You can set custom properties for your service. Custom properties must first be defined in the **Targeting** menu of the [Adrop console](https://console.adrop.io).

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics

  // Local activity app example
  AdropMetrics.setProperty("region", "Seoul")
  AdropMetrics.setProperty("booking_count", 5)

  // Shopping mall app example
  AdropMetrics.setProperty("membership_tier", "gold")
  AdropMetrics.setProperty("total_purchase_amount", 1500000)

  // Media app example
  // Note: Array values are not supported. Use JSON string instead.
  AdropMetrics.setProperty("favorite_genres", """["drama","action"]""")
  AdropMetrics.setProperty("is_premium_subscriber", true)
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;

  // Local activity app example
  AdropMetrics.setProperty("region", "Seoul");
  AdropMetrics.setProperty("booking_count", 5);

  // Shopping mall app example
  AdropMetrics.setProperty("membership_tier", "gold");
  AdropMetrics.setProperty("total_purchase_amount", 1500000);

  // Media app example
  // Note: Array values are not supported. Use JSON string instead.
  AdropMetrics.setProperty("favorite_genres", "[\"drama\",\"action\"]");
  AdropMetrics.setProperty("is_premium_subscriber", true);
  ```
</CodeGroup>

<Warning>
  Custom property names must exactly match the names defined in the console. Case-sensitive.
</Warning>

### Property Usage Example

Example of updating properties when a user enters a specific screen in the app.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.Adrop
  import io.adrop.ads.metrics.AdropMetrics
  import io.adrop.ads.model.AdropKey
  import io.adrop.ads.model.AdropValue

  class ProfileActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_profile)

          // Get user info
          val user = getUserInfo()

          // Set UID
          Adrop.setUID(user.id)

          // Set default properties
          AdropMetrics.setProperty(AdropKey.BIRTH, user.birthDate)
          AdropMetrics.setProperty(AdropKey.GENDER, user.gender)

          // Set custom properties
          AdropMetrics.setProperty("membership_level", user.membershipLevel)
          AdropMetrics.setProperty("total_booking_count", user.bookingCount)
      }
  }
  ```

  ```java Java theme={null}
  import io.adrop.ads.Adrop;
  import io.adrop.ads.metrics.AdropMetrics;
  import io.adrop.ads.model.AdropKey;
  import io.adrop.ads.model.AdropValue;

  public class ProfileActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_profile);

          // Get user info
          User user = getUserInfo();

          // Set UID
          Adrop.INSTANCE.setUID(user.getId());

          // Set default properties
          AdropMetrics.setProperty(AdropKey.BIRTH, user.getBirthDate());
          AdropMetrics.setProperty(AdropKey.GENDER, user.getGender());

          // Set custom properties
          AdropMetrics.setProperty("membership_level", user.getMembershipLevel());
          AdropMetrics.setProperty("total_booking_count", user.getBookingCount());
      }
  }
  ```
</CodeGroup>

***

## Contextual Targeting

Display ads based on content context (category, topic, etc.). Use the `contextId` property in banner ads and native ads.

### Banner Ads

#### Setting in XML

<CodeGroup>
  ```xml XML theme={null}
  <io.adrop.ads.banner.AdropBanner
      android:id="@+id/adropBanner"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:adrop_unit_id="PUBLIC_TEST_UNIT_ID_320_50"
      app:adrop_context_id="article_sports" />
  ```
</CodeGroup>

#### Setting in Code

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.banner.AdropBanner

  val adropBanner = AdropBanner(this, "PUBLIC_TEST_UNIT_ID_320_50", "article_sports")

  // Or set on existing instance
  val existingBanner = findViewById<AdropBanner>(R.id.adropBanner)
  // contextId can only be set in the constructor
  ```

  ```java Java theme={null}
  import io.adrop.ads.banner.AdropBanner;

  AdropBanner adropBanner = new AdropBanner(this, "PUBLIC_TEST_UNIT_ID_320_50", "article_sports");

  // Or set on existing instance
  AdropBanner existingBanner = findViewById(R.id.adropBanner);
  // contextId can only be set in the constructor
  ```
</CodeGroup>

### Native Ads

Native ads can set `contextId` in the constructor.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.nativeAd.AdropNativeAd
  import io.adrop.ads.nativeAd.AdropNativeAdListener

  val nativeAd = AdropNativeAd(this, "PUBLIC_TEST_UNIT_ID_NATIVE")
  nativeAd.listener = object : AdropNativeAdListener {
      override fun onAdReceived(ad: AdropNativeAd) {
          // Ad received successfully
      }

      override fun onAdFailedToReceive(ad: AdropNativeAd, errorCode: AdropErrorCode) {
          // Ad failed to receive
      }
  }

  // contextId is set via constructor, load() takes no parameters
  nativeAd.load()
  ```

  ```java Java theme={null}
  import io.adrop.ads.nativeAd.AdropNativeAd;
  import io.adrop.ads.nativeAd.AdropNativeAdListener;

  // contextId is set via constructor
  AdropNativeAd nativeAd = new AdropNativeAd(this, "PUBLIC_TEST_UNIT_ID_NATIVE", "article_technology");
  nativeAd.setListener(new AdropNativeAdListener() {
      @Override
      public void onAdReceived(@NonNull AdropNativeAd ad) {
          // Ad received successfully
      }

      @Override
      public void onAdFailedToReceive(@NonNull AdropNativeAd ad, AdropErrorCode errorCode) {
          // Ad failed to receive
      }
  });

  // load() takes no parameters
  nativeAd.load();
  ```
</CodeGroup>

### Context ID Usage Example

Example of displaying ads based on article category in a news app.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.banner.AdropBanner

  class ArticleActivity : AppCompatActivity() {
      private lateinit var adropBanner: AdropBanner

      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_article)

          // Get article category
          val articleCategory = getArticleCategory() // "sports", "technology", "entertainment", etc.

          // Create banner with Context ID matching category
          val contextId = "article_$articleCategory"
          adropBanner = AdropBanner(this, "YOUR_UNIT_ID", contextId)

          // Add to layout
          val container = findViewById<ViewGroup>(R.id.ad_container)
          container.addView(adropBanner)

          // Load ad
          adropBanner.load()
      }
  }
  ```

  ```java Java theme={null}
  import io.adrop.ads.banner.AdropBanner;

  public class ArticleActivity extends AppCompatActivity {
      private AdropBanner adropBanner;

      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_article);

          // Get article category
          String articleCategory = getArticleCategory(); // "sports", "technology", "entertainment", etc.

          // Create banner with Context ID matching category
          String contextId = "article_" + articleCategory;
          adropBanner = new AdropBanner(this, "YOUR_UNIT_ID", contextId);

          // Add to layout
          ViewGroup container = findViewById(R.id.ad_container);
          container.addView(adropBanner);

          // Load ad
          adropBanner.load();
      }
  }
  ```
</CodeGroup>

<Note>
  Context ID must match the context targeting category defined in the console.
</Note>

***

## Event Tracking

Track user behavior events to build audiences based on user actions. Use `AdropMetrics.sendEvent()` to send events.

<Note>
  `logEvent()` is deprecated. Use `sendEvent()` instead.
</Note>

### Sending Events

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics
  import io.adrop.ads.metrics.AdropEventParam

  // Simple event (no parameters)
  AdropMetrics.sendEvent("app_open")

  // Event with parameters
  val params = AdropEventParam.Builder()
      .putString("item_id", "SKU-123")
      .putString("item_name", "Widget")
      .putFloat("price", 29.99f)
      .build()
  AdropMetrics.sendEvent("view_item", params)
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;
  import io.adrop.ads.metrics.AdropEventParam;

  // Simple event (no parameters)
  AdropMetrics.sendEvent("app_open");

  // Event with parameters
  AdropEventParam params = new AdropEventParam.Builder()
      .putString("item_id", "SKU-123")
      .putString("item_name", "Widget")
      .putFloat("price", 29.99f)
      .build();
  AdropMetrics.sendEvent("view_item", params);
  ```
</CodeGroup>

### Multi-Item Events

For events that involve multiple items (e.g., purchase, begin\_checkout), use `putItems()` to attach an item list.

<CodeGroup>
  ```kotlin Kotlin theme={null}
  import io.adrop.ads.metrics.AdropMetrics
  import io.adrop.ads.metrics.AdropEventParam

  val item1 = AdropEventParam.Builder()
      .putString("item_id", "A")
      .putString("item_name", "Product A")
      .putInt("price", 100)
      .putInt("quantity", 1)
      .build()
  val item2 = AdropEventParam.Builder()
      .putString("item_id", "B")
      .putString("item_name", "Product B")
      .putInt("price", 200)
      .putInt("quantity", 2)
      .build()
  val params = AdropEventParam.Builder()
      .putString("tx_id", "tx_123")
      .putString("currency", "KRW")
      .putItems(listOf(item1, item2))
      .build()
  AdropMetrics.sendEvent("purchase", params)
  ```

  ```java Java theme={null}
  import io.adrop.ads.metrics.AdropMetrics;
  import io.adrop.ads.metrics.AdropEventParam;

  AdropEventParam item1 = new AdropEventParam.Builder()
      .putString("item_id", "A")
      .putString("item_name", "Product A")
      .putInt("price", 100)
      .putInt("quantity", 1)
      .build();
  AdropEventParam item2 = new AdropEventParam.Builder()
      .putString("item_id", "B")
      .putString("item_name", "Product B")
      .putInt("price", 200)
      .putInt("quantity", 2)
      .build();
  AdropEventParam params = new AdropEventParam.Builder()
      .putString("tx_id", "tx_123")
      .putString("currency", "KRW")
      .putItems(java.util.Arrays.asList(item1, item2))
      .build();
  AdropMetrics.sendEvent("purchase", params);
  ```
</CodeGroup>

### Supported Event Examples

| Event Name        | Description        | Common Parameters                           |
| ----------------- | ------------------ | ------------------------------------------- |
| `app_open`        | App opened         | —                                           |
| `sign_up`         | User signed up     | `method`                                    |
| `view_item`       | Viewed item        | `item_id`, `item_name`, `price`             |
| `add_to_cart`     | Added to cart      | `item_id`, `item_name`, `price`, `quantity` |
| `add_to_wishlist` | Added to wishlist  | `item_id`, `item_name`, `price`             |
| `begin_checkout`  | Began checkout     | `currency`, `items`                         |
| `purchase`        | Purchase completed | `tx_id`, `currency`, `items`                |
| `page_view`       | Page viewed        | `page_id`, `page_category`                  |
| `click`           | Element clicked    | `element_id`, `element_type`                |

<Note>
  * Event name must be 1–64 characters.
  * Parameter key must be 1–64 characters.
  * String parameter values are limited to 1024 characters.
  * Duplicate events with the same name and parameters are throttled within a 500ms window.
</Note>

***

## Best Practices

### 1. Set UID Before Loading Ads

<CodeGroup>
  ```kotlin Kotlin theme={null}
  // Correct example
  Adrop.setUID("user_123")
  adropBanner.load()

  // Wrong example
  adropBanner.load()
  Adrop.setUID("user_123") // Targeting won't be applied if set after ad load
  ```

  ```java Java theme={null}
  // Correct example
  Adrop.INSTANCE.setUID("user_123");
  adropBanner.load();

  // Wrong example
  adropBanner.load();
  Adrop.INSTANCE.setUID("user_123"); // Targeting won't be applied if set after ad load
  ```
</CodeGroup>

### 2. Use Meaningful Context IDs

<CodeGroup>
  ```kotlin Kotlin theme={null}
  // Correct example
  val contextId = "article_${article.category}" // "article_sports", "article_tech"
  val adropBanner = AdropBanner(this, unitId, contextId)

  // Wrong example
  val contextId = "page_${randomNumber}" // Meaningless random value
  val adropBanner = AdropBanner(this, unitId, contextId)
  ```

  ```java Java theme={null}
  // Correct example
  String contextId = "article_" + article.getCategory(); // "article_sports", "article_tech"
  AdropBanner adropBanner = new AdropBanner(this, unitId, contextId);

  // Wrong example
  String contextId = "page_" + randomNumber; // Meaningless random value
  AdropBanner adropBanner = new AdropBanner(this, unitId, contextId);
  ```
</CodeGroup>

### 3. Update Properties Whenever They Change

<CodeGroup>
  ```kotlin Kotlin theme={null}
  class MainActivity : AppCompatActivity() {
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)

          // Set initial properties on app start
          updateUserProperties()
      }

      fun onUserPurchaseComplete(purchaseAmount: Int) {
          // Update properties on purchase completion
          val currentTotal = getCurrentTotalPurchase()
          AdropMetrics.setProperty("total_purchase_amount", currentTotal + purchaseAmount)
      }

      fun onMembershipUpgrade(newTier: String) {
          // Update properties on membership upgrade
          AdropMetrics.setProperty("membership_tier", newTier)
      }
  }
  ```

  ```java Java theme={null}
  public class MainActivity extends AppCompatActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);

          // Set initial properties on app start
          updateUserProperties();
      }

      public void onUserPurchaseComplete(int purchaseAmount) {
          // Update properties on purchase completion
          int currentTotal = getCurrentTotalPurchase();
          AdropMetrics.setProperty("total_purchase_amount", currentTotal + purchaseAmount);
      }

      public void onMembershipUpgrade(String newTier) {
          // Update properties on membership upgrade
          AdropMetrics.setProperty("membership_tier", newTier);
      }
  }
  ```
</CodeGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Create Audience Targeting" icon="users" href="/targeting/audience">
    Create audience targeting in console
  </Card>

  <Card title="Create Context Targeting" icon="book" href="/targeting/context">
    Create context targeting in console
  </Card>

  <Card title="Sell Targeting" icon="dollar-sign" href="/targeting/sell">
    Set up targeting category sales
  </Card>

  <Card title="Banner Ads" icon="rectangle-ad" href="/sdk/android/banner">
    Implement banner ads
  </Card>

  <Card title="Native Ads" icon="mobile" href="/sdk/android/native">
    Implement native ads
  </Card>

  <Card title="Reference" icon="code" href="/sdk/android/reference">
    Classes, listeners, error codes
  </Card>
</CardGroup>

***

## FAQ

<AccordionGroup>
  <Accordion title="Will targeted ads not be displayed if UID is not set?">
    Ads will still be displayed even without setting UID, but audience targeting won't be applied. Only basic targeting (country, language, etc.) will be used. Setting UID is essential for sophisticated targeting.
  </Accordion>

  <Accordion title="I set properties but don't see data in the console.">
    Property data is reflected in the console within up to 24 hours after collection. If data is not displayed:

    1. Verify that properties are correctly defined in the console.
    2. Verify that property keys passed from SDK exactly match the console (case-sensitive).
    3. Verify that `AdropMetrics.setProperty()` is called before loading ads.
  </Accordion>

  <Accordion title="What format should Context ID be in?">
    Context ID should be a meaningful string representing the content context. For example:

    * News app: `"article_sports"`, `"article_tech"`, `"article_entertainment"`
    * Shopping app: `"category_fashion"`, `"category_electronics"`
    * Video app: `"video_drama"`, `"video_comedy"`

    Set it to match the context targeting category defined in the console.
  </Accordion>

  <Accordion title="Can I set array type properties?">
    No, array values are not directly supported. `setProperty` accepts String, Int, Double, Long, Boolean, and null values only. To store multiple values, use a JSON string:

    ```kotlin theme={null}
    AdropMetrics.setProperty("favorite_genres", """["drama","action","comedy"]""")
    ```
  </Accordion>

  <Accordion title="How do I delete a property value?">
    Pass `null` to the property value to delete that property:

    ```kotlin theme={null}
    AdropMetrics.setProperty("membership_level", null)
    ```
  </Accordion>
</AccordionGroup>
