From 5cccc4b434d2b0ffa510953138656fd8ada8a5f7 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Thu, 28 Apr 2022 18:21:30 -0300 Subject: [PATCH 1/4] Add admob ads --- src/components/Board/Board.container.js | 10 ++++++++- src/components/Settings/Settings.container.js | 11 ++++++++++ .../WelcomeScreen/WelcomeScreen.container.js | 6 +++++- src/cordova-util.js | 21 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index b58664af7..50710bfb7 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 { bannerAd, interstitialAd, 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()) { + await this.handleAds(); + } } UNSAFE_componentWillReceiveProps(nextProps) { @@ -360,6 +363,11 @@ export class BoardContainer extends Component { } } + async handleAds() { + if (bannerAd._created) await bannerAd.hide(); + await interstitialAd.load(); + } + 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..33efa3bc6 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 { interstitialAd, bannerAd, isAndroid } from '../../cordova-util'; export class SettingsContainer extends Component { static propTypes = { @@ -16,6 +17,16 @@ export class SettingsContainer extends Component { logout: PropTypes.func.isRequired, isDownloadingLang: PropTypes.bool }; + async componentDidMount() { + if (isAndroid()) { + interstitialAd + .show() + .catch(msg => console.log('The interstitial advice is not available')); + bannerAd + .show() + .catch(msg => console.log('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..820d04f5f 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 { bannerAd, isAndroid, isElectron } from '../../cordova-util'; import { login } from '../Account/Login/Login.actions'; export class WelcomeScreen extends Component { @@ -35,6 +35,10 @@ export class WelcomeScreen extends Component { onClose: PropTypes.func }; + async componentDidMount() { + if (isAndroid()) await bannerAd.hide(); + } + handleActiveView = activeView => { this.setState({ activeView diff --git a/src/cordova-util.js b/src/cordova-util.js index ae01b4d0c..0c801b348 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -36,6 +36,7 @@ export const initCordovaPlugins = () => { console.log(err.message); } configFacebookPlugin(); + prepareAds(); } }; @@ -60,6 +61,26 @@ const configFacebookPlugin = () => { ); }; +export let interstitialAd; +export let bannerAd; + +const prepareAds = () => { + const INTERSTITIAL_ADVICE_UNIT_ID = + process.env.INTERSTITIAL_ADVICE_UNIT_ID || + 'ca-app-pub-3940256099942544/1033173712'; + const BANNER_ADVICE_UNIT_ID = + process.env.BANNER_ADVICE_UNIT_ID || + 'ca-app-pub-3940256099942544/6300978111'; + + interstitialAd = new window.admob.InterstitialAd({ + adUnitId: INTERSTITIAL_ADVICE_UNIT_ID + }); + + bannerAd = new window.admob.BannerAd({ + adUnitId: BANNER_ADVICE_UNIT_ID + }); +}; + export const cvaTrackEvent = (category, action, label) => { try { window.ga.trackEvent(category, action, label); From cbb7c9ff6179cd2aec8f555ec48f730a3fa96555 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 3 May 2022 15:42:03 -0300 Subject: [PATCH 2/4] Admob ads added --- src/components/Board/Board.container.js | 11 ++++++---- src/components/Settings/Settings.container.js | 3 ++- .../WelcomeScreen/WelcomeScreen.container.js | 4 ++-- src/cordova-util.js | 20 ++++++++++++------- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 50710bfb7..1970a65ad 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 { bannerAd, interstitialAd, isAndroid } from '../../cordova-util'; +import { adMobAds, isAndroid } from '../../cordova-util'; const Transition = React.forwardRef(function Transition(props, ref) { return ; @@ -277,7 +277,7 @@ export class BoardContainer extends Component { // if (isAndroid()) downloadImages(); if (isAndroid()) { - await this.handleAds(); + await this.handleAdMobAds(); } } @@ -363,9 +363,12 @@ export class BoardContainer extends Component { } } - async handleAds() { + async handleAdMobAds() { + const { bannerAd, interstitialAd } = adMobAds; if (bannerAd._created) await bannerAd.hide(); - await interstitialAd.load(); + await interstitialAd + .load() + .catch(msg => console.log('Error load interstitial Ad', msg)); } async tryRemoteBoard(boardId) { diff --git a/src/components/Settings/Settings.container.js b/src/components/Settings/Settings.container.js index 33efa3bc6..7457605ed 100644 --- a/src/components/Settings/Settings.container.js +++ b/src/components/Settings/Settings.container.js @@ -7,7 +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 { interstitialAd, bannerAd, isAndroid } from '../../cordova-util'; +import { adMobAds, isAndroid } from '../../cordova-util'; export class SettingsContainer extends Component { static propTypes = { @@ -19,6 +19,7 @@ export class SettingsContainer extends Component { }; async componentDidMount() { if (isAndroid()) { + const { bannerAd, interstitialAd } = adMobAds; interstitialAd .show() .catch(msg => console.log('The interstitial advice is not available')); diff --git a/src/components/WelcomeScreen/WelcomeScreen.container.js b/src/components/WelcomeScreen/WelcomeScreen.container.js index 820d04f5f..0ee8c1fc1 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 { bannerAd, isAndroid, isElectron } from '../../cordova-util'; +import { adMobAds, isAndroid, isElectron } from '../../cordova-util'; import { login } from '../Account/Login/Login.actions'; export class WelcomeScreen extends Component { @@ -36,7 +36,7 @@ export class WelcomeScreen extends Component { }; async componentDidMount() { - if (isAndroid()) await bannerAd.hide(); + if (isAndroid()) await adMobAds.bannerAd.hide(); } handleActiveView = activeView => { diff --git a/src/cordova-util.js b/src/cordova-util.js index 0c801b348..dc7a99f92 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -36,7 +36,13 @@ export const initCordovaPlugins = () => { console.log(err.message); } configFacebookPlugin(); - prepareAds(); + if (isAndroid()) { + try { + prepareAds(); + } catch (err) { + console.log(err.message); + } + } } }; @@ -61,22 +67,22 @@ const configFacebookPlugin = () => { ); }; -export let interstitialAd; -export let bannerAd; +export const adMobAds = {}; const prepareAds = () => { const INTERSTITIAL_ADVICE_UNIT_ID = - process.env.INTERSTITIAL_ADVICE_UNIT_ID || + process.env.REACT_APP_INTERSTITIAL_ADVICE_UNIT_ID || 'ca-app-pub-3940256099942544/1033173712'; + const BANNER_ADVICE_UNIT_ID = - process.env.BANNER_ADVICE_UNIT_ID || + process.env.REACT_APP_BANNER_ADVICE_UNIT_ID || 'ca-app-pub-3940256099942544/6300978111'; - interstitialAd = new window.admob.InterstitialAd({ + adMobAds.interstitialAd = new window.admob.InterstitialAd({ adUnitId: INTERSTITIAL_ADVICE_UNIT_ID }); - bannerAd = new window.admob.BannerAd({ + adMobAds.bannerAd = new window.admob.BannerAd({ adUnitId: BANNER_ADVICE_UNIT_ID }); }; From 7582466faa08804a27ec63a17d9564f66c0d5d61 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Tue, 3 May 2022 15:46:10 -0300 Subject: [PATCH 3/4] Small fix --- src/components/WelcomeScreen/WelcomeScreen.container.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/WelcomeScreen/WelcomeScreen.container.js b/src/components/WelcomeScreen/WelcomeScreen.container.js index 0ee8c1fc1..c7df7f4a8 100644 --- a/src/components/WelcomeScreen/WelcomeScreen.container.js +++ b/src/components/WelcomeScreen/WelcomeScreen.container.js @@ -36,7 +36,8 @@ export class WelcomeScreen extends Component { }; async componentDidMount() { - if (isAndroid()) await adMobAds.bannerAd.hide(); + const { bannerAd } = adMobAds; + if (isAndroid() && bannerAd._created) await bannerAd.hide(); } handleActiveView = activeView => { From 865cbca11602b1a5bb65c6cb8226ce63e53deee9 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Fri, 6 May 2022 12:04:13 -0300 Subject: [PATCH 4/4] Changes requested --- src/components/Board/Board.container.js | 4 ++-- src/components/Settings/Settings.container.js | 6 ++++-- src/cordova-util.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/Board/Board.container.js b/src/components/Board/Board.container.js index 1970a65ad..eca2e80ca 100644 --- a/src/components/Board/Board.container.js +++ b/src/components/Board/Board.container.js @@ -277,7 +277,7 @@ export class BoardContainer extends Component { // if (isAndroid()) downloadImages(); if (isAndroid()) { - await this.handleAdMobAds(); + this.handleAdMobAds(); } } @@ -368,7 +368,7 @@ export class BoardContainer extends Component { if (bannerAd._created) await bannerAd.hide(); await interstitialAd .load() - .catch(msg => console.log('Error load interstitial Ad', msg)); + .catch(msg => console.error('Error load interstitial Ad', msg)); } async tryRemoteBoard(boardId) { diff --git a/src/components/Settings/Settings.container.js b/src/components/Settings/Settings.container.js index 7457605ed..a746f2e22 100644 --- a/src/components/Settings/Settings.container.js +++ b/src/components/Settings/Settings.container.js @@ -22,10 +22,12 @@ export class SettingsContainer extends Component { const { bannerAd, interstitialAd } = adMobAds; interstitialAd .show() - .catch(msg => console.log('The interstitial advice is not available')); + .catch(msg => + console.error('The interstitial advice is not available') + ); bannerAd .show() - .catch(msg => console.log('The banner advice is not available')); + .catch(msg => console.error('The banner advice is not available')); } } diff --git a/src/cordova-util.js b/src/cordova-util.js index 3cb358f6d..bd262763b 100644 --- a/src/cordova-util.js +++ b/src/cordova-util.js @@ -44,7 +44,7 @@ export const initCordovaPlugins = () => { try { prepareAds(); } catch (err) { - console.log(err.message); + console.error(err.message); } } }