expo-mopub
v1.0.7
Published
this is mopub sdk react native library compatible with expo
Downloads
9
Maintainers
Readme
expo-mopub
Getting started
$ yarn add expo-mopub
Mostly automatic installation
$ react-native link expo-mopub
MoPub Integration
iOS
- Open terminal and navigate to project iOS directory and run command.
pod init
- It will create Podfile in your project, open it and paste the following lines below
`target 'PROJECT_NAME' do`.
pod 'React', :path => '../node_modules/react-native', :subspecs => [
'Core',
'CxxBridge', # Include this for RN >= 0.47
'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
'RCTText',
'RCTNetwork',
'RCTWebSocket', # Needed for debugging
'RCTAnimation', # Needed for FlatList and animations running on native UI thread
# Add any other subspecs you want to use in your project
]
# Explicitly include Yoga if you are using RN >= 0.42.0
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
# Third party deps podspec link
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'expo-mopub', path: '../node_modules/expo-mopub'
end
- Then run the following command in termainal in the same location
pod install
Android
- Add following permissions to your android AndroidManifest.xml.
<!-- Required permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Optional permissions. Will pass Lat/Lon values when available. Choose either Coarse or Fine -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- Declare the following activities in your AndroidManifest.xml.
<!-- MoPub's consent dialog -->
<activity android:name="com.mopub.common.privacy.ConsentDialogActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<!-- All ad formats -->
<activity android:name="com.mopub.common.MoPubBrowser" android:configChanges="keyboardHidden|orientation|screenSize"/>
<!-- Interstitials -->
<activity android:name="com.mopub.mobileads.MoPubActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<!-- Rewarded Video and Rewarded Playables -->
<activity android:name="com.mopub.mobileads.RewardedMraidActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<activity android:name="com.mopub.mobileads.MraidVideoPlayerActivity" android:configChanges="keyboardHidden|orientation|screenSize"/>
<meta-data android:name="com.google.android.gms.version"
android:value="15.0.90" />
- Add following lines to build.gradle
allprojects
➜repositories
maven { url "https://s3.amazonaws.com/moat-sdk-builds" }
maven { url 'https://adcolony.bintray.com/AdColony' }
maven { url 'https://tapjoy.bintray.com/maven' }
maven { url 'https://jitpack.io' }
Usage
Interstitial
import {RNMoPubInterstitial} from 'expo-mopub';
Interstitial Methods
| Mehod | Description | | --- | --- | | initializeInterstitialAd (adUnitId: string) | Initialize Interstitial ad for the the given ad unit. | | loadAd () | Loads ad for the unit provided through initialization. | | setKeywords (keywords: string) | Set keyword for the ad. | | isReady () | Return a promise to check whether Interstitial is ready. | | show () | Shows Interstitial if loaded. | | addEventListener (eventType: string, listener: Function) |Adds listener to the events from Interstitial ad, possible event names are "onLoaded" "onFailed", "onClicked", "onShown" and "onDismissed".| |removeAllListeners (eventType: string)|Remove listeners for added for events from Interstitial ad.|
Banner Ad
import {MoPubBanner} from 'expo-mopub';
Banner Props
| Prop |Type| Description | | --- | --- | --- | |adUnitId| String |Banner ad unit id for which you want to show banner ad.| |autoRefresh| Bool | Toggle auto-refresh enable or disable.| |keywords| String |Pass the keywords from your app to MoPub as a comma-separated list in the ad view. Each keyword should be formatted as a key/value pair (e.g. m_age:24). Any characters can be used except & and =.| |onLoaded|Function|Calls when the banner has successfully retrieved an ad.| |onFailed|Function|Calls when the banner has failed to retrieve an ad. You can get error message from the event object.| |onClicked|Function|Calls when the user has tapped on the banner.| |onExpanded|Function|Calls when the banner has just taken over the screen.| |onCollapsed|Function|Calls when an expanded banner has collapsed back to its original size.|