React Native SDK
Welcome to the guide on integrating AdsPostX into your React Native application. This comprehensive documentation is designed to assist developers in seamlessly incorporating AdsPostX Offers into their React native apps. Whether you're looking to monetize your app or enhance user engagement, AdsPostX provides a powerful solution.
Before getting started, please ensure that you already have an account with AdsPostX. If you don't have an account yet, you can easily create a new one now. Once you have your account credentials, you can proceed with the integration process outlined in this guide.
Let's dive in and explore the features and functionalities of the rnadspostx package to unlock the full potential of AdsPostX within your React Native application.
Before you begin the integration process, make sure you have the following requirements in place:
- React Native Environment Setup: Ensure that you have set up the general React Native environment on your development machine. This includes Node.js, npm/yarn, and the React Native CLI. Refer to the React Native documentation for detailed instructions on setting up the development environment.
- iOS Build Support Tools: If you plan to target iOS devices, you will need to install Xcode and the necessary build support tools. Xcode is available for download from the Mac App Store. Install Xcode and follow the installation instructions to set up the necessary development tools.
- Android Build Support Tools: If you intend to target Android devices, you will need to install Android Studio and the required build support tools. Android Studio provides a comprehensive development environment for building Android apps. Download and install Android Studio, following the installation guide provided by Google.
- Cocoapods (iOS only): Cocoapods is a dependency manager for iOS projects. If you are targeting iOS devices, you will need to have Cocoapods installed. Cocoapods simplifies the process of integrating third-party libraries into your iOS project. Install Cocoapods by running the following command in your terminal:
Ensure that your target platforms meet the minimum deployment target requirements:
The minimum deployment target for iOS is iOS 13 or later.
- Open your client app iOS project-workspace (*.xcworkspace) in XCODE.
- Select your project at PROJECT level. On the Right side, Under info section, you will find Deployment Target Section. Under it, you will find iOS Deployment Target, make sure it is ≥ 13.0
-
- Select your project at TARGETS level. Under General → Minimum Deployments make sure the value for iOS is ≥ 13.0
-
- Open a Pod file, If you are using a global platform, check to make sure platform :ios, '13.0’. (OR any value above 13.0 will work) has been updated.
The minimum SDK version for Android is 24 (Android 7.0 Nougat) or later.
- Set minSdkVersion to 24 in app-level build.gradle. (Note: if you are referring to root/project level value for eg. rootProject.ext.minSdkVersion inside app-level build.gradle for minSdkVersion then set minSdkVersion to 24 in project-level build.gradle.)
Having these requirements in place will allow you to proceed with the integration of the rnadspostx package smoothly.
version |
0.1.31 |
To integrate the rnadspostx package into your React Native project, follow these steps:
- Open Terminal and navigate to the root folder of your React Native project.
- Run the following command to install the rnadspostx package:
3. Wait for the installation process to complete. This may take a few moments, depending on your internet connection and the size of the package.
- Open terminal, Go to <your react native app>/ios. / Do pod install OR pod update
- Check the value of android:allowBackup in android/app/src/main/AndroidManifest.xml
- If it is false then you need to make changes as below:
- add xmlns:tools="http://schemas.android.com/tools" to manifest as an XML namespace.
- add tools:replace="android:allowBackup” at <application> level and also add/update android:allowBackup= “true (OR false)” (depending upon your requirement).
- If it is true or not present then no changes are required.
- Perform gradle sync.
There are two ways to integrate AdsPostX into your React Native app.
Native Ads API Native Ads API provides a highly flexible implementation method. With Native Ads API, you can retrieve Offers in a JSON response and then parse and display them according to your specific requirements. The JSON response contains individual fragments that make up an Offer, giving you full control over how the Offer is rendered. This method allows for deep customization and styling to seamlessly blend the Offers into your app's UI.
Standard Integration If you prefer a quick and straightforward way to display AdsPostX Offers without the need for extensive customization, the Standard integration is a suitable option. It offers a pre-built modal box that can be easily integrated into your React Native app. While it may not provide the same level of customization as Native Ads, the Standard integration does allow basic theming options that can be controlled through the AdsPostX dashboard. This option is ideal for those who prioritize simplicity and quick implementation.
Once you've installed the rnadspostx package using the step(s) above, you can simply use the getOffers call to retrieve Offers. You will need your SDK ID in order to do so.
Import AdsPostXPlugin in your RN project:
Here is an example of a fully-formed call using the getOffers method:
where
Parameter Name | Parameter Type | Optional/Required | Description |
sdkId | string | required | SDK ID as provided |
payload | JSON object | optional | User payload parameters and other filters/options |
It returns a promise with status and response details.
Name | Data Type | Description |
status | boolean | indicates if the getOffers call was successful or not. |
response | JSON object | If promise resolve then status will be true, response will give details about the Offers. If promiserejects then status will be false, response will give details about the error. |
The getOffers method is effectively a wrapper around the AdsPostX Native Ads API which you can learn more about here. The payload and options values can be passed through and used interchangeably with the Native Ads API.
In the example above, the payload parameter is passing user payload information including country and firstname. The payload parameter also includes a creatives: 1 option to instruct AdsPostX to only return Offers that have at least one creative.
The getOffers response object will contain Offers if Offers are available and can then be parsed to display them using the Offers fragments provided.
To accurately report events such as impressions, opt-outs, etc, each Offer contains beacon URL to fire based on the nature of the event. For impressions, use the pixel attribute. For other events, refer to the beacons attribute to handle. For example, if the user presses "No thanks" on the offer, fire the no_thanks_click beacon URL.
Success
A successful call to getOffers would return a JSON object containing status and response as follows:
Failure
A failed call to getOffers would return a JSON response similar to the following:
Integrating AdsPostX in your app consists of three steps.
- Initializing SDK
- Loading Offers
- Displaying Offers
Include the rnadspostx initialization code anywhere in the app but make sure to call it before loading & showing offers.
Also, make sure to import { AdsPostXPlugin } from 'rnadspostx'
where
Parameter Name | Parameter Type | Required/Optional | Description |
sdkId | string | required | SDK ID as provided |
response | callback object | required | indicates if the init call was successful or not; if not, error information will be returned |
Once the SDK is initialized successfully, call the load function to load Offers.
The load function must be called at least once before showing Offers.
Load Offers with payload
Load Offers without payload
where
Parameter Name | Parameter Type | Required/Optional | Description |
response | callback parameter | required | gives an indication that the offers are loaded successfully or not. If a response is 'true', this mean offers are loaded successfully and ready to be displayed. Otherwise, you will get an error with 'error' field in the response. |
payload | JS Object | optional | payload and their values you want to send to AdsPostX in the payload. Supports adhoc key-value pairs. |
Currently, the following payload values are supported:
Name | Data Type |
string | |
firstname | string |
lastname | string |
mobile | string |
confirmationref | string |
amount | string |
currency | string |
paymentType | string |
ccbin | string |
language | string |
country | string |
zipcode | string |
orderid | string |
offerid | string |
subid | string |
Once init and load calls are successful, call show to display offers in your app.
where
Parameter Name | Parameter Type | required/optional | Description |
position | object | required | contains topMargin, rightMargin, bottomMargin, leftMarin as members. topMargin: Describes top margin in %. Must be >=0 and <=15. rightMargin: Describes right side margin in %. Must be >=0 and <=15. bottomMargin: Describes bottom margin in %. Must be >=0 and <=15. leftMargin: Describes left side margin in %. Must be >=0 and <=15. |
styles | object | required | contains transparent and type. transparent: set it to true if you want to set the offer background transparent. type: can be popupor fullscreen |
callbacks | object | required | contains showCallback, errorCallback and dismissCallback. |
errorCallback | should be part of callbacks | required | Callback that runs when there is an error. Provides a error info. |
showCallback | should be part of callbacks | required | Callback to run each time an offer is displayed |
dismissCallback | should be part of callbacks | required | Callback to run each time an offer is dismissed |
Margins will be calculated based on orientation. If in landscape orientation, margin will be calculated considering the device height. If in portrait orientation, margin will be calculated considering the device width.
If margin value is > 15 then it will consider only 15.
After displaying offers, the load function must be called again before displaying offers again.
The default value for Environment is 0(live environment).
We recommend using test environment only in development, not in production.
Make sure to call this method before init() call.
By default, Debug Log is disabled.
Enabling Debug Log will give you more debug information related to offers.
We recommend enabling logs only in development - not in production.
Make sure to call this method before the init() call.
Also, add the following code to the client application's 'AppDelegate' method supportedInterfaceOrientationsFor window
Open & Navigate to <react-native-client-app> /ios /<project_name> /AppDelegate.mm
#import <AdsPostX/AdsPostX-Swift.h> in AppDelegate.mm
add the following code.
where
Value | description |
UIInterfaceOrientationMaskAll | if the client app supports all orientations. |
UIInterfaceOrientationMaskPortrait | if the client app supports only portrait orientation. |
UIInterfaceOrientationMaskLandscape | if the client app supports only landscape orientation. |
UIInterfaceOrientationMaskAllButUpsideDown | if client app supports all orientations except UpsideDown. |
1) When pod install / pod update if you are getting the below error:
Ans:
In React Native client app -> ios -> Pod file, change to platform :ios, 13. Also make sure xcode project deployment target is >= iOS13.
2) If you are getting the below error in Android version:
Ans:
Set minSdkVersion = 23 in gradle file.
3) If you are getting the below error in Android version:
Ans:
To fix this error, you need to add the tools namespace declaration to your AndroidManifest.xml file. Here's an example:
Make sure to add the xmlns:tools="http://schemas.android.com/tools" declaration to the root manifest element. Once you've added the declaration, the "Namespace 'tools' is not bound" error should go away.
4) If you are getting the below error in the Android version.
Ans:
Add tools:replace="android:allowBackup" in androidmanifest.xml.
If you're running into any issues while going through the integration process, feel free to contact us at help@adspostx.com.