JQM Google AdMob plug-in App

Using Google AdMob is one of the easiest ways to potentially make money from your app. In this tutorial, you will learn how to integrate AdMob advertisements into your Appery.io JQM app.

Part 1. Importing Plug-in

Before the plug-in can be used in your app, you need to import it into Appery.io. You can find the plug-in sources by following this GitHub link: Cordova AdMob Free plugin GitHub page.

🚧

Cordova AdMob plug-ins

There are several Cordova plug-ins for AdMob integration that can be found. However, some of them may be chargeable, so please be careful. The plug-in described in this tutorial is a free and ad-free version of the Google AdMob plug-in for Cordova.

Information on how a custom plug-in can be imported into Appery.io can be found here: Custom Cordova Plugins: Importing Cordova plug-ins from GitHub.

After the plug-in is imported, you can proceed with setting up AdMob and creating the app.

Part 2. Setting up AdMob Account

  1. Create a new Google AdMob account or use an existing account if you already have one. Navigate to the AdMob console to start.

  2. In the left panel, click Apps > ADD YOUR FIRST APP (or Apps > ADD APP if you already have some apps in your account):

  1. In the new window, provide the app name and the platform (Android or iOS), and select Yes, the app is listed on a supported app store if your app has been published on Google Play or the App Store. Otherwise, click No, Click CONTINUE:

👍

AdMob for iOS

If you plan to use AdMob for iOS devices, you will need to create another app under your AdMob account.

  1. In the next step, name your app and confirm adding it:
  1. You will see a message saying that your app has been added to AdMob. You can select to go to the CREATE AD UNIT link or click the below DONE button to do the same:
  1. Next, create a new ad unit by clicking the ADD AD UNIT button:
  1. Select the ad unit type from Banner, Interstitial, Rewarded interstitial, Rewarded, Native Advanced, or App open. You can create an ID for each ad type. For example, let's create a Banner:
  1. Next, select a name for the banner and click Create ad unit:
  1. As a result, you will be provided with the App ID. The second ID is the Ad Unit ID. We will need both these IDs later:
1 - App ID, 2 - Ad Unit ID1 - App ID, 2 - Ad Unit ID

1 - App ID, 2 - Ad Unit ID

📘

Note!

Your app ad units details can be found under Apps > APP_NAME > Ad units:

🚧

Verifying your AdMob account

Please note that production ads will only appear after your AdMob account is verified. Your AdMob account will get verified only after you enter all information about you, including payment information.

Using Sample Ad IDs for Testing

You can use sample ads units for development purposes.
More information about using test ads and the full list of Google provided test ad IDs can be found in this article.

Here are the test IDs that will be used in our tutorial:

Ad format

Sample ad unit ID

Banner

ca-app-pub-3940256099942544/6300978111

Interstitial

ca-app-pub-3940256099942544/1033173712

Rewarded Video

ca-app-pub-3940256099942544/5224354917

🚧

Important!

If you need to show ads in your production app, you will need to create real ad units.

Part 3. Creating App

  1. From the Apps tab, click Create new app.

  2. Select IjQuery Mobile > Blank for the application type, enter adMobApp for the app name, and click Create. You will be navigated to the app's dashboard:

Adding Dependencies

  1. Inside the app, navigate to Project > App Settings > Cordova plugins. Here, go to the Imported Cordova Plugins tab and enable the Cordova AdMob Plugin:
  1. From the AdMob console, go to Apps > VIEW ALL APPS to find the AdMob App IDs:
  1. First, copy the Android AdMob App ID to the clipboard and go back to the Appery.io App Builder. Click the Options button next to the Cordova AdMob Plugin and add a new option with ADMOB_APP_ID as its key and the copied App ID as its value. Then click the Save options button:
  1. In order to make the plug-in work on iOS devices, we need to make some changes to the config.xml file. From the AdMob Apps list, copy the iOS AdMob App ID and go back to the Appery.io App Builder.

🚧

AdMob for iOS

If you plan to use AdMob for iOS devices, you will need to create a new app under your AdMob account first just like you did for Android in part 2 of this tutorial.

  1. Click Source and unfold the CORDOVA folder. In your config.xml file inside the <platform name="ios"> section, paste the following, replacing YOUR_ADMOB_IOS_APP_ID string with the iOS AdMob App ID:
<config-file target="*-Info.plist" parent="GADIsAdManagerApp">
  <true />
</config-file>

<config-file target="*-Info.plist" parent="GADApplicationIdentifier">
  <string>YOUR_ADMOB_IOS_APP_ID</string>
</config-file>
Editing config.xml fileEditing config.xml file

Editing config.xml file

  1. Don't forget to save the app changes by clicking the SAVE button.

Displaying AdMob Advertisements

Now let's use simple methods to show different types of AdMob ads.

🚧

Important!

In this tutorial, we will be using the sample App IDs for testing purposes provided in this section. But if you need to show ads in your production app, you will need to create real ad units.

  1. In the app, go to Project > Pages > startScreen and open the DESIGN panel.

  2. Drag & drop three Buttons to the screen.

  3. Change their Text properties to Show Banner, Show Interstitial and Show Video ads accordingly:

  1. Select the first, Show Banner, button. Unfold the EVENTS tab from the bottom and create a new Click event for this button with Run TypeScript for the Action , type in the following code and save:
admob.banner.config({
   isTesting: true, // change to false in production app
   autoShow: true,
   id: 'ca-app-pub-3940256099942544/6300978111', // replace with your Ad Unit ID in production app
});

admob.banner.prepare();

📘

Banner Ads

Clicking the first button will display a banner. Banner is a basic ad format that appears at the top or bottom of the device screen. Let's add a banner ad unit.

  1. Then select the second, Show Interstitial, button. From the EVENTS tab, create a new Click event for this button with Run TypeScript for the Action, type in the following code, and save:
admob.interstitial.config({
   isTesting: true, // change to false in production app
   autoShow: true,
   id: 'ca-app-pub-3940256099942544/1033173712', // replace with your Ad Unit ID in production app
});

admob.interstitial.prepare();

📘

Interstitial Ads

Clicking the second button will display an Interstitial Ad. An interstitial ad is a full-page ad appearing at natural breaks and page transitions. It supports showing video content.

  1. Finally, select the third, Show Video ads, button. From the EVENTS tab, create a new Click event for this button. Select Run TypeScript as its Action and type in the following code:
admob.rewardvideo.config({
   isTesting: true, // change to false in production app
   autoShow: true,
   id: 'ca-app-pub-3940256099942544/5224354917', // replace with your Ad Unit ID in production app
});

admob.rewardvideo.prepare();

📘

Rewarded Video Ads

Clicking the third button will display a Rewarded Video Ads. Rewarded Video Ads reward users for watching short videos and interacting with playable ads and surveys. It also supports video content.

Save all app changes.

🚧

Ad Unit IDs

Make sure you have replaced the sample Ad Unit IDs with the correct Ad Unit IDs for all three buttons in your production app!

App Testing

Congratulations! You are ready to test the app.

Note that to use the AdMob plug-in, you need to run the app on the device. So, first of all, export the app and install it on your device.

👍

Important!

In this tutorial, we will be using the sample App IDs for testing purposes provided in Part 2 section. But if you need to show ads in your production app, you will need to create real ad units.

Click the buttons one by one to test different ad types:

App work on AndroidApp work on Android

App work on Android

👍

iOS Certificate Generation

Please note that you will need to generate the iOS certificate with In-App Purchase capability to build an .ipa file.

🚧

Important!

For Android only:

If your application also uses the Push Notification service, please add the OneSignal Cordova plug-in to it. You can learn here how to do it.

Note that there is no need to call it or use any custom code, adding one more Cordova plug-in will suffice.

For JQM apps only:

If you are working with a JQM app, the same OneSignal Cordova plug-in should be added but you will need to call the following code to open the ad:

admob.banner.config({
   isTesting: true, // change to false in production app
   autoShow: true,
   id: 'ca-app-pub-3940256099942544/6300978111', // replace with your *Ad Unit ID* in production app
});

admob.banner.prepare();

Note as well that the code provided above shows test ads only. To display user's production ads please replace the code with the following:

admob.interstitial.config({

   id: '<Put your admob app id here>',

   isTesting: false,

   autoShow: true

});

admob.interstitial.prepare();