7.0.4 • Published 3 years ago

@wowmaking/react-native-iron-source v7.0.4

Weekly downloads
106
License
MIT
Repository
github
Last release
3 years ago

@wowmaking/react-native-iron-source

Iron Source SDK React Native bridge. Supports all ad units (Rewarded Video, Interstitial, Banner, Offerwall).

Many thanks to all contributors of squaretwo/react-native-iron-source.

The fork includes following improvements:

  • Banner implementation
  • Bug fixes for Offerwall, Interstitial, Rewarded
  • Documentation
  • Installation using CocoaPods
  • Easier installation on android
  • Validate integration option
  • IronSource.setConsent method
  • Working Example App
  • etc

Compatibility table

@wowmaking/react-native-iron-sourceXcodeIronSourceSDK
7.0.0<= 11<= 7.0.1
>= 7.0.3>= 12>= 7.0.3

Getting started

npm install @wowmaking/react-native-iron-source --save

You can find available versions here.

RN >= 0.60

iOS

Add SKAdNetworkIdentifier to your Info.plist

<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>SU67R6K2V3.skadnetwork</string>
    </dict>
</array>

Android

Add a repo to your android/app/build.gradle file

allprojects {
    repositories {
        // Existing repos here
        // ...
        
        maven { url "https://dl.bintray.com/ironsource-mobile/android-sdk" }
    }
}

Mostly automatic installation

$ react-native link @wowmaking/react-native-iron-source

Manual installation

iOS
  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modules@wowmaking/react-native-iron-source and add RNIronSource.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNIronSource.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)

    iOS CocoaPods
  5. Add pod 'RNIronSource', :path => '../node_modules/@wowmaking/react-native-iron-source' to your ios/Podfile

  6. Run pod install while in ios directory

    Allow iOS Static Frameworks

    If you are using Static Frameworks on iOS, you need to manually enable this for the project. To enable Static Framework support, add the following global to the top of your /ios/Podfile file: $RNIronSourceAsStaticFramework = true

    Android
  7. Open up android/app/src/main/java/[...]/MainApplication.java

    • Add import com.reactlibrary.RNIronSourcePackage; to the imports at the top of the file
    • Add new RNIronSourcePackage() to the list returned by the getPackages() method
  8. Append the following lines to android/settings.gradle:
    	```
    	include ':@wowmaking_react-native-iron-source'
    	project(':@wowmaking_react-native-iron-source').projectDir = new File(rootProject.projectDir, 	'../node_modules/@wowmaking/react-native-iron-source/android')
    	```
  9. Insert the following lines inside the dependencies block in android/app/build.gradle:

     implementation project(':@wowmaking_react-native-iron-source')
    	```
    
    ### Manual Setup
    
    #### IronSource iOS SDK
    
    ##### For projects with CocoaPods
    
    Do nothing.
    
    ##### For other projects
  10. Download the iOS SDK from Ironsrc.com

  11. Unzip and rename the directory to IronSourceSDK
  12. Copy the SDK to ~/Documents/IronSourceSDK
  13. Drag the IronSource.framework to your react native target build phases from the ~/Documents/IronSourceSDK directory
  14. Add ~/Documents/IronSourceSDK to your target's Framework Search Paths in Build Settings

    Android

    Add a repo to your app/build.gradle file
    repositories {
        maven { url "https://dl.bintray.com/ironsource-mobile/android-sdk" }
    }

Mediation Setup

WARNING! Make sure you following the doc carefully. If you miss something in the mediation setup process for some network it may not work partially or entirely. Follow guide for each mediation. Add your devices and simulators to test device list in ironsource admin panel.

Official doc:

pod 'RNIronSource', :path => '../node_modules/@wowmaking/react-native-iron-source', :subspecs => [
    'Core', # required
    'AdColony',
    'Admob',
    'Amazon',
    'AppLovin',
    'Chartboost',
    'Facebook',
    'HyprMX',
    'InMobi',
    'Maio',
    'MediaBrix',
    'Tapjoy',
    'UnityAds',
    'Vungle'
]

Usage

You can use example app as a reference.

There is also an older example app for RN <= 0.59.x in this branch.

Initialization

// After user granted consent

IronSource.setConsent(true);

</details> 

2. Initialize IronSource SDK

```javascript
import { IronSource } from '@wowmaking/react-native-iron-source';

IronSource.initializeIronSource('8a19a09d', 'userId', {
 validateIntegration: true,
}).then(() => {
 console.warn('Init finished');
});

Interstitial

import { IronSourceInterstitials } from '@wowmaking/react-native-iron-source';

IronSourceInterstitials.loadInterstitial();
IronSourceInterstitials.addEventListener('interstitialDidLoad', () => {
  IronSourceInterstitials.showInterstitial();
});

Rewarded Video

import { IronSourceRewardedVideo } from '@wowmaking/react-native-iron-source';


IronSourceRewardedVideo.initializeRewardedVideo();
IronSourceRewardedVideo.addEventListener('ironSourceRewardedVideoAdRewarded', res => {
  console.warn('Rewarded!', res)
});

// or use IronSourceRewardedVideo.addEventListener('ironSourceRewardedVideoAvailable') 
// to get video status
IronSourceRewardedVideo.isRewardedVideoAvailable().then((available) => {
  if (available) {
    IronSourceRewardedVideo.showRewardedVideo();
  } else {
    throw new Error('No video available');
  }
})

Banner

import { IronSourceBanner } from '@wowmaking/react-native-iron-source';

IronSourceBanner.loadBanner('LARGE');
IronSourceBanner.addEventListener('ironSourceBannerDidLoad', () => {
  console.warn('Iron Source banner loaded');
  IronSourceBanner.showBanner();
});

Offerwall

import { IronSourceOfferwall } from '@wowmaking/react-native-iron-source';

IronSourceOfferwall.showOfferwall();
IronSourceOfferwall.addEventListener('ironSourceOfferwallReceivedCredits', res => {
  console.warn('Got credits', res)
});

API (Incomplete)

IronSource.initializeIronSource(ironSourceAppKey, userId, options)

Initializes IronSource SDK.

validateIntegration provides an easy way to verify that you’ve successfully integrated the ironSource SDK and any additional adapters; it also makes sure all required dependencies and frameworks were added for the various mediated ad networks. It doesn't validate Amazon adapter in current version. See official docs for Android, iOS. There's known issue in ios 12. See known issue section.

Parameter(s)

  • ironSourceAppKey: String. Can be found in Iron Source administrator's interface
  • userId: String. Any unique user id.
  • options: Object (optional)
    • validateIntegration: Boolean. Default: false

Returns Promise

IronSource.initializeIronSource('8a19a09d', 'userId', {
  validateIntegration: true
})
  .then(() => {
    console.warn('Init finished');
  });

IronSourceBanner.loadBanner(options)

Loads IronSource banner. Returns a promise that will be resolved when banner loads successfully and rejected when it fails.

Parameter(s)

  • size: String. Supported values: "BANNER", "LARGE", "RECTANGLE", "SMART"
  • options: Object (optional)
    • position: String. Supported values: "top" or "bottom". Default: "bottom".
    • scaleToFitWidth: Boolean. Default: false

Returns Promise of

  • response: Object
    • width: Number
    • height: Number
IronSourceBanner.loadBanner('BANNER', {
  position: 'top',
  scaleToFitWidth: true,
})
  .then(response => {
    console.warn(`width: ${response.width}, height: ${response.height}`);
  })
  .catch(err => {
    console.warn(err.message);
  });

IronSourceBanner.hideBanner()

IronSourceBanner.hideBanner();

IronSourceSegment constructor

Creates a segment manager

import { IronSourceSegment } from '@wowmaking/react-native-iron-source';

const segment = new IronSourceSegment();

IronSourceSegment.setCustomValue

Sets custom user property

segment.setCustomValue('VALUE').forKey('KEY');

IronSourceSegment.setSegmentName

Sets custom segment name

segment.setSegmentName('NAME');

IronSourceSegment.activate

Makes currently existing segment active. Once it's active IronSource SDK will use it to serve your ad units based on segments to tailor the user’s ad experience.

segment.activate();

IronSourceRewardedVideo.isRewardedVideoAvailable

Check if a reward video is available to be shown. Return a Promise resolving a boolean.

IronSourceRewardedVideo.isRewardedVideoAvailable().then((available) => {
  if (available) {
    // Video available
  } else {
    // Video not available
  }
});

Events

Banner events

NameDescription
ironSourceBannerDidLoadCalled after a banner ad has been successfully loaded
ironSourceBannerDidFailToLoadWithErrorCalled after a banner has attempted to load an ad but failed
ironSourceBannerDidDismissScreenCalled after a full screen content has been dismissed
ironSourceBannerWillLeaveApplicationCalled when a user would be taken out of the application context
ironSourceBannerWillPresentScreenCalled when a banner is about to present a full screen content
ironSourceDidClickBannerCalled after a banner has been clicked

Rewarded video events

NameDescription
ironSourceRewardedVideoAvailableCalled after a rewarded video has changed its availability to YES. It means that now you can show the ad
ironSourceRewardedVideoUnavailableCalled after a rewarded video has changed its availability to NO
ironSourceRewardedVideoClosedByUserCalled after a rewarded video has been dismissed
ironSourceRewardedVideoDidStartCalled after a rewarded video has started playing. Note: this event is not available for all supported rewarded video ad networks. Check which events are available per ad network you choose
ironSourceRewardedVideoClosedByErrorCalled after a rewarded video has attempted to show but failed
ironSourceRewardedVideoDidOpenCalled after a rewarded video has been opened
ironSourceRewardedVideoAdStartedCalled after a rewarded video has been opened
ironSourceRewardedVideoAdEndedCalled after a rewarded video has finished playing. Note: this event is not available for all supported rewarded video ad networks. Check which events are available per ad network you choose
ironSourceRewardedVideoAdRewardedInvoked when the user completed the video and should be rewarded

Interstitial events

NameDescription
interstitialDidLoadInvoked when Interstitial Ad is ready to be shown after load function was called
interstitialDidShowCalled each time the Interstitial window has opened successfully
interstitialDidFailToShowWithErrorCalled if showing the Interstitial for the user has failed
didClickInterstitialCalled each time the end user has clicked on the Interstitial ad
interstitialDidCloseCalled each time the Interstitial window is about to close
interstitialDidOpenCalled each time the Interstitial window is about to open
interstitialDidFailToLoadWithErrorInvoked when there is no Interstitial Ad available after calling load function

Offerwall events

NameDescription
ironSourceOfferwallAvailableInvoked when there is a change in the Offerwall availability status to YES
ironSourceOfferwallUnavailableInvoked when there is a change in the Offerwall availability status to NO
ironSourceOfferwallDidShowCalled each time the Offerwall successfully loads for the user
ironSourceOfferwallClosedByUserCalled when the user closes the Offerwall
ironSourceOfferwallClosedByErrorCalled each time the Offerwall fails to show
ironSourceOfferwallReceivedCreditsCalled each time the user completes an offer
ironSourceOfferwallFailedToReceiveCreditsByErrorCalled when failed to retrieve the users credit balance info

You can find out more about events in the official doc. Start here if you wish.

Known issues

Ads may stop loading properly when "Reload" option (or CMD+R) in your React Native app was used. You have to restart the app completely if you want to check that ads load and display correctly.


7.0.4

3 years ago

7.0.3

3 years ago

7.0.0-alpha.0

4 years ago

7.0.0

4 years ago

3.3.6

4 years ago

3.3.5

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

4 years ago

3.3.1

4 years ago

3.2.5

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.7

5 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.0

5 years ago

2.8.5

5 years ago

2.8.4

5 years ago

2.8.3

5 years ago

2.8.2

5 years ago

2.8.1

5 years ago

2.8.0

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.0

5 years ago

2.5.3

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago