Skip to content

Commit b1ff658

Browse files
committed
Merge branch 'master' into migrate-to-typescript
2 parents 8099b18 + 1a1b220 commit b1ff658

1 file changed

Lines changed: 60 additions & 165 deletions

File tree

README.md

Lines changed: 60 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -9,104 +9,77 @@
99
## Table of Contents
1010

1111
- [Installation](#installation)
12-
- [Install Javascript packages](#1-install-javascript-packages)
13-
- [Configure native projects](#2-configure-native-projects)
14-
- [iOS](#21-ios)
15-
- [Android](#22-android)
1612
- [Usage](#usage)
1713
- [Interstitial Ads](#interstitial-ads)
18-
- [1. Showing ad](#1-showing-ad)
1914
- [Native Ads](#native-ads)
20-
- [1. Creating AdsManager](#1-creating-adsmanager)
21-
- [2. Making ad component](#2-making-ad-component)
22-
- [3. Rendering an ad](#3-rendering-an-ad)
2315
- [Banner View](#bannerview)
24-
- [1. Showing ad](#1-showing-ad-1)
2516
- [API](#api)
2617
- [NativeAdsManager](#nativeadsmanager)
27-
- [disableAutoRefresh](#disableautorefresh)
28-
- [setMediaCachePolicy](#setmediacachepolicy)
29-
- [InterstitialAdManager](#interstitialadmanager)
30-
- [showAd](#showad)
31-
- [RewardedVideoAdManager](#rewardedvideoadmanager)
32-
- [loadAd](#loadAd)
33-
- [showAd](#showAd)
3418
- [AdSettings](#adsettings)
35-
- [currentDeviceHash](#currentdevicehash)
36-
- [addTestDevice](#addtestdevice)
37-
- [clearTestDevices](#cleartestdevices)
38-
- [setLogLevel](#setloglevel)
39-
- [setIsChildDirected](#setischilddirected)
40-
- [setMediationService](#setmediationservice)
41-
- [setUrlPrefix](#seturlprefix)
42-
- [Running example](#running-example)
19+
- [Running the example](#running-the-example)
4320
- [Install dependencies](#1-install-dependencies)
4421
- [Start packager](#2-start-packager)
4522
- [Run it on iOS / Android](#3-run-it-on-ios--android)
4623
- [Credits](#credits)
4724

4825
## Installation
4926

50-
### 1. Install Javascript packages
27+
### 1. Integrate the base Facebook SDK
5128

52-
##### RN >= 0.40
29+
Follow the instructions on [react-native-fbsdk](https://github.com/facebook/react-native-fbsdk) to integrate the Facebook SDK into your project.
30+
Note that for iOS, it's [recommended you use Cocoapods](https://developers.facebook.com/docs/ios/getting-started/advanced) rather than the manual installation.
5331

54-
Install JavaScript packages:
32+
### 2. (iOS only) Integrate Facebook Audience Network
5533

56-
```bash
57-
$ react-native install react-native-fbads
58-
```
59-
60-
##### RN < 0.40
34+
1. Add the following Pod to your Podfile:
6135

62-
Install JavaScript packages:
63-
64-
```bash
65-
$ react-native install react-native-fbads@3.1.1
6636
```
67-
68-
#### Upgrading to latest version
69-
37+
pod 'FBAudienceNetwork'
7038
```
71-
react-native unlink react-native-fbads
7239

73-
npm install react-native-fbads@latest --save
40+
2. Run `pod install`
7441

75-
react-native link react-native-fbads
42+
If you didn't use Cocoapods to integrate the Facebook SDK, you'll need to manually add the audience network framework file to your project.
7643

77-
//IOS NOTICE
78-
Use pod to install fbAudience framework
79-
```
44+
### 3. Install The Javascript Package
8045

81-
### 2. Configure native projects
46+
Add the package to your project using your favorite package manager
8247

83-
The react-native-fbads has been automatically linked for you, the next step will be downloading and linking the native Facebook SDK for both platforms.
48+
```bash
49+
$ yarn install react-native-fbads
50+
```
8451

85-
#### 2.1 iOS
52+
Link the native dependencies
8653

87-
Make sure you have the latest Xcode installed. Open the .xcodeproj in Xcode found in the ios subfolder from your project's root directory. Now, follow all the steps in the [Getting Started Guide for Facebook SDK](https://developers.facebook.com/docs/ios/getting-started) for iOS. Along with FBSDKCoreKit.framework, don't forget to import FBAudienceNetwork.framework.
54+
```bash
55+
$ react-native link react-native-fbads
56+
```
8857

89-
Next, **follow steps 1 and 3** from the [Getting Started Guide for Facebook Audience](https://developers.facebook.com/docs/audience-network/getting-started). Once you have created the `placement id`, write it down and continue to next section.
58+
### 4. Get a Placement ID
9059

91-
#### 2.2. Android
60+
Follow [Facebook's instructions](https://www.facebook.com/help/publisher/1195459597167215) to create placement IDs for your ads.
9261

93-
If you are using [`react-native-fbsdk`](https://github.com/facebook/react-native-fbsdk) you can follow their installation instructions. Otherwise, please follow official [Getting Started Guide for Facebook SDK](https://developers.facebook.com/docs/android/getting-started).
62+
You can skip the _Integrate the SDK_ step of that guide, as you've already integrated the Facebook SDK in previous steps.
9463

9564
## Usage
9665

97-
For detailed usage please check `examples` folder.
98-
9966
### Interstitial Ads
10067

101-
Interstitial Ad is a type of an ad that displays full screen with media content. It has a dismiss button as well as the clickable area that takes user outside of your app.
68+
An Interstitial Ad is a an ad that covers the whole screen with media content. It has a dismiss button as well as the clickable area that takes user outside of your app.
10269

10370
<img src="https://cloud.githubusercontent.com/assets/2464966/19014517/3cea1da2-87ef-11e6-9f5a-6f3dbccc18a2.png" height="500">
10471

105-
They are displayed over your root view with a single, imperative call.
72+
Interstitial ads are displayed over your root view with a single, imperative call.
10673

107-
#### 1. Showing ad
74+
On android, you'll need to add the following to your `AndroidManifest.xml`:
10875

109-
In order to show an ad, you have to import `InterstitialAdManager` and call `showAd` on it supplying it a placementId identifier, as in the below example:
76+
```xml
77+
<activity
78+
android:name="com.facebook.ads.InterstitialAdActivity"
79+
android:configChanges="keyboardHidden|orientation" />
80+
```
81+
82+
Usage:
11083

11184
```js
11285
import { InterstitialAdManager } from 'react-native-fbads';
@@ -116,18 +89,15 @@ InterstitialAdManager.showAd(placementId)
11689
.catch(error => {});
11790
```
11891

119-
Method returns a promise that will be rejected when an error occurs during a call (e.g. no fill from ad server or network error) and resolve when user either dimisses or interacts with the displayed ad.
92+
The `showAd` method returns a promise that will be resolves once the ad has been either dismissed or clicked by the user. The promise will reject if an erros occurs before displaying the ad, such as a network error.
12093

12194
### Native Ads
12295

123-
Native Ad is a type of an ad that matches the form and function of your React Native interface.
96+
Native Ads allow you to create custom ad layouts that match your app. Before proceeding, please review [Facebook's documentation on Native Ads](https://developers.facebook.com/docs/audience-network/native-ads/) to get a better understanding of the requirements Native Ads impose.
12497

12598
<img src="https://cloud.githubusercontent.com/assets/2464966/18811079/52c99932-829e-11e6-9a3d-218569d71a6d.png" height="500" />
12699

127-
#### 1. Creating AdsManager
128-
129-
In order to start rendering your custom native ads within your app, you have to construct
130-
a `NativeAdManager` that is responsible for caching and fetching ads as you request them.
100+
#### 1. Create the ads manager
131101

132102
```js
133103
import { NativeAdsManager } from 'react-native-fbads';
@@ -138,17 +108,11 @@ const adsManager = new NativeAdsManager(placementId, numberOfAdsToRequest);
138108
The constructor accepts two parameters:
139109

140110
- `placementId` - which is an unique identifier describing your ad units,
141-
- `numberOfAdsToRequest` - which is a number of ads to request by ads manager at a time
142-
143-
#### 2. Making ad component
111+
- `numberOfAdsToRequest` - which is a number of ads to request by ads manager at a time, defaults to 10.
144112

145-
After creating `adsManager` instance, next step is to wrap an arbitrary component that you want to
146-
use for rendering your custom advertises with a `withNativeAd` wrapper.
113+
#### 2. Create your component
147114

148-
It's a higher order component that passes `nativeAd` via props to a wrapped component allowing
149-
you to actually render an ad!
150-
151-
The `nativeAd` object can contain the following properties:
115+
Your component will have access to the following properties, under the `nativeAd` prop:
152116

153117
- `advertiserName` - The name of the Facebook Page or mobile app that represents the business running each ad.
154118
- `headline` - The headline that the advertiser entered when they created their ad. This is usually the ad's main title.
@@ -160,24 +124,29 @@ The `nativeAd` object can contain the following properties:
160124
- `callToActionText` - Call to action phrase, e.g. - "Install Now"
161125
- `socialContext` - social context for the Ad, for example "Over half a million users"
162126

163-
** Note: ** Don't use more than one MediaView/AdIconView component within one native ad.
127+
In addition, you'll have access to the following components:
128+
129+
- `MediaView` for displaying Media ads
130+
- `AdIconView` for displaying the ad's icon
131+
- `AdChoicesView` for displaying the Facebook AdChoices icon.
132+
- `TriggerableView` for wrapping `Text` so it will respond to user clicks.
164133

165-
** Note: ** To make any text `Triggerable` wrap it in <TriggerableView></TriggerableView> use only <Text /> component
134+
Please ensure you've reviewed Facebook's instructions to get a better understanding of each of these components and how you should use them.
166135

167136
```js
168137
import {
169138
AdIconView,
170139
MediaView,
171140
AdChoicesView,
172-
TriggerableView
141+
TriggerableView,
173142
} from 'react-native-fbads';
174143
class AdComponent extends React.Component {
175144
render() {
176145
return (
177146
<View>
178147
<AdChoicesView style={{ position: 'absolute', left: 0, top: 0 }} />
179-
<AdIconView />
180-
<MediaView />
148+
<AdIconView style={{ width: 50, height: 50 }} />
149+
<MediaView style={{ width: 160, height: 90 }} />
181150
<TriggerableView>
182151
<Text>{this.props.nativeAd.description}</Text>
183152
</TriggerableView>
@@ -191,7 +160,7 @@ export default withNativeAd(AdComponent);
191160

192161
#### 4. Displaying Facebook Ad Choices Icon
193162

194-
Facebook's guidelines require every native ad to include the Ad Choices component, which contains a small clickable icon.
163+
Facebook's guidelines require every native ad to include the Ad Choices view, which contains a small clickable icon.
195164
You can use the included `AdChoicesView` component and style it to your liking.
196165

197166
#### Example usage
@@ -210,18 +179,16 @@ import { AdChoicesView } from 'react-native-fbads'
210179
| expandable | false | false | (iOS only) makes the native AdChoices expandable |
211180
| location | topLeft | false | (iOS only) controls the location of the AdChoices icon |
212181

213-
#### 3. Rendering an ad
182+
#### 3. Showing the ad
214183

215-
Finally, you can render your wrapped component from previous step and pass it `adsManager`
216-
of your choice.
217-
218-
##### Native Ad Props
219-
220-
| prop | default | required | params | description |
221-
| ---------- | ------- | -------- | ---------------------------------------------------------------------------- | --------------------------- |
222-
| adsManager | null | true | `const adsManager = new NativeAdsManager(placementId, numberOfAdsToRequest)` | The ad manager to work with |
184+
Finally, wrap your component with the `withNativeAd` HOC and pass it the `adsManager` you've previously created.
223185

224186
```js
187+
class MyAd {
188+
...
189+
}
190+
export const AdComponent = withNativeAd(MyAd);
191+
225192
class MainApp extends React.Component {
226193
render() {
227194
return (
@@ -235,25 +202,17 @@ class MainApp extends React.Component {
235202

236203
### BannerView
237204

238-
BannerView is a component that allows you to display native banners (know as _AdView_).
205+
BannerView is a component that allows you to display ads in a banner format (know as _AdView_).
239206

240207
Banners are available in 3 sizes:
241208

242209
- `standard` (BANNER_HEIGHT_50)
243210
- `large` (BANNER_HEIGHT_90)
244211
- `rectangle` (RECTANGLE_HEIGHT_250)
245212

246-
#### 1. Showing ad
247-
248-
In order to show an ad, you have to first import it `BannerView` from the package:
249-
250213
```js
251214
import { BannerView } from 'react-native-fbads';
252-
```
253-
254-
Later in your app, you can render it like below:
255215

256-
```js
257216
function ViewWithBanner(props) {
258217
return (
259218
<View>
@@ -292,68 +251,6 @@ adsManager.setMediaCachePolicy('none' | 'icon' | 'image' | 'all');
292251

293252
**Note:** This method is a noop on Android
294253

295-
### InterstitialAdManager
296-
297-
```js
298-
import { InterstitialAdManager } from 'react-native-fbads';
299-
```
300-
301-
InterstitialAdManager is a manager that allows you to display interstitial ads within your app with a single call.
302-
303-
#### showAd
304-
305-
Loads an interstitial ad asynchronously and shows it full screen by attaching a view onto the current root view
306-
controller.
307-
308-
```js
309-
InterstitialAdManager.showAd('placementId')
310-
.then(...)
311-
.catch(...);
312-
```
313-
314-
Promise will be rejected when there's an error loading ads from Facebook Audience network. It will resolve with a
315-
`boolean` indicating whether user didClick an ad or not.
316-
317-
On Android you have to add following activity to _AndroidManifest.xml_
318-
319-
```xml
320-
<activity
321-
android:name="com.facebook.ads.InterstitialAdActivity"
322-
android:configChanges="keyboardHidden|orientation" />
323-
```
324-
325-
**Note:** There can be only one `showAd` call being performed at a time. Otherwise, an error will be thrown.
326-
327-
### RewardedVideoAdManager
328-
329-
```js
330-
import { RewardedVideoAdManager } from 'react-native-fbads';
331-
```
332-
333-
RewardedVideoAdManager is a manager that allows you to load a rewarded video, then show the video once the video is loaded, in that order.
334-
335-
#### loadAd
336-
337-
Loads a rewarded video asynchronously, returns success / true if it loads, error if there wasn't an ad fill or an error from the audience network SDK.
338-
339-
```js
340-
RewardedVideoAdManager.loadAd('placementId')
341-
.then(...) // fill success
342-
.catch(...); // no fill or SDK error
343-
```
344-
345-
#### showAd
346-
347-
Shows a rewarded video immediately, returns success if the video was watched to completion and the user should be rewarded, error if the video wasn't complete or there was an error from the audience network SDK.
348-
349-
```js
350-
RewardedVideoAdManager.showAd()
351-
.then(...) // fully watched video, set your reward.
352-
.catch(...); // error
353-
```
354-
355-
**Note:** You need to be sure to load then show each time you wish to show a rewarded video ad. You also cannot load another video in the success callback of showAd().
356-
357254
### AdSettings
358255

359256
```js
@@ -368,12 +265,10 @@ Constant which contains current device's hash id.
368265

369266
#### addTestDevice
370267

371-
Registers given device to receive test ads. When you run app on simulator, it should automatically get added. Use it
372-
to receive test ads in development mode on a standalone phone. Hash of the current device can be obtained from a
373-
debug log or `AdSettings.currentDeviceHash` constant.
374-
375-
All devices should be specified before any other action takes place, like [`AdsManager`](#nativeadsmanager) gets created.
268+
Registers given device to receive test ads. When running on a real device, call this method with the result of `AdSettings.currentDeviceHash` to get test ads.
269+
Do not call this method in production.
376270

271+
You should register test devices before displaying any ads or creating any ad managers.
377272
```js
378273
AdSettings.addTestDevice('hash');
379274
```
@@ -425,7 +320,7 @@ AdSettings.setUrlPrefix('...');
425320

426321
**Note:** This method should never be used in production
427322

428-
## Running example
323+
## Running the example
429324

430325
In order to see ads you will have to create your own `placementId` and use it instead of the one provided in the examples. This is our internal set up that doesn't work for any developers outside of Callstack.io organisation. This is because of Facebook not showing test ads to outside collaborators in the development mode.
431326

0 commit comments

Comments
 (0)