0

I'm trying to display interstitial Ad in my PhoneGap app but it's not working; it's not displaying the ad at all. I followed the instructions here.

Apart from trying to make it work, what I also need to do is to show the interstitial at a particular time (probably when the game is over) but I dont know how to refer to the Java code from JavaScript code to show the loaded interstitial ad.

Please help.

mcwaloy
  • 15
  • 5

1 Answers1

0

I recently got AdMob working within my Cordova 4 project after much fiddling. Forget the instructions you linked to in your question, which are not for cordova/phonegap builds.

Step 1: You will need to install the Cordova/Phonegap plugin for Admob. (This assumes you have already created the project files.) In my case, e.g. for Cordova command line interface, I used Terminal, cd to my project's root directory and then type:

cordova plugin add com.admob.google

For your Phonegap setup, you will likely need to do one of the following:

Add this to your project's config.xml file.

<gap:plugin name="com.admob.google" source="plugins.cordova.io" />

OR (for Phonegap CLI), type this command into Terminal from your project's root directory,

phonegap local plugin add com.admob.google

Once you have the plugin, you can use javascript to control Admob behavior.

Step 2: Add appropriate javascript for Admob plugin to your project, linked in your index.html file. I ran into some trouble here, so just to prove to myself that the plugin really works, I removed (backed up) everything from my project's WWW folder and added the exact files from the WWW folder from this project and later this one on Github. Both work. It was then a matter of making smarter-people-than-myself's javascript work in my app.

A few tips

  • Don't use the emulator. Admob may not perform correctly in the emulator.
  • For some reason, I am not served Admob ads over LTE/4G. If you are certain you have done everthing correctly, try connecting your device to WIFI when testing
  • If your app is still not working, and you don't know what elese to do, try to validate your HTML. Invalid html will affect performance of javascript.
  • Make sure you have added <script type="text/javascript" src="cordova.js"></script> in your head of your index file.
SEAnalyst
  • 1,077
  • 8
  • 15
  • Hi, when I tried to add `` to the config.xml file in the project home folder, it automatically updates it to the config.xml file in `res/xml/config.xml` which gives error when I try to build: `error: Error parsing XML: unbound prefix` – mcwaloy Dec 30 '14 at 05:09
  • Hi @user2070999 , thanks for your great help and pointing me to the right js code. It's working now. However, I removed the `` from the `config.xml` due to the error it was giving me while building. But yet, it works :). Thanks man. You made my day. Happy new year!!! – mcwaloy Dec 31 '14 at 11:55
  • Great! Glad it is working. Since you mentioned adding ` – SEAnalyst Jan 02 '15 at 17:49
  • Hi @user2070999 , I've been following the first link in the step 2 and it shows both banner and interstitial ads. However, it doesn't reflect on my Admob account. No clicks or fill rate or request. Nothing atall. I did used my ad codes of course and clicked on the ads to test. Have you encountered this problem before? Have a way out of this? – mcwaloy Jan 14 '15 at 08:40
  • My guess: if you followed the [admob-phonegap-build-demo](https://github.com/appfeel/admob-phonegap-build-demo), you are missing one of these configurations:1. Replace the `interstitial` and the `banner` codes in index.js with codes from your actual admob account _e.g. something like ca-app-pub-84403..._ It sounds like you did this okay already. 2. make sure `isTesting:` is NOT set to true in the index.js file. Set to `false`. If you are able to get a test ad, you should be able to see a real ad when set to true. See if you can at least get the impressions to start counting. Good luck. – SEAnalyst Jan 18 '15 at 18:31
  • Idid 1 already. For 2, there is no `isTesting` in the code I used. I has `var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;` instead. That's the only line I can find something related to `test`. Do I need to change something here? The requests and impressions works fine I think, just the clicking that doesnt show anything. It has been like that since. – mcwaloy Jan 18 '15 at 18:36
  • Hmm. `isTesting:` appears in the .js file for both examples in Step 2. I just noticed that one is called index.js and the other is called admob.js. Let me send a link to both. Here is [#1](https://github.com/appfeel/admob-google-cordova/blob/master/www/admob.js) and [#2](https://github.com/appfeel/admob-phonegap-build-demo/blob/master/www/js/index.js). – SEAnalyst Jan 22 '15 at 01:05