Giter Site home page Giter Site logo

abendemar / react-native-mopub-sdk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from senolatac/react-native-mopub-sdk

0.0 0.0 0.0 803 KB

React native library for mopub ad network

License: MIT License

Java 44.00% JavaScript 16.03% Ruby 2.98% Objective-C 29.42% Starlark 2.20% TypeScript 5.37%

react-native-mopub-sdk's Introduction

react-native-mopub-sdk

Getting started

yarn add https://github.com/amsdamsgram/React-Native-Mopub-SDK.git

iOS

    cd ios/ && pod install

Android

  1. Add following permissions to your android AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  1. 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"/>
  1. Add a network config security file

  2. Add the following lines to android/build.gradle

allprojects {
    repositories {
        // other stuff here
        maven { url "https://maven.google.com" }
        maven { url "https://s3.amazonaws.com/moat-sdk-builds" }

Usage

import { AdLidSDK, RNMoPubInterstitial } from 'react-native-mopub-sdk';

function initializeAds(onInitialized: () => {}) {
    AdLibSDK.addEventListener("onSDKInitialized", () => {
        AdLibSDK.removeAllListeners("onSDKInitialized");

        // Initialize ad once Mopub SDK has been initialized
        RNMoPubInterstitial.initializeInterstitialAd(
            INTERSTITIAL_UNIT_ID
        );

        // Do other stuff like show an ad after initialization
        onInitialized();
    });
    
    AdLibSDK.init(INTERSTITIAL_UNIT_ID);
}

Interstitial

import { RNMoPubInterstitial } from 'react-native-mopub-sdk';

Interstitial Methods

Mehod Description
initializeInterstitialAd (adUnitId: string) Initialize Interstitial ad for the the given ad unit.
loadAd () Load ad for the unit provided through initialization.
isReady () Return a promise to check whether Interstitial is ready.
show () Show Interstitial if loaded.
addEventListener (eventType: string, listener: Function) Add listener to the events from Interstitial ad, possible event names are "onLoaded" "onFailed", "onClicked", "onShown", "onDismissed" and "onTrackImpressionData".
removeAllListeners (eventType: string) Remove listeners for added events from Interstitial ad.

Banner Ad

import { MoPubBanner } from 'react-native-mopub-sdk';

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.

react-native-mopub-sdk's People

Contributors

senolatac avatar amsdamsgram avatar abendemar avatar aliasad106 avatar dependabot[bot] avatar hari avatar jenniferlim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.