Library for creating Rich Media ads running on the Google AdMob network of mobile applications.

Include this library in an ad with: <script type="text/javascript" src="http://media.admob.com/api/v1/google_mobile_app_ads.js"></script>


Global Functions

admob.events.addEventListener(typehandleropt_captureopt_handlerScope)
Adds a listener for events dispatched by the SDK.

Banners do not have any SDK events.

The rich media overlay has two lifecycle events: 'onshow' and 'onhide'. The time between them is the total time the user spent engaging with the ad. Overlay event types:

  • 'onshow' is called when the user first sees the overlay. It is when animations should start and interstitial impressions should be counted. When coming from a banner 'onshow' is dispatched immediately after the HTML 'load' event; for interstitials it may come long after. If there are multiple HTML pages only the first receives 'onshow'.
  • 'onhide' is called immediately before the overlay is dismissed.

For example to begin an intro animation once the overlay is visible:

function startMyAnimation(event) {
  // ...
}

// Begin animations once the user can see the overlay.
if (admob.opener.isOverlayShowing()) {
  startMyAnimation();
} else {
  admob.events.addEventListener('onshow', startMyAnimation);
}

Arguments:
type :
The type of the event to listen for.
handler :
(Object | null)
The function to handle the event.
opt_capture :
(boolean | undefined)
In DOM-compliant browsers, determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
admob.opener.canOpen(urlscallbackFunction)
Detects if the OS can open one or more URLs. For example, in the iOS SDK, trying 'googleapp://' will return if the Google Search app is installed on the device.

This has no effect if called from outside of a SDK (e.g. in Mobile Safari, the Android Browser, or Chrome).

To determine if the Google Search app is installed, you might include this function:

function checkForGoogleSearchApp() {
  var appUrl = 'googleapp://';
  admob.opener.canOpen(appUrl, function(checkType, results) {
    if (results[appUrl]) {
      // Google Search app is installed.
      // You might provide a link to let the user open it.
    } else {
      // Google Search app is not installed.
      // You might provide a link to let the user download it.
    }
  });
}

Arguments:
urls :
(Array.<string> | null | string)
The URL or array of URLs to validate if they can be handled.
callbackFunction :
function (string, (Object.<boolean> | ?null)):
A function called with results of the query. The first parameter is always the event name 'openableURLs'. The second is an associative array of results where the keys are the urls passed to this function and the values are booleans indicating if the OS can open those URLs or not.
admob.opener.close()
The SDK should close the current ad and go back to application.

This has no effect inside a banner. It only works in the rich media overlay.

admob.events.dispatchAppEvent(nameopt_infoopt_sendBeforePageLoad)
Notify the application with an app event with optional information.
Arguments:
name :
An identifier for the app event.
opt_info :
(string | undefined)
The information to be sent to the app.
opt_sendBeforePageLoad :
(boolean | undefined)
Set to true when the app event is desired before the SDK notifies the publisher delegate of a 'received ad' event.
admob.isAdMobSdk()
Detects if JavaScript is running within a Google AdMob Ads SDK. This is more specific than the Closure library's boolean goog.userAgent.MOBILE which detects a mobile device, but not necessarily the SDK.
Returns:   true if running inside an AdMob SDK.
admob.isAdMobSdkForAndroid()
Detects if JavaScript is running within the Google AdMob Ads SDK for Android. This is more specific than the Closure library's boolean goog.userAgent.product.ANDROID which detects an Android device, but not necessarily the Android SDK.
Returns:   true if running inside the AdMob SDK for Android.
admob.isAdMobSdkForIos()
Detects if JavaScript is running within the Google AdMob Ads SDK for iOS. This is more specific than the Closure library's booleans goog.userAgent.product.IPHONE and goog.userAgent.product.IPAD which detects an iOS device, but not necessarily the iOS SDK.
Returns:   true if running inside the AdMob SDK for iOS.
admob.opener.isOverlayShowing()
Checks if the ad is in the rich media overlay and has shown to the user. This is true between the 'onshow' and 'onhide' events.
Returns:   Returns true if the rich media overlay is visible to the user.
admob.log(message)
Logs the message to the development console. Logging on iOS outputs to the Xcode console, on Android to ADB, and on a traditional browser to window.console.log.
Arguments:
message :
The log message to send to the developer console.
admob.opener.openApp(url)
Use admob.opener.openUrl(url). Opens the URL in another application such as the Apple App Store or Android Market.
Arguments:
url :
The URL of the application to load in the store.
admob.opener.openBrowser(url)
Use admob.opener.openUrl(url). Opens the URL in a new browser window (or tab).
Arguments:
url :
The absolute URL to load.
admob.opener.openOverlay(urlopt_supportedOrientations)
Opens the "Rich Media Overlay" and loads the URL. This is the most commonly used method of this API.

The rich media overlay is a full screen browser. There is no status bar, always the full screen's dimensions. A close button is placed over the ad in the upper-left corner (centered in the bounding box [0, 0, 32, 32]).

For example a banner might include this function to handle a click by opening the landing page locked in the landscape orientation:

function adClicked(relativeUrl) {
  var current = location.href;
  var base = current.substring(0, current.lastIndexOf('/') + 1);
  var destination = base + relativeUrl;

  // Open the landing page locking the screen in landscape.
  admob.opener.openOverlay(destination, 'l');
}

Arguments:
url :
The absolute URL to load.
opt_supportedOrientations :
(string | undefined)
If not supplied any orientation is supported, if it is 'p' only portrait is available, and if it is 'l' then only landscape is supported.
admob.opener.openUrl(urlopt_openNativeApp)
Opens the URL in the most appropriate handler. This is determined by inspecting the protocol and extension of the URL string.

URLs with app-specific protocols, like 'googleapp://', will attempt to launch the app directly. Note: this does not automatically check if the application is installed. Please use admob.opener.canOpen first to make that determination.

URLs with standard communication protocols, like 'sms:' and 'tel:', will attempt to launch the default OS intent.

URLs with extensions that indicate a supported video container, like '.m4v', will attempt to open in the default video player.

All other URLs will open in a new browser window with forward and back controls.

Arguments:
url :
The absolute URL to open.
opt_openNativeApp :
(boolean | undefined)
Whether to force the URL to open in a native app. On iOS, if you prefer to open a landing page in Mobile Safari instead of the in-app browser, set this parameter to true.
admob.recordEvent(url)
Useful for analytics. The url is normally a tracking pixel that records an event. When running inside an AdMob SDK the URL will be accessed in the background so the application does not pause. When outside of an AdMob SDK it will create a hidden image tag.
Arguments:
url :
The HTTP URL to load asynchronously.
admob.events.removeEventListener(typehandleropt_captureopt_handlerScope)
Removes a listener for events dispatched by the SDK.
Arguments:
type :
The type of the event to listen for.
handler :
function (string, (Object | ?null)):
The function to handle the event.
opt_capture :
(boolean | undefined)
In DOM-compliant browsers, determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
(Object | null | undefined)
Object in whose scope to call the listener.
admob.device.vibrate()
Causes the device to vibrate for a short time. This is not available on all devices. For example the iPhone will vibrate but the iPad and iPod Touch will not.