Implementation Methods
Native ads allow you to display ads with custom UI that matches your app’s design.Use the test unit ID in development:
PUBLIC_TEST_UNIT_ID_NATIVEDefault Template
You can use the default template in the same way as banner ads. Images and text are automatically rendered in the SDK-provided template.The default template does not support advertiser profile sections. Use custom UI to display advertiser profiles.
Custom UI
Data Attributes Method
Add thedata-adrop-render="custom" attribute and bind fields using data-adrop-native attributes on inner elements.
Data Attributes
string
required
Unit ID created in Ad Control Console
string
required
Set to
custom for custom UIstring
Context ID for contextual targeting
string
default:"light"
Theme setting (
light or dark)boolean
default:false
Enable entire area click
false: Only text/images are clickable, clicking advertiser profile goes to profile linktrue: Entire container is clickable, all clicks go to ad destination
boolean
default:false
Enable custom click handling - When
true, SDK will not automatically navigate to the destination URL on click, only emit adClicked event. Allows developers to implement custom click behavior.string
Advertising identifier — required for the View on Device feature to preview a draft creative on a registered test device. Do not hard-code in production.
renderAd Method
Use this when you want direct control over ad loading timing.renderAd Options
string
required
Unit ID created in Ad Control Console
string
User identifier (used to override SDK-level setting for individual placements)
string
Context ID for contextual targeting
number
required
Set to
1 for custom UIboolean
default:false
Enable entire area click
string
default:"light"
Theme setting (
light or dark)boolean
default:false
Enable custom click handling - When
true, SDK will not automatically navigate to the destination URL on click, only emit adClicked event with destination URL. Allows developers to implement custom click behavior.string
Advertising identifier — required for the View on Device feature to preview a draft creative on a registered test device. Do not hard-code in production.
Field Binding
Bind ad data to UI elements using thedata-adrop-native attribute.
extra.{key} is the ID of extra text items set in Ad Control Console. It may be empty if not set as required.extraAssets.{id} is the media ID of a multi-media unit (e.g., m2). This binding only shows images. If the unit accepts videos, display media items as described in Multi-Media Creatives. (SDK 1.4.0+)To display advertiser profile (
profile.displayLogo, profile.displayName), you must enable Show Advertiser Profile for that ad unit in Ad Control Console.Ad Size
Custom UI size can be set freely.Backfill ads request creatives matching the container size. Specify an appropriate size.
Fetching Data Only with requestAd
If you want complete control over the UI, you can fetch only the ad data usingrequestAd.
AdropAdResponse
Return value ofrequestAd().
AdData
Ad data object. Event handlers also receive the same structure. See Reference > AdData for the complete interface definition.Event Handling
Supported Events
Custom Click Handling
WhenuseCustomClick is enabled, the SDK will not automatically navigate to the destination URL. Instead, you can handle the click event and implement custom behavior.
With custom click handling enabled, you have full control over what happens when users click the ad. The
destinationURL is provided in the adClicked event data.Multi-Media Creatives
Requires
@adrop/ads-web-sdk 1.4.0 or later.extraAssets holds every media item of the ad, keyed by the media ID set in the console. Media 1 is always m1, and the other media items use the IDs shown in Media Size on the Ad Unit detail screen, such as m2 and m3. It’s included in the ad data of SDK events such as AD_RECEIVED, and in requestAd() and requestAds() results.
- Media 1 (
m1) is the ad’s main media (assetorad). Keep displaying it as before, and draw only the other media items yourself. extraAssetsisn’t included for creatives of units with a single media item or for backfill ads.- Look up media items by ID instead of relying on their order.
- If the ad is served in dark mode, image media items are dark mode images too.
- To check your layout with a multi-media creative, preview the creative on a test device.
AdropNativeAsset
Displaying Media Items
This section uses custom UI (trackMode: 1).
- Image: Set
isEntireClick: trueso that a click on an image you add counts as an ad click. Show images withasset: withtrackMode: 1, theadHTML of an image doesn’t report clicks to Adrop. - Video: Play the
adHTML in an<iframe>, not theassetURL. The HTML contains the video player and its tracking, so video metrics are measured only through it. Clicks inside an<iframe>don’t reach the ad container, so a tap on the video is handled only by its HTML. Don’t set thesandboxattribute on the<iframe>: the HTML needs to run scripts and open the landing page. - Landing page: When a user taps the video, its HTML reports the click and opens the landing page.
Impressions and Clicks
Impressions, clicks, and video metrics are counted once per ad, not per media item, even when both the SDK and a media item report them.Which taps on a video count as clicks depends on the unit’s video controller setting. With the controller off, every tap on the video is a click. With it on, taps on the play and mute controls aren’t clicks.
Example
This example shows Media 2 (m2) as an image or a video inside the ad container. Replace m2 with the ID of your unit’s media item.
Size the
<iframe> to the media item’s size set on the unit. The example uses a 16:9 media item.