diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js
index b58664af7..eca2e80ca 100644
--- a/src/components/Board/Board.container.js
+++ b/src/components/Board/Board.container.js
@@ -65,7 +65,7 @@ import {
import { NOTIFICATION_DELAY } from '../Notifications/Notifications.constants';
import { EMPTY_VOICES } from '../../providers/SpeechProvider/SpeechProvider.constants';
import { DEFAULT_ROWS_NUMBER, DEFAULT_COLUMNS_NUMBER } from './Board.constants';
-//import { isAndroid } from '../../cordova-util';
+import { adMobAds, isAndroid } from '../../cordova-util';
const Transition = React.forwardRef(function Transition(props, ref) {
return ;
@@ -276,6 +276,9 @@ export class BoardContainer extends Component {
this.setState({ isFixedBoard: !!boardExists.isFixed });
// if (isAndroid()) downloadImages();
+ if (isAndroid()) {
+ this.handleAdMobAds();
+ }
}
UNSAFE_componentWillReceiveProps(nextProps) {
@@ -360,6 +363,14 @@ export class BoardContainer extends Component {
}
}
+ async handleAdMobAds() {
+ const { bannerAd, interstitialAd } = adMobAds;
+ if (bannerAd._created) await bannerAd.hide();
+ await interstitialAd
+ .load()
+ .catch(msg => console.error('Error load interstitial Ad', msg));
+ }
+
async tryRemoteBoard(boardId) {
const { userData } = this.props;
const remoteBoard = await API.getBoard(boardId);
diff --git a/src/components/Settings/Settings.container.js b/src/components/Settings/Settings.container.js
index 78b4e726c..a746f2e22 100644
--- a/src/components/Settings/Settings.container.js
+++ b/src/components/Settings/Settings.container.js
@@ -7,6 +7,7 @@ import { logout } from '../Account/Login/Login.actions';
import { getUser, isLogged } from '../App/App.selectors';
import { injectIntl, intlShape } from 'react-intl';
import { disableTour } from '../../components/App/App.actions';
+import { adMobAds, isAndroid } from '../../cordova-util';
export class SettingsContainer extends Component {
static propTypes = {
@@ -16,6 +17,19 @@ export class SettingsContainer extends Component {
logout: PropTypes.func.isRequired,
isDownloadingLang: PropTypes.bool
};
+ async componentDidMount() {
+ if (isAndroid()) {
+ const { bannerAd, interstitialAd } = adMobAds;
+ interstitialAd
+ .show()
+ .catch(msg =>
+ console.error('The interstitial advice is not available')
+ );
+ bannerAd
+ .show()
+ .catch(msg => console.error('The banner advice is not available'));
+ }
+ }
render() {
return ;
diff --git a/src/components/WelcomeScreen/WelcomeScreen.container.js b/src/components/WelcomeScreen/WelcomeScreen.container.js
index 625c6894e..c7df7f4a8 100644
--- a/src/components/WelcomeScreen/WelcomeScreen.container.js
+++ b/src/components/WelcomeScreen/WelcomeScreen.container.js
@@ -20,7 +20,7 @@ import ResetPassword from '../Account/ResetPassword';
import CboardLogo from './CboardLogo/CboardLogo.component';
import './WelcomeScreen.css';
import { API_URL } from '../../constants';
-import { isAndroid, isElectron } from '../../cordova-util';
+import { adMobAds, isAndroid, isElectron } from '../../cordova-util';
import { login } from '../Account/Login/Login.actions';
export class WelcomeScreen extends Component {
@@ -35,6 +35,11 @@ export class WelcomeScreen extends Component {
onClose: PropTypes.func
};
+ async componentDidMount() {
+ const { bannerAd } = adMobAds;
+ if (isAndroid() && bannerAd._created) await bannerAd.hide();
+ }
+
handleActiveView = activeView => {
this.setState({
activeView
diff --git a/src/cordova-util.js b/src/cordova-util.js
index 6d34d446c..bd262763b 100644
--- a/src/cordova-util.js
+++ b/src/cordova-util.js
@@ -40,6 +40,13 @@ export const initCordovaPlugins = () => {
} catch (err) {
console.log(err.message);
}
+ if (isAndroid()) {
+ try {
+ prepareAds();
+ } catch (err) {
+ console.error(err.message);
+ }
+ }
}
};
@@ -64,6 +71,26 @@ const configFacebookPlugin = () => {
);
};
+export const adMobAds = {};
+
+const prepareAds = () => {
+ const INTERSTITIAL_ADVICE_UNIT_ID =
+ process.env.REACT_APP_INTERSTITIAL_ADVICE_UNIT_ID ||
+ 'ca-app-pub-3940256099942544/1033173712';
+
+ const BANNER_ADVICE_UNIT_ID =
+ process.env.REACT_APP_BANNER_ADVICE_UNIT_ID ||
+ 'ca-app-pub-3940256099942544/6300978111';
+
+ adMobAds.interstitialAd = new window.admob.InterstitialAd({
+ adUnitId: INTERSTITIAL_ADVICE_UNIT_ID
+ });
+
+ adMobAds.bannerAd = new window.admob.BannerAd({
+ adUnitId: BANNER_ADVICE_UNIT_ID
+ });
+};
+
export const cvaTrackEvent = (category, action, label) => {
try {
window.ga.trackEvent(category, action, label);