Reputation: 475
I've integrated Interstitial Ads in my app. Below are the transition,
- Screen 3
- Screen 4
- Screen 5
- Screen 6
Screen 2 - Screen 7
- Screen 8
- Screen 9
- Screen 10
- Screen 11
- Screen 12
While the transition happens from Screen 2 to Screen n (Where n is 3-12), an interstitial ad is called. I hope this is allowed to do.
Today, I have received a mail from Admob saying that Layout Encourages Accidental Clicks. How do I fix this? I'm not sure where I am going wrong.
Below is the code of one of the activities.
public class CC extends AppCompatActivity implements ConnectivityReceiver.ConnectivityReceiverListener {
ConnectivityReceiver conn;
CheckingStatus checkingStatus;
private static final String TAG = "CC";
private AdView mAdView;
InterstitialAd interstitial;
private static final String AD_UNIT_ID = "ca-app-pub-4189677300abcdefgh.....";
private InterstitialAd interstitialAd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
checkingStatus=new CheckingStatus();
conn=new ConnectivityReceiver();
IntentFilter intentFilter=new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(conn, intentFilter);
checkfunction(CC.this);
setContentView(R.layout.cc);
getSupportActionBar().setTitle("CC");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//for banner ads
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
findViewById(R.id.cc1).setOnClickListener(listener_ca);
findViewById(R.id.cc2).setOnClickListener(listener_cb);
findViewById(R.id.cc3).setOnClickListener(listener_ccc);
//for interstitial ads
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_UNIT_ID);
AdRequest aDRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(aDRequest);
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
if (interstitialAd.isLoaded()) {
interstitialAd.show();
}
}
@Override
public void onAdOpened() {
}
@Override
public void onAdFailedToLoad(int errorCode) {
}
});
};
View.OnClickListener listener_ca = new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(CC.this, pt_ca.class);
startActivity(intent);
}
};
View.OnClickListener listener_cb = new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(CC.this, pt_cb.class);
startActivity(intent);
}
};
View.OnClickListener listener_ccc = new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(CC.this, pt_ccc.class);
startActivity(intent);
}
};
public void checkfunction(Context context){
boolean isConnected=ConnectivityReceiver.isConnected();
checkingStatus.notification(isConnected,context);
}
@Override
protected void onResume() {
super.onResume();
MyApplication.getInstance().setConnectivityListener(this);
}
@Override
public void onNetworkConnectionChanged(boolean isConnected) {
checkfunction(this);
}
@Override
public boolean onSupportNavigateUp(){
finish();
return true;
}
}
What changes should I do to fix this issue?
Upvotes: 3
Views: 6177
Reputation: 5947
I solved with the next code
import {InterstitialAd, AdEventType} from 'react-native-google-mobile-ads';
const adUnitId = 'ca-app-pub-0000000000000000/0000000000';
const [loadingAds, setLoadingAds] = useState<boolean>(false);
useEffect(() => {
let interstitial = InterstitialAd.createForAdRequest(adUnitId, {
requestNonPersonalizedAdsOnly: true,
keywords: ['game', 'education', 'learning', 'kids', 'smart'],
});
if (interstitial != undefined) {
setLoadingAds(true);
}
interstitial.addAdEventListener(AdEventType.LOADED, () => {
//Ready to show
interstitial.show();
setLoadingAds(false);
});
interstitial.addAdEventListener(AdEventType.ERROR, (error) => {
console.log('Ad error:', error);
setLoadingAds(false);
});
interstitial.load();
return () => {
interstitial = null;
setLoadingAds(false);
};
}, []);
You can read the documentation about react-native-google-mobile-ads
here
Upvotes: 0
Reputation: 166
What went wrong is the ad placement. Basically you pop up an interstitial while the user is transitioning forward from one screen to another with intent to do some action there, resulting in accidental clicks.
What you can do is place the interstitial ad while the user is in backward transition, i.e. on the click of back button. In theOnBackPress
method of your desired activity. That should fix your issue.
For more check on google ad policies you can go through this page
Upvotes: 1