Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ad Choices Icon Changes #95

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 8 additions & 150 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,160 +1,18 @@
# Cordova Plugin for Facebook AudienceNetwork #

# Quick Demo
This is the BisManOnline forked version of this plugin.

```bash
# install cordova CLI
[sudo] npm install -g cordova
Please see: https://github.com/floatinghotpot/cordova-plugin-facebookads/blob/master/README.md for the full readme

# install a small utility to run all the commands for you
[sudo] npm install -g plugin-verify

# Demo 1: run admob demo with sample index.html
plugin-verify cordova-plugin-facebookads
```
# Fork Details
We implemented the suggested changes in order to get the AdChoices icon working.

## How to use? ##
The Android code comes from:

If use with Cordova CLI:
```
cordova plugin add cordova-plugin-facebookads
```
https://github.com/floatinghotpot/cordova-plugin-facebookads/issues/81#issuecomment-335093936

If use with Intel XDK:
Project -> CORDOVA 3.X HYBRID MOBILE APP SETTINGS -> PLUGINS AND PERMISSIONS -> Third-Party Plugins ->
Add a Third-Party Plugin -> Get Plugin from the Web, input:
```
Name: FacebookAdsPluginPro
Plugin ID: com.rjfun.cordova.facebookads
[x] Plugin is located in the Apache Cordova Plugins Registry
```
The IOS code comes from: (Note: Ours differs from his exact post)

## Quick Start Example Code ##

Step 1: Prepare your Facebook Audience Network Placement Id for your app, create it in [Facebook Developers website](https://developers.facebook.com/)

```javascript
var ad_units = {
ios : {
banner:"your_ad_place_id",
interstitial:"your_ad_place_id",
nativeAd:"your_ad_place_id"
},
android : {
banner:"your_ad_place_id",
interstitial:"your_ad_place_id",
nativeAd:"your_ad_place_id"
}
};

// select the right Ad Id according to platform
var adid = (/(android)/i.test(navigator.userAgent)) ? ad_units.android : ad_units.ios;

// set your hashed device id if testing on device (optional)
if(FacebookAds) FacebookAds.setOptions({
isTesting: true,
deviceHash: 'copy_your_hash_id_from_console_here'
});
```

Step 2: Create a banner with single line of javascript

```javascript
// it will display smart banner at top center, using the default options
if(FacebookAds) FacebookAds.createBanner( adid.banner );
```

Or, show the banner Ad in some other way:

```javascript
// or, show a default banner at bottom
if(FacebookAds) FacebookAds.createBanner( {
adId: adid.banner,
position:FacebookAds.AD_POSITION.BOTTOM_CENTER,
autoShow:true} );
```

Step 3: Prepare an interstitial, and show it when needed

```javascript
// preppare and load ad resource in background, e.g. at begining of game level
if(FacebookAds) FacebookAds.prepareInterstitial( {adId:adid.interstitial, autoShow:false} );

// show the interstitial later, e.g. at end of game level
if(FacebookAds) FacebookAds.showInterstitial();
```

You can even embed the Ad into web content with Native Ad.

Check the example code [test/index.html] (https://github.com/floatinghotpot/cordova-plugin-facebookads/blob/master/test/index.html)

## Javascript API Overview ##

Methods:
```javascript
// set default value for other methods
setOptions(options, success, fail);

// for banner
createBanner(adId/options, success, fail);
removeBanner();
showBanner(position);
showBannerAtXY(x, y);
hideBanner();

// for interstitial
prepareInterstitial(adId/options, success, fail);
showInterstitial();

// for native ad
createNativeAd(adId, success, fail);
removeNativeAd(adId);
setNativeAdClickArea(adId,x,y,w,h);
```

## Detailed Documentation ##

The APIs, Events and Options are detailed documented.

Read the detailed API Reference Documentation [English](https://github.com/floatinghotpot/cordova-plugin-facebookads/wiki).

## FAQ ##

If encounter problem when using the plugin, please read the [FAQ](https://github.com/floatinghotpot/cordova-plugin-facebookads/wiki/FAQ) first.

## Full Example Code ##

This FacebookAds Plugin Pro offers the most flexibility and many options.

Check the [test/index.html] (https://github.com/floatinghotpot/cordova-plugin-facebookads/blob/master/test/index.html).

## Screenshots ##

iPhone Banner | iPhone Interstitial
-------|---------------
![ScreenShot](docs/iphone_banner.jpg) | ![ScreenShot](docs/iphone_interstitial.jpg)

iPhone Landscape

![ScreenShot](docs/iphone_landscape.jpg)

iPhone Native Ad | Android Native Ad
-------|---------------
![ScreenShot](docs/iphone_nativead.jpg) | ![ScreenShot](docs/android_nativead.jpg)

Ad PluginPro series for the world leading Mobile Ad services:

* [GoogleAds PluginPro](https://github.com/floatinghotpot/cordova-admob-pro), for Google AdMob/DoubleClick.
* [iAd PluginPro](https://github.com/floatinghotpot/cordova-iad-pro), for Apple iAd.
* [FacebookAds PluginPro](https://github.com/floatinghotpot/cordova-plugin-facebookads), for Facebook Audience Network.
* [FlurryAds PluginPro](https://github.com/floatinghotpot/cordova-plugin-flurry), for Flurry Ads.
* [mMedia PluginPro](https://github.com/floatinghotpot/cordova-plugin-mmedia), for Millennial Meida.
* [MobFox PluginPro](https://github.com/floatinghotpot/cordova-mobfox-pro), for MobFox.
* [MoPub PluginPro](https://github.com/floatinghotpot/cordova-plugin-mopub), for MoPub.

More Cordova/PhoneGap plugins by Raymond Xie, [find them in npm](https://www.npmjs.com/~floatinghotpot).

If use in commercial project or need prompt support, please [buy a license](http://rjfun.github.io/), you will be served with high priority.

Project outsourcing and consulting service is also available. Please [contact us](mailto:rjfun.mobile@gmail.com) if you have the business needs.
https://github.com/floatinghotpot/cordova-plugin-facebookads/issues/81#issuecomment-350557252

8 changes: 4 additions & 4 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "cordova-plugin-facebookads",
"version": "4.23.2",
"name": "bmo-cordova-plugin-facebookads",
"version": "4.23.3",
"description": "Cordova Plugin for Facebook AudienceNetwork Ads",
"cordova": {
"id": "cordova-plugin-facebookads",
"id": "bmo-cordova-plugin-facebookads",
"platforms": [
"android",
"ios"
]
},
"repository": {
"type": "git",
"url": "https://github.com/floatinghotpot/cordova-plugin-facebookads.git"
"url": "https://github.com/BisManOnline/bmo-cordova-plugin-facebookads.git"
},
"bugs": {
"url": "https://github.com/floatinghotpot/cordova-plugin-facebookads/issues"
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-facebookads"
version="4.23.2">
id="bmo-cordova-plugin-facebookads"
version="4.23.3">

<name>FacebookAds</name>
<description>Cordova/PhoneGap Plugin for Facebook AudienceNetwork Ads</description>
<author>Liming Xie</author>
<license>MIT</license>
<keywords>rjfun,ad,admob,iad,mopub,facebook,audience</keywords>
<repo>https://github.com/floatinghotpot/cordova-plugin-facebookads.git</repo>
<repo>https://github.com/BisManOnline/bmo-cordova-plugin-facebookads.git</repo>
<issue>https://github.com/floatinghotpot/cordova-plugin-facebookads/issues</issue>

<engines>
Expand Down
59 changes: 46 additions & 13 deletions src/android/FacebookAdPlugin.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
import com.facebook.ads.NativeAd.Image;
import com.facebook.ads.NativeAd.Rating;
import com.rjfun.cordova.ad.GenericAdPlugin;

import android.provider.Settings;
public class FacebookAdPlugin extends GenericAdPlugin {
private static final String LOGTAG = "FacebookAds";

private static final String TEST_BANNER_ID = "726719434140206_777151452430337";
private static final String TEST_INTERSTITIAL_ID = "726719434140206_777151589096990";
private static final String TEST_NATIVEAD_ID = "726719434140206_777151705763645";
private static final String TEST_BANNER_ID = "Your APP ID";
private static final String TEST_INTERSTITIAL_ID = "Your APP ID";
private static final String TEST_NATIVEAD_ID = "Your APP ID";

private AdSize adSize;

Expand All @@ -44,6 +44,7 @@ public class FacebookAdPlugin extends GenericAdPlugin {
public static final String ACTION_CREATE_NATIVEAD = "createNativeAd";
public static final String ACTION_REMOVE_NATIVEAD = "removeNativeAd";
public static final String ACTION_SET_NATIVEAD_CLICKAREA = "setNativeAdClickArea";
public static final String ACTION_CLICK_ADCHOICE = "AdchoiceClicked";

private RelativeLayout layout;

Expand Down Expand Up @@ -127,7 +128,17 @@ public boolean execute(String action, JSONArray inputs, CallbackContext callback
this.setNativeAdClickArea(adid, x, y, w, h);
result = new PluginResult(Status.OK);

} else {
}
else if (ACTION_CLICK_ADCHOICE.equals(action)) {
String adid = inputs.optString(0);
int x = inputs.optInt(1);
int y = inputs.optInt(2);
int w = inputs.optInt(3);
int h = inputs.optInt(4);
this.setNativeAdClickArea(adid, x, y, w, h);
result = new PluginResult(Status.OK);

}else {
return super.execute(action, inputs, callbackContext);
}

Expand Down Expand Up @@ -165,7 +176,7 @@ public void run() {
layout.addView(unit.tracking, new RelativeLayout.LayoutParams(unit.w, unit.h));
layout.addView(unit.view, new RelativeLayout.LayoutParams(unit.w, unit.h));
if(isTesting) {
unit.tracking.setBackgroundColor(0x30FF0000);
unit.tracking.setBackgroundColor(0x30FF0000);
unit.view.setBackgroundColor(0x3000FF00);
}

Expand Down Expand Up @@ -253,7 +264,7 @@ public void fireNativeAdLoadEvent(Ad ad) {
String titleForAdButton = unit.ad.getAdCallToAction();
String textForAdBody = unit.ad.getAdBody();
Rating appRatingForAd = unit.ad.getAdStarRating();

Image adChoiceIcon = unit.ad.getAdChoicesIcon();
JSONObject json = new JSONObject();
json.put("adNetwork", __getProductShortName());
json.put("adEvent", EVENT_AD_LOADED);
Expand Down Expand Up @@ -282,25 +293,38 @@ public void fireNativeAdLoadEvent(Ad ad) {
iconInfo.put("url", iconForAd.getUrl());
iconInfo.put("width", iconForAd.getWidth());
iconInfo.put("height", iconForAd.getHeight());
}
JSONObject adchoiceInfo = new JSONObject();
if(adChoiceIcon != null) {
adchoiceInfo.put("url", adChoiceIcon.getUrl());
adchoiceInfo.put("width", adChoiceIcon.getWidth());
adchoiceInfo.put("height", adChoiceIcon.getHeight());
unit.ad.getAdChoicesLinkUrl();
adchoiceInfo.put("onadchoice", unit.ad.getAdChoicesLinkUrl());
Log.d(LOGTAG, "unit.ad.getAdChoicesLinkUrl() : " + unit.ad.getAdChoicesLinkUrl());
//
}

adRes.put("coverImage", coverInfo);
adRes.put("icon", iconInfo);
adRes.put("adchoice", adchoiceInfo);
json.put("adRes", adRes);

jsonData = json.toString();
} catch(Exception e) {
}
if (unit.ad != null) {
unit.ad.unregisterView();

unit.ad.registerViewForInteraction(unit.tracking);
}

fireEvent(__getProductShortName(), EVENT_AD_LOADED, jsonData);
break;
}
}
}

public void removeNativeAd(final String adId) {
final Activity activity = getActivity();
activity.runOnUiThread(new Runnable(){
Expand Down Expand Up @@ -336,7 +360,7 @@ public void setNativeAdClickArea(final String adId, int x, int y, int w, int h)
unit.h = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, metrics);

View rootView = getView().getRootView();
int offsetRootView[] = {0,0}, offsetMainView[] = {0,0};
int offsetRootView[] = {0,0}, offsetMainView[] = {2,2};
rootView.getLocationOnScreen( offsetRootView );
getView().getLocationOnScreen( offsetMainView );
unit.x += (offsetMainView[0] - offsetRootView[0]);
Expand Down Expand Up @@ -370,14 +394,22 @@ public void setOptions(JSONObject options) {
if(options.has(OPT_AD_SIZE)) {
this.adSize = __AdSizeFromString(options.optString(OPT_AD_SIZE));
}

// if(isTesting) {
// testTraffic = true;
// String ANDROID_ID = Settings.Secure.getString(cordova.getActivity().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
// String deviceId = md5(ANDROID_ID).toUpperCase();
// Log.d(LOGTAG, "Facebook Device Id" + deviceId);
// AdSettings.addTestDevice(deviceId);
// this.deviceHash = options.optString(deviceId);
// Log.d(LOGTAG, "set device hash: " + this.deviceHash);
if(isTesting) {
testTraffic = true;

if(options.has(OPT_DEVICE_HASH)) {
this.deviceHash = options.optString( OPT_DEVICE_HASH );
Log.d(LOGTAG, "set device hash: " + this.deviceHash);
AdSettings.addTestDevice(this.deviceHash);
AdSettings.addTestDevice("bbbb29bbf199262cb14c924d692b11ef");

}

SharedPreferences adPrefs = getActivity().getSharedPreferences("FBAdPrefs", 0);
Expand All @@ -389,7 +421,8 @@ public void setOptions(JSONObject options) {
Log.d(LOGTAG, "auto set device hash: " + this.deviceHash);
AdSettings.addTestDevice(deviceIdHash);
}
}
// }
}

@Override
protected View __createAdView(String adId) {
Expand Down Expand Up @@ -537,4 +570,4 @@ protected void __destroyInterstitial(Object interstitial) {
ad.destroy();
}
}
}
}
10 changes: 10 additions & 0 deletions src/ios/FacebookAdPlugin.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ - (void) fireNativeAdLoadEvent:(FBNativeAd*)nativeAd
NSString *socialContextForAd = nativeAd.socialContext;
struct FBAdStarRating appRatingForAd = nativeAd.starRating;
NSString *titleForAdButton = nativeAd.callToAction;
FBAdImage *iconForAdChoice = nativeAd.adChoicesIcon;

NSMutableDictionary* coverInfo = [[NSMutableDictionary alloc] init];
[coverInfo setValue:[coverImage.url absoluteString] forKey:@"url"];
Expand All @@ -509,6 +510,14 @@ - (void) fireNativeAdLoadEvent:(FBNativeAd*)nativeAd
[iconInfo setValue:[iconForAd.url absoluteString] forKey:@"url"];
[iconInfo setValue:[NSNumber numberWithInt:iconForAd.width] forKey:@"width"];
[iconInfo setValue:[NSNumber numberWithInt:iconForAd.height] forKey:@"height"];

NSMutableDictionary* adchoiceInfo = [[NSMutableDictionary alloc] init];
[adchoiceInfo setValue:[nativeAd.adChoicesLinkURL absoluteString] forKey:@"onadchoice"];
[adchoiceInfo setValue:nativeAd.adChoicesText forKey:@"onadchoicetext"];
[adchoiceInfo setValue:[iconForAdChoice.url absoluteString] forKey:@"url"];
[adchoiceInfo setValue:[NSNumber numberWithInt:iconForAdChoice.width] forKey:@"width"];
[adchoiceInfo setValue:[NSNumber numberWithInt:iconForAdChoice.height] forKey:@"height"];


NSMutableDictionary* adRes = [[NSMutableDictionary alloc] init];
[adRes setValue:coverInfo forKey:@"coverImage"];
Expand All @@ -519,6 +528,7 @@ - (void) fireNativeAdLoadEvent:(FBNativeAd*)nativeAd
[adRes setValue:[NSNumber numberWithFloat:appRatingForAd.value] forKey:@"rating"];
[adRes setValue:[NSNumber numberWithInt:appRatingForAd.scale] forKey:@"ratingScale"];
[adRes setValue:titleForAdButton forKey:@"buttonText"];
[adRes setValue:adchoiceInfo forKey:@"adchoice"];

NSMutableDictionary* json = [[NSMutableDictionary alloc] init];
[json setValue:[self __getProductShortName] forKey:@"adNetwork"];
Expand Down