Skip to main content

Overview

This document provides practical examples of the Adrop React Native SDK. All examples are written in TypeScript and can be used directly in actual projects.

Sample Project

View the complete sample project on GitHub.

React Native Sample Project

React Native sample app written in TypeScript

A complete example of manually loading banner ads using refs and handling errors.

Key Features

  • Manual Load: Set autoLoad={false} and load ads at desired timing via ref
  • Error Handling: Manage error state with onAdFailedToReceive callback
  • Multiple Banners: Manage multiple banners independently
  • Platform Support: Set platform-specific unit IDs using Platform.OS

Native Ad Example

An example of using native ads with WebView and handling backfill ads.

Key Features

  • Profile Information Display: Show advertiser information using AdropProfileLogoView and AdropProfileNameView
  • WebView Integration: Render HTML creatives with WebView
  • Backfill Handling: Handle backfill ads using isBackfilled property
  • URL Handling: Process WebView navigation events to open external links
  • Memory Management: Clean up ad objects with destroy() method

Interstitial Ad Example

An example of implementing interstitial ads using Hooks.

Key Features

  • Hook Usage: Easy state management with useAdropInterstitialAd Hook
  • State Tracking: Track ad state using isLoaded, isOpened, isReady states
  • Error Handling: Check error state with errorCode
  • Initialization: Initialize ads with reset() method
Since interstitial ads cover the entire screen, it’s important to display them at appropriate times considering user experience.

Rewarded Ad Example

An example of implementing rewarded ads using Hooks.

Key Features

  • Hook Usage: Easy state management with useAdropRewardedAd Hook
  • Reward Handling: Check reward timing via listener (see Rewarded Ad Guide for listener setup)
  • State Management: Check ad state with isLoaded, isOpened, isReady
Rewarded ads require users to watch the entire ad to receive rewards. Only grant rewards in the onAdEarnRewardHandler callback.

An example of implementing and customizing popup ads using classes.

Key Features

  • Class-based: Direct use of AdropPopupAd class
  • Color Customization: Set popup style with AdropPopupAdColors
  • Close on Click: Call ad.close() in onAdClicked
  • Memory Management: Call destroy() in useEffect cleanup

Targeting Configuration Example

An example of setting ad targeting.

Available Targeting Properties

Targeting properties are sent to the server during ad requests to display more relevant ads.

Error Handling Utility

A utility example that converts error codes into human-readable messages.

Error Code List


Full Integration Example

An example of using all ad formats in a single app.

Best Practices

1. Memory Management

Always clean up ad objects after use.

2. Error Handling

Implement error handling for all ad loads.

3. State Management

Track ad state using Hooks.

4. Platform Branching

Use different unit IDs for each platform.

5. Use Test Unit IDs

Always use test unit IDs during development and testing.

Next Steps

API Reference

Check the complete API documentation

Banner Ads

Detailed banner ad guide

Native Ads

Detailed native ad guide

Interstitial Ads

Detailed interstitial ad guide