floatinghotpot / cordova-smart-adserver

Cordova/PhoneGap Plugin for Smart Ad Server
MIT License
8 stars 7 forks source link

cordova-smart-adserver

Cordova/PhoneGap Plugin for Smart Ad Server.

Show Mobile Ad with single line of javascript code

Step 1: Prepare SiteId, PageId, FormatId, and baseUrl, in Smart Ad Server portal, then write it in your javascript code.

    var ad_units = {};
    if( /(android)/i.test(navigator.userAgent) ) { 
        ad_units = { // for Android
            siteId: 73569,
            banner: '549527/15140',  // in pattern: '{pageId}/{formatId}'
            interstitial: '549527/12145'
        };
    } else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
        ad_units = { // for iOS
            siteId: 73568,
            banner: '549526/15140',
            interstitial: '549526/12145'
        };
    } else {
        alert('Windows phone not supported');
    }
    var defaultOptions = {
        siteId: ad_units.siteId,
        baseUrl: 'http://mobile.smartadserver.com',
        position: SmartAdServer.AD_POSITION.BOTTOM_CENTER,
        // offsetTopBar: false, // avoid overlapped by status bar, for iOS7+
        bgColor: 'black', // color name, or '#RRGGBB'
        isTesting: true, // set to true, to receiving test ad for testing purpose
        // autoShow: true // auto show interstitial ad when loaded, set to false if prepare/show
    };
    SmartAdServer.setOptions( defaultOptions );

Step 2: Want a banner? single line of javascript code.

// it will display smart banner at top center, using the default options
if(SmartAdServer) SmartAdServer.createBanner( {
    adId: ad_units.banner, 
    position: SmartAdServer.AD_POSITION.TOP_CENTER, 
    autoShow: true 
} );

Step 3: Want full screen Ad? Easy.

// load and display full screen Ad
if(SmartAdServer) SmartAdServer.prepareInterstitial( {
    adId: ad_units.interstitial, 
    autoShow: true
} );

Features

Platforms supported:

Highlights:

How to use?

Quick start with cordova CLI

    # create a demo project
    cordova create test1 com.rjfun.test1 Test1
    cd test1
    cordova platform add android

    # now add the plugin, cordova CLI will handle dependency automatically
    cordova plugin add com.rjfun.cordova.smartadserver

    # now remove the default www content, copy the demo html file to www
    rm -r www/*;
    cp plugins/com.rjfun.cordova.smartadserver/test/* www/;

    # now build and run the demo in your device or emulator
    cordova prepare; 
    cordova run android; 
    # or import into eclipse

Javascript API Overview

Methods:

// use banner
createBanner(adId/options, success, fail);
removeBanner();
showBanner(position);
showBannerAtXY(x, y);
hideBanner();

// use interstitial
prepareInterstitial(adId/options, success, fail);
showInterstitial();

// set default value for other methods
setOptions(options, success, fail);

Screenshots

Banner Bottom Banner Top
ScreenShot ScreenShot
Banner Toast Interstitial
ScreenShot ScreenShot

Credits

This Cordova plugin is developed by Raymond Xie for Groupe Express-Roularta and Chunk Group.

Groupe Express-Roularta is the sponsor of Android code of this project, and agrees to publish as open source to benefit the community.

Chunk is the sponsor of iOS code of this project, and agrees to publish as open source to benefit the community.

See Also

Ad PluginPro series for the world leading Mobile Ad services:

More Cordova/PhoneGap plugins by Raymond Xie, find them in plugin registry.

If use in commercial project and need email/skype support, please buy a license, you will be supported with high priority.

Project outsourcing and consulting service is also available. Please contact us if you have the business needs.