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);
}
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.
}
});
}
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.
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.
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.
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 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.
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');
}
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(url, opt_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.
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.
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.