Skip to content

Instantly share code, notes, and snippets.

@eladcandroid
Created October 28, 2018 06:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eladcandroid/75bb38967c0b74346b2998b599ef2e09 to your computer and use it in GitHub Desktop.
Save eladcandroid/75bb38967c0b74346b2998b599ef2e09 to your computer and use it in GitHub Desktop.
adMob.js for cordova-plugin-admob-free
let adMob = null;
export function initAd() {
adMob = window.plugins.AdMob || window.AdMob;
if (/(android)/i.test(navigator.userAgent) && adMob) {
adMob.banner.config({
id: "ca-app-pub-8953910389003952/3660976168",
autoShow: false,
isTesting: process.env.NODE_ENV === "production" ? false : true
});
adMob.banner.prepare();
adMob.interstitial.config({
id: "ca-app-pub-8953910389003952/2792136689",
autoShow: false,
isTesting: process.env.NODE_ENV === "production" ? false : true
});
adMob.interstitial.prepare();
}
}
export function showInterstitial() {
if (adMob) adMob.interstitial.show();
}
export function showAd() {
if (adMob) adMob.banner.show();
}
@eladcandroid
Copy link
Author

eladcandroid commented Oct 28, 2018

Usage: (VueJS)

In main.js for example:

import { initAd, showAd } from "./adMob";

....

  mounted() {
    document.addEventListener("deviceready", () => {
      initAd();
      showAd();
    });
  },

....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment