Any way to display AdMob ads (or other ad provider) in pure JavaScript

14,985

Solution 1

There's a powerful AdMob Plugin Pro (free, even though name pro sounds scary), that can be quite easily used in PhoneGap Build. I think, this is the state-of-art solution for this problem, because -- with introduction to npm plugins to PhoneGap Build -- you can now use in pure Javascript PhoneGap Build application all the ad networks, that require you to use their native SDKs.

Key advantages (in context of this question) -- out-of-the-box support for:

  • PhoneGap Build (see notice below),
  • many ad types, including full screen ads,
  • many ad providers and ad networks (with plugins, see below),
  • serving ads using pure Javascript, with just a few lines of code.

Plugin supports following ad networks / providers:

  • AdMob,
  • DFP,
  • Facebook Audience Network,
  • Flurry,
  • iAd,
  • InMobi,
  • Millennial Media,
  • MobFox.

Where first two (in bold) has out-of-the-box support, while all other require use of additional plugins.

There's an article on using this plugin in PhoneGap Build. It is a bit out-dated. You should not use now deprecated plugins.cordova.io, but newly supported npm repository. For this, simply replace:

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

with:

<gap:plugin name="cordova-plugin-admobpro" source="npm"/>

Plugin's author offers an extensible documentation which includes API documentation, code examples and example implementations among different development platforms. Really good piece of work!

Resources:

Solution 2

tl;dr Displaying mobile ads using pure Javascript:

I've been through this for long while and your request (JavaScript code) unfortunately is not available neither with mMedia nor AdMob.

mMedia : They have the following source code types for a mobile web site ( not android app ): ASP, Perl, PHP, JSP5, ruby on rails, and vb.net. to get the source code you need a mobile web site and the mobile web site has to be approved by mMedia then you get live ads and I guess if you used the source code of website in your android app they will have the account suspended because in mMedia every project has to be approved first so they expect their ads are displayed on the project they approved on. And there is no JavaScript code as you requested anyway. mMedia will provide with sdk and instruction to download and install in your app off course live ads would be displayed after their approval and I guess that what you don't want.

AdMob: It is little bit confusing reading about them , because in the past they used to serve ads through JavaScript method intended for mobile web site but after google buying the company they removed this and AdMob doesn't serve mobile website any more and for mobile web site they advise you to use AdSense. what confusing about it that there is still instruction for installing AdMob JavaScript which doesn't exist any more. I saw your links and I guess you where trying to install AdMob for iOS app. I did it for Android app which was straight forward and it was easy using In-App-Advertisements, but the problem was what ever I try it shows on the bottom.

AdSense: they have the JavaScript way but they don't allow you to use it on mobile apps and if they find out they will have your account suspended (details).

for MobFox: they serve ads for mobile web site and the source code types for mobile web site are : JavaScript, PHP, cURL, PHP, fSocket, J2SE 1.4, CGI/Perl and ASP.NET. and for application you have to download the SDK. but there is nothing states in MobFox the you can't use their JavaScript for mobile app and they work like google once you are approved you get Publisher ID and do what ever you want without breaking their terms. Unlike mMedia they have to approve every thing first. And they have the Ad network mediation option for the following companies 4INFO, Aditic (Sofialys), Adfonic, AdMarvel, Admoda, BuzzCity, Hunt, Mobile Ads, InMobi, iVdopia, JumpTap, Komli Mobile (ZestAdz), Lumata Group(bMobile), m-perf, Madvertise, MdotM, MobGold, MobPartner, Mocean, Mojiva, Nexage Exchange, Smaato, TapIt!, Vserv, WapStart, YOC Performance (Mocean Platform), YOC Performance (Ubiyoo Platform)

As far as my research goes the only choice you have for JavaScript code would be with MobFox and you need a way to get the approval so you would have a publisher ID. I had a mobile web contains 4 pages with a little traffic like 20 per day and I got their approval.

Share:
14,985
trejder
Author by

trejder

I'm just an average person, that uniquely combines strict, engineering mind with a non-schematic, humanistic and magical way of looking on life and surrounding world. Add a little bit of madness, and you'll get entire picture of me! :] I'm a developer, both desktop and mobile, with 15+ years of experience and 50+ small-to-big projects on account. In the very same time I'm a writer with similar experience and a lot of books, articles, blog posts or own blogs ideas on account.

Updated on June 22, 2022

Comments

  • trejder
    trejder almost 2 years

    Is there any way to display AdMob ads using only pure JavaScript? Or in any other way, that I can use it directly in PhoneGap application built with PhoneGap Build?

    I'm developing mobile apps using PhoneGap. I've seen many solutions and approaches to this problem (like this or this). But since I'm using PhoneGap Build only, I can't use any of it. I've seen AdMob Cordova Plugin, but since it is platform-oriented (currently only available for iOS and Android) and has a lot of Java and SDK in documentation, I'm pretty sure, that I can't use it in app compiled with PhoneGap Build.

    If there is no way to get AdMob via JS, then maybe there is another ad provider, which API is reachable entirely from JavaScript?

    I've heard that MillenialMedia can display ads using pure JavaScript and even allows external ads providers (like AdMob). So this would be a perfect solution for me. But their page is so poorly organised (a lot of self-marketing bla-bla and no actual links to some API, examples or docs, at least no, when you're not logged in), that I can't confirm that it supports both JavaScript and AdMob. Does someone have any experience with this system and can confirm this?

  • Phill Healey
    Phill Healey over 10 years
    Where does it show how to just use 3 lines of JS? All I seem to be able to find is lengthy instructions involving SDK's and android native code. Hopefully Im just looking in the wrong places. Any help would be appreciated. Thanks.
  • Big Rich
    Big Rich about 10 years
    I think that API might be for the creation of [banner] adverts written using HTML5 and not for the integration of Admob's adverts into an HTML-based app (seems perverse I know, but I don't make the rules, unfortunately :-) )
  • trejder
    trejder almost 9 years
    @BigRich I think you're pretty right. Lotav says (in his answer), that AdMob does not allow pure-JS ads integration and this link indeed points to a guide how to build a HTML5-based ad rather than how to integrate displaying of them.
  • trejder
    trejder almost 9 years
    @PhillHealey Seems you're absolutely right! I only found three-line-or-so-solution for mobile websites, where it is clearly stated, that this solution is prohibited for mobile apps!