Install code samples

From Mocean Mobile Wiki

Jump to: navigation, search

Contents

Getting the Site/Zone ids

  1. Go to the respective network http://*.moceanmobile.net
  2. Click on 'Publisher Sites & Content' and find "Existing Apps/Sites" table at the "Create App/Site" or at the "Manage Apps/Sites"
  3. Select the "Zones" option from the 'Action' drop-down for the desired site/app
  4. Click on 'Code'

PHP install code

<?php

// change to "live" to disable demo mode and show real ads
define("MOCEANV2_MODE", "test");

function moceanv2_get_udid()
{
        $moceanv2_get = '';
        //check UID
    if ( isset($_COOKIE['MOCEAN_AD_UDID']) ) {
        if(setcookie('MOCEAN_AD_UDID', $_COOKIE['MOCEAN_AD_UDID'], time() + 60 * 60 * 24 * 7)) {
            $moceanv2_get = '&udid='.urlencode($_COOKIE['MOCEAN_AD_UDID']);
        }
    } else {
        $udid = md5(time()+rand());
        if(setcookie('MOCEAN_AD_UDID', $udid, time() + 60 * 60 * 24 * 7)) {
            $moceanv2_get = '&udid='.urlencode($udid);
        }
    }
    return $moceanv2_get;
}

$moceanv2_udid = moceanv2_get_udid();

function moceanv2_ad()
{
    $ua = $_SERVER['HTTP_USER_AGENT'];
    $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR'...]) ? trim(reset(split(",", $_SERVER['HTTP_X_FORWARDED_FOR']))) : $_SERVER['REMOTE_ADDR'];

    // prepare url parameters of request
    $moceanv2_get  = 'site='.urlencode('85');
    $moceanv2_get .= '&ip='.urlencode($ip);
    $moceanv2_get .= '&ua='.urlencode($ua);
    $moceanv2_get .= '&url='.urlencode(sprintf("http%s://%s%s", (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == TRUE ? "s": ""), $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
    $moceanv2_get .= '&zone='.urlencode('85');
    $moceanv2_get .= '&type=-1'; // type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad) or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
    $moceanv2_get .= '&key=1';
    //$moceanv2_get .= '&lat=1';
    //$moceanv2_get .= '&long=1';
    $moceanv2_get .= '&count=1'; // quantity of ads
    $moceanv2_get .= '&version='.urlencode('php_0001'); // php code version
    $moceanv2_get .= '&keywords='; // keywords to search ad delimited by commas (not necessary)
    $moceanv2_get .= '&whitelabel=0'; // filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
    $moceanv2_get .= '&premium=0'; // filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
    $moceanv2_get .= '&over_18=0'; // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
    $moceanv2_get .= '&paramBORDER='.urlencode('#000000'); // ads border color
    $moceanv2_get .= '&paramHEADER='.urlencode('#cccccc'); // header color
    $moceanv2_get .= '&paramBG='.urlencode('#eeeeee'); // background color
    $moceanv2_get .= '&paramTEXT='.urlencode('#000000'); // text color
    $moceanv2_get .= '&paramLINK='.urlencode('#ff0000'); // url color
    global $moceanv2_udid;
    $moceanv2_get .= $moceanv2_udid;

   
    if(MOCEANV2_MODE == "test") $moceanv2_get .= '&test=1';

    // send request
    $moceanv2_request = @fsockopen('ads.moceanads.com', 80, $errno, $errstr, 1);
    if ($moceanv2_request) {
        stream_set_timeout($moceanv2_request, 3000);
        $query = "GET /ad?".$moceanv2_get." HTTP/1.0\r\n";
        $query .= "Host: ads.moceanads.com\r\n";
        $query .= "Connection: close\r\n";


        // IIS support
        if(isset($_SERVER['ALL_HTTP']) && is_array($_SERVER['ALL_HTTP'])) {
            foreach ($_SERVER['ALL_HTTP'] as $name => $value) {
                $query .= "CS_$name: $value\r\n";
            }
        }
        elseif(isset($_SERVER['ALL_HTTP'])) {
            $array = explode("\n",$_SERVER['ALL_HTTP']);
            foreach ($array as $value) {
                if($value) {
                    $query .= "CS_$value\r\n";
                }
            }
        }

        foreach ($_SERVER as $name => $value) {
            $query .= "CS_$name: $value\r\n";
        }

        $query .= "\r\n";
        fwrite($moceanv2_request, $query);
        $moceanv2_info = stream_get_meta_data($moceanv2_request);
        $moceanv2_timeout = $moceanv2_info['timed_out'];
        $moceanv2_contents = "";
        $moceanv2_body = false;
        $moceanv2_head = "";
        while (!feof($moceanv2_request) && !$moceanv2_timeout) {
            $moceanv2_line = fgets($moceanv2_request);
            if(!$moceanv2_body && $moceanv2_line == "\r\n") $moceanv2_body = true;
            if(!$moceanv2_body) $moceanv2_head .= $moceanv2_line;
            if($moceanv2_body && !empty($moceanv2_line)) $moceanv2_contents .= $moceanv2_line;
            $moceanv2_info = stream_get_meta_data($moceanv2_request);
            $moceanv2_timeout = $moceanv2_info['timed_out'];
        }
        fclose($moceanv2_request);
        if (!preg_match('/^HTTP\/1\.\d 200 OK/', $moceanv2_head)) $moceanv2_timeout = true;
        if($moceanv2_timeout) return "";
        return $moceanv2_contents;
    }
}

?>
<?php

// copy this snippet elsewhere on your page for display more of ads
echo moceanv2_ad();

?>

PHP CURL install code

<?php
 
// change to "live" to disable demo mode and show real ads
define("MOCEANV2_MODE", "test");
 
function moceanv2_get_udid()
{
	$moceanv2_get = '';
    //check UID
    if ( isset($_COOKIE['MOCEAN_AD_UDID']) ) {
        if(setcookie('MOCEAN_AD_UDID', $_COOKIE['MOCEAN_AD_UDID'], time() + 60 * 60 * 24 * 7)) {
            $moceanv2_get .= '&udid='.urlencode($_COOKIE['MOCEAN_AD_UDID']);
        }
    } else {
        $udid = md5(time()+rand());
        if(setcookie('MOCEAN_AD_UDID', $udid, time() + 60 * 60 * 24 * 7)) {
            $moceanv2_get .= '&udid='.urlencode($udid);
        }
    }
    return $moceanv2_get;
}
 
$moceanv2_udid = moceanv2_get_udid();
 
function moceanv2_ad()
{
    $ua = $_SERVER['HTTP_USER_AGENT'];
    $ip = isset($_SERVER['HTTP_X_FORWARDED_FOR'...]) ? trim(reset(split(",", $_SERVER['HTTP_X_FORWARDED_FOR']))) : $_SERVER['REMOTE_ADDR'];
 
    // prepare url parameters of request
    $moceanv2_get  = 'site='.urlencode('85');
    $moceanv2_get .= '&ip='.urlencode($ip);
    $moceanv2_get .= '&ua='.urlencode($ua);
    $moceanv2_get .= '&url='.urlencode(sprintf("http%s://%s%s", (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == TRUE ? "s": ""), $_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"]));
    $moceanv2_get .= '&zone='.urlencode('85');
    $moceanv2_get .= '&type=3'; // type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad) or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
    $moceanv2_get .= '&key=1';
    //$moceanv2_get .= '&lat=1';
    //$moceanv2_get .= '&long=1';
    $moceanv2_get .= '&count=1'; // quantity of ads
    $moceanv2_get .= '&keywords='; // keywords to search ad delimited by commas (not necessary)
    $moceanv2_get .= '&whitelabel=0'; // filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
    $moceanv2_get .= '&premium=0'; // filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
    $moceanv2_get .= '&over_18=0'; // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
    $moceanv2_get .= '&paramBORDER='.urlencode('#000000'); // ads border color
    $moceanv2_get .= '&paramHEADER='.urlencode('#cccccc'); // header color
    $moceanv2_get .= '&paramBG='.urlencode('#eeeeee'); // background color
    $moceanv2_get .= '&paramTEXT='.urlencode('#000000'); // text color
    $moceanv2_get .= '&paramLINK='.urlencode('#ff0000'); // url color
    global $moceanv2_udid;
    $moceanv2_get .= $moceanv2_udid;
 
 
    if(MOCEANV2_MODE == "test") $moceanv2_get .= '&test=1';
 
    $sc_headers = array();
    foreach ($_SERVER as $name => $value) {
        $sc_headers[] = "CS_$name: $value";
    }
 
    // send request
    $url="http://ads.moceanads.com:80/ad?".$moceanv2_get;
    $timeout=3; //timeout in seconds
    $ch  = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $sc_headers);
    $html=@curl_exec($ch);
    @curl_close($ch);
    if($html!==false) return $html;
    else return "";
 
}
 
?>
<?php
 
// copy this snippet elsewhere on your page for display more of ads
echo moceanv2_ad();
 
 
?>

JS Install Codes

There are three types of install codes that can be used on the client side:

  1. JS 1.0 install code
  2. JS 2.0 Synchronous install code
  3. JS 2.0 Asynchronous install code

Notes for using JS install codes

Parameters acceptable by the JS 1.0 install code can be divided into three groups.

  1. Ad Serving Domain:
    • service: Url used for serving ads. By default "http://ads.moceanads.com/ad" will be used.
  2. Ad Request API Parameters:
    • site: App/Site ID
    • zone: ID of the zone on the site
    • type: Type of ads to be returned (for JS 1.0: 1 - text, 2 – image; for JS 2.0: 1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad). You can set different combinations with these values. For example, 3 = 1 + 2 (text + image). Default value is -1 which means that an ad of any type can be returned.
    NOTE: Any Ad Request API Parameter is accepted by the JS 1.0 install code except key (it requires key:6).
  3. Client-Side Parameters:
    • target: The link target; set to “_blank” if you want the clicked ad to open in a new window
    • defaultHtml: Default ad content that will be shown if no ad is returned from the server. This will not accept additional javascript. It only supports basic HTML.
    • clickPrepend: Whatever is here will be added verbatim to the beginning of all clickable urls. It is not recommended to use this parameter in case of rich-media ads.
    • pixelUrl: If this is set, the ad will make a call to the url when the ad is shown.
    • forceHTML: Forces ad to render as HTML.
    • img_width and img_height: In the case of an image (type:2) these settings will override the image's size. This is not recommended.

Please note that JS 2.0 install codes are built in such a way that client-side parameters are not supported. However, if you would like any additional parameter to be processed on your side, you may overload the adRequest2.render function as follows.

  • For JS 2.0 Synchronous install code:
<html>
<head>
    <script type="text/javascript" src="http://img.ads.moceanads.com/js/ad2/request.min.js"></script>
    <script type="text/javascript">//<!--
        // Here function override starts
        var originalRenderer = adRequest2.render;
        // Render function accepts two arguments: ad html code and object with additional parameters
        adRequest2.render = function(html, advars) {
        // Add clickPrepend functionality
        if (advars.clickPrepend) {
            html = html.replace(/(<a[^>]+href\s*=\s*[\'"]{0,1})/img, '$1' + advars.clickPrepend);
        }
        // Add pixedUrl functionality
        if (advars.pixelUrl) {
            img = new Image();
            img.src = advars.pixelUrl;
        }
        originalRenderer(html, advars);
    }
    // Here function overriding ends
    // Object with additional parameters can be passed to adRequest2 call
    //--></script> 
</head>
<body>
    <script type="text/javascript">//<!--
        adRequest2(
            "http://ads.moceanads.com/ad?site=410069&zone=1640083&type=-1", {'clickPrepend':'http://sample.com/', 'pixelUrl':'http://images.com/1.gif'}
        );
    //--></script> 
</body></html>


  • For JS 2.0 Asynchronous install code:
<html>
<head>
    <script type="text/javascript" async="async" src="http://img.ads.moceanads.com/js/ad2/request.async.min.js"></script>
</head>
<body>
    <!--
    // Copy following anywhere on your page you want to display an ad. Note that each
    // time you paste this, you can use different settings. Please see the wiki
    // (Mocean Ad Request API) for additional parameters.
    -->
    <div id="ads2_container_255065"><!-- maybe some loading text here --></div>
    <script type="text/javascript">//<!--<![CDATA[
        window._ads2 = window._ads2 || [];
        // START: overriding render function
        window._ads2.push(function(adRequest2) {
            var originalRenderer = adRequest2.render;
            adRequest2.render = function(html, advars) {
                // Add target element
                if (advars.target) {
                    html = html.replace('<a href', '<a target="' + advars.target + '" href'); 
                }
                originalRenderer(html, advars);
            }
        });
        // END: overriding render function
        window._ads2.push({
            "url": "http://ads.moceanads.com/ad?zone=355130&type=-1&target=_blank",
            "target":"_blank",
            "containerId": 'ads2_container_255065'
        });
    //]]>--></script>
</body></html>

JS 1.0 install code

Include in the head of your page:

<script type="text/javascript" src="http://img.ads.moceanads.com/js/mobile.js"></script>

Then, in any place you want an ad to appear, paste this code:

<script type="text/javascript">
AdRequest_({
    site:'9084',
    zone:'18344',
    service:"http://ads.mycompany.com/ad",
 
    /* 
      type of ads 
        1 = text 
        2 = image
        4 = richmedia ad
        8 = native ad
        16 = video ad
        32 = audio ad
      combination examples: 
        3 = 1+2 (text + image) 
    */
    type:"-1",  
    target:'', /* link target ex. _blank */
    defaultHtml:'', /* default ad instead of empty */
    clickPrepend:'', /* anything here will be prepended to the click url, for instance 'http://other-tracking.com/?redirect=' */
    pixelUrl:'', /* url for additional tracking */
    forceHTML:'' /* Forces ad to render as HTML, without interpreting incoming script */
});
</script>

Please see Notes for using JS install codes above to get more information about parameters used in JS install codes.

JS 2.0 Synchronous install code

Include in the head of your page:

<script type="text/javascript" src="http://img.ads.moceanads.com/js/ad2/request.min.js"></script>

You can review the script source code here: request.js source

Then, in any place you want an ad to appear, paste this code:

<script type="text/javascript">
adRequest2(
    "http://ads.moceanads.com/ad?site=410069&zone=1640083&type=-1"
);
</script>
NOTE: Each time you paste this, you can use different url. Please, see the wiki page for additional parameters.
NOTE: Please, encode strings correctly.

JS 2.0 Asynchronous install code

Include in the head of your page:

<script type="text/javascript" async="async" src="http://img.ads.moceanads.com/js/ad2/request.async.min.js"></script>

You can review the script source code here: request.async.js source

Then, in any place you want an ad to appear, paste this code:

<div id="ads2_container_1640083"><!-- Here may be some loading text --></div>
<script type="text/javascript">
window._ads2 = window._ads2 || [];
window._ads2.push({
    "url": "http://ads.moceanads.com/ad?site=410069&zone=1640083&type=-1",
    "containerId": 'ads2_container_1640083'
});
</script>
NOTE: Each time you paste this, you can use different url. Please, see the wiki page for additional parameters.
NOTE: Please, encode strings correctly.

JSP install code

<%@ page import="java.util.*,java.io.*,java.net.*, java.security.*, java.math.*" %>
<%
// copy this snippet elsewhere on your page for display more of ads
out.print(moceanv2_ad(request));
 
// copy this snippet elsewhere on your page for display advertise here link
// out.print('<a href="http://YOURNETWORK.moceanmobile.net/wap/landing/network/site_id/41369">Advertise Here</a>');
%>
<%!
 
// change to "live" to disable demo mode and show real ads
private static final String MOCEANV2_MODE = "test";
 
private String moceanv2_ad(HttpServletRequest request)
{
    StringBuilder moceanv2_contents = new StringBuilder();
    try {
 
        // prepare url parameters of request
        StringBuilder moceanv2_get = new StringBuilder();
        moceanv2_get.append("site=").append("85");
        moceanv2_get.append("&ua=").append(URLEncoder.encode(request.getHeader("User-Agent"), "UTF-8"));
        moceanv2_get.append("&ip=").append(URLEncoder.encode(request.getRemoteAddr(),"UTF-8"));
        moceanv2_get.append("&url=").append(URLEncoder.encode(request.getRequestURL().toString(), "UTF-8"));
        moceanv2_get.append("&zone=").append("85");
        moceanv2_get.append("&type=3"); // type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad) or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
        moceanv2_get.append("&key=1");
        //moceanv2_get.append("&lat=1");
        //moceanv2_get.append("&long=1");
        moceanv2_get.append("&keywords="); // keywords to search ad delimited by commas (not necessary)
        moceanv2_get.append("&whitelabel=0"); // filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel
        moceanv2_get.append("&premium=0"); // filter by premium status (0 - non-premium, 1 - premium only, 2 - both
        moceanv2_get.append("&country="); // country of visitor
        moceanv2_get.append("&region="); // region of visitor
        moceanv2_get.append("&size_required=0"); // if img size attributes are required
        moceanv2_get.append("&over_18=0"); // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
        moceanv2_get.append("&paramBORDER=").append(URLEncoder.encode("#000000", "UTF-8")); // ads border color
        moceanv2_get.append("&paramHEADER=").append(URLEncoder.encode("#cccccc", "UTF-8")); // header color
        moceanv2_get.append("&paramBG=").append(URLEncoder.encode("#eeeeee", "UTF-8")); // background color
        moceanv2_get.append("&paramTEXT=").append(URLEncoder.encode("#000000", "UTF-8")); // text color
        moceanv2_get.append("&paramLINK=").append(URLEncoder.encode("#ff0000", "UTF-8")); // url color
 
        if(MOCEANV2_MODE.equals("test")) moceanv2_get.append("&test=1");
        // send request
        BufferedReader moceanv2_reader = null;
        try {
            URL moceanv2_url = new URL("http://ads.moceanads.com:80/ad");
            HttpURLConnection moceanv2_request = (HttpURLConnection)moceanv2_url.openConnection();
            moceanv2_request.setRequestMethod("POST");
            moceanv2_request.setDoOutput(true);
            moceanv2_request.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            moceanv2_request.setRequestProperty("Content-Length", Integer.toString(moceanv2_get.length()));
            Enumeration e = request.getHeaderNames();
            if(e != null && e.hasMoreElements()) {
                while(e.hasMoreElements()) {
                   String hdr = (String) e.nextElement();
                   moceanv2_request.addRequestProperty("ch_"+hdr,request.getHeader(hdr));
                }
            }
            moceanv2_request.setConnectTimeout(3000);
            moceanv2_request.setReadTimeout(3000);
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(moceanv2_request.getOutputStream()));
            writer.write(moceanv2_get.toString());
            writer.close();
            moceanv2_reader = new BufferedReader(new InputStreamReader(moceanv2_request.getInputStream()));
            for (String line = null; (line = moceanv2_reader.readLine()) != null;)
                moceanv2_contents.append(line);
        } catch(java.net.SocketTimeoutException ste) {
              moceanv2_contents.append("");
        } catch (Exception e) {
 
        } finally {
            try {
                if(moceanv2_reader != null) {
                    moceanv2_reader.close();
                }
            } catch(Exception e) {
 
            }
        }
    } catch(Exception ex) {
 
    }
    return moceanv2_contents.toString();
}
%>


CGI/PERL install code

use LWP::UserAgent;
use URI::URL;
 
# copy this snippet elsewhere on your page for display more of ads
print moceanv2_ad();
 
sub moceanv2_ad
{
    # change to "live" to disable demo mode and show real ads
    my $moceanv2_mode = 'test';
 
    # prepare url parameters of request
    my $moceanv2_page_url = sprintf('http%s://%s%s',($ENVHTTPS ne '' ? 's': ''), $ENVHTTP_HOST, $ENVREQUEST_URI);
    my %moceanv2_get = (
        'site'        => 85,
        'ua'          => $ENVHTTP_USER_AGENT,
        'ip'          => $ENVREMOTE_ADDR,
        'url'         => $moceanv2_page_url,
        'zone'        => '85',
        'type'        => '3', # type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad) or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
        'key'         => '1',
        #'lat'         => '1',
        #'long'         => '1',
        'count'       => '1',
        'keywords'    => "", # keywords to search ad delimited by commas (not necessary)
        'whitelabel'  => '0', # filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
        'premium'     => '0', # filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
        'over_18'     => '0', # filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
        'paramBORDER' => '#000000', # ads border color
        'paramHEADER' => '#cccccc', # header color
        'paramBG'     => '#eeeeee', # background color
        'paramTEXT'   => '#000000', # text color
        'paramLINK'    => '#ff0000', # url color
 
    );
 
    $moceanv2_gettest = '1' if($moceanv2_mode eq 'test');
 
    # send request
    my $moceanv2_uri = URI::URL->new("http://ads.moceanads.com:80/ad");
    my $moceanv2_request = LWP::UserAgent->new;
    $moceanv2_request->timeout(3);
    my $moceanv2_response = $moceanv2_request->post($moceanv2_uri, \%moceanv2_get);
    if ($moceanv2_response->is_error()) {
        return "";
    } else {
        return $moceanv2_response->content();
    }
}


VB.NET install code

<%
    'copy this snippet elsewhere on your page for display more of ads
    Response.Write(moceanv2_ad())
 
%>
 
<script runat="server">
    Function moceanv2_ad() As String
 
        'change to "live" to disable demo mode and show real ads
        Dim MOCEANV2_MODE As String = "test"
 
        'prepare url parameters of request
        Dim moceanv2_get As StringBuilder = New StringBuilder()
        moceanv2_get.Append("site=").Append("85")
        moceanv2_get.Append("&ua=").Append(HttpUtility.UrlEncode(Request.UserAgent, Encoding.UTF8))
        moceanv2_get.Append("&ip=").Append(HttpUtility.UrlEncode(Request.UserHostAddress, Encoding.UTF8))
        moceanv2_get.Append("&url=").Append(HttpUtility.UrlEncode(Request.Url.ToString(), Encoding.UTF8))
        moceanv2_get.Append("&zone=").Append(HttpUtility.UrlEncode("85", Encoding.UTF8))
        moceanv2_get.Append("&type=3") 'type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad) or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
        moceanv2_get.Append("&keywords=") ' keywords to search ad delimited by commas (not necessary)
        moceanv2_get.Append("&whitelabel=0") ' filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
        moceanv2_get.Append("&premium=0") ' filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
        moceanv2_get.Append("&over_18=0") ' filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
        moceanv2_get.Append("&key=1")
        'moceanv2_get.Append("&lat=1")
        'moceanv2_get.Append("&long=1")
        moceanv2_get.Append("&count=1") 'quantity of ads
        moceanv2_get.Append("&paramBORDER=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)) 'ads border color
        moceanv2_get.Append("&paramHEADER=").Append(HttpUtility.UrlEncode("#cccccc", Encoding.UTF8)) 'header color
        moceanv2_get.Append("&paramBG=").Append(HttpUtility.UrlEncode("#eeeeee", Encoding.UTF8)) 'background color
        moceanv2_get.Append("&paramTEXT=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)) 'text color
        moceanv2_get.Append("&paramLINK=").Append(HttpUtility.UrlEncode("#ff0000", Encoding.UTF8)) 'url color
 
 
        If MOCEANV2_MODE = "test" Then moceanv2_get.Append("&test=1")
 
        'send request
        Dim moceanv2_contents As StringBuilder = New StringBuilder()
        Try
            Dim moceanv2_get_bytes As Byte() = System.Text.Encoding.UTF8.GetBytes(moceanv2_get.ToString)
            Dim moceanv2_request As System.Net.WebRequest = System.Net.WebRequest.Create("http://ads.moceanads.com:80/ad")
            moceanv2_request.Method = "POST"
            moceanv2_request.ContentType = "application/x-www-form-urlencoded"
            moceanv2_request.ContentLength = moceanv2_get_bytes.Length()
            moceanv2_request.Timeout = 3000
            Dim moceanv2_os As System.IO.Stream = moceanv2_request.GetRequestStream()
            moceanv2_os.Write(moceanv2_get_bytes, 0, moceanv2_get_bytes.Length())
            moceanv2_os.Close()
            Dim moceanv2_response As System.Net.HttpWebResponse = CType(moceanv2_request.GetResponse, System.Net.HttpWebResponse)
            Dim moceanv2_ios As System.IO.Stream = moceanv2_response.GetResponseStream()
            Dim moceanv2_reader As System.IO.StreamReader = New System.IO.StreamReader(moceanv2_ios)
            moceanv2_contents.Append(moceanv2_reader.ReadToEnd())
        Catch moceanv2_e As Exception
            moceanv2_contents.Append("")
        End Try
        Return moceanv2_contents.ToString()
    End Function
</script>


C# install code

<%
// copy this snippet elsewhere on your page for display more of ads
Response.Write(moceanv2_ad());
 
%>
<script runat="server">
 
// change to "live" to disable demo mode and show real ads
const string MOCEANV2_MODE = "test";
 
string moceanv2_ad()
{
    // prepare url parameters of request
    StringBuilder moceanv2_get = new StringBuilder();
    moceanv2_get.Append("site=").Append("85");
    moceanv2_get.Append("&ua=").Append(HttpUtility.UrlEncode(Request.UserAgent, Encoding.UTF8));
    moceanv2_get.Append("&ip=").Append(HttpUtility.UrlEncode(Request.UserHostAddress, Encoding.UTF8));
    moceanv2_get.Append("&url=").Append(HttpUtility.UrlEncode(Request.Url.ToString(), Encoding.UTF8));
    moceanv2_get.Append("&zone=").Append(HttpUtility.UrlEncode("85", Encoding.UTF8));
    moceanv2_get.Append("&type=3"); // type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad) or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
    moceanv2_get.Append("&key=1");
    //moceanv2_get.Append("&lat=1");
    //moceanv2_get.Append("&long=1");
    moceanv2_get.Append("&keywords="); // keywords to search ad delimited by commas (not necessary)
    moceanv2_get.Append("&whitelabel=0"); // filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
    moceanv2_get.Append("&premium=0"); // filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
    moceanv2_get.Append("&over_18=0"); // filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
    moceanv2_get.Append("&count=1"); // quantity of ads
    moceanv2_get.Append("&paramBORDER=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)); // ads border color
    moceanv2_get.Append("&paramHEADER=").Append(HttpUtility.UrlEncode("#cccccc", Encoding.UTF8)); // header color
    moceanv2_get.Append("&paramBG=").Append(HttpUtility.UrlEncode("#eeeeee", Encoding.UTF8)); // background color
    moceanv2_get.Append("&paramTEXT=").Append(HttpUtility.UrlEncode("#000000", Encoding.UTF8)); // text color
    moceanv2_get.Append("&paramLINK=").Append(HttpUtility.UrlEncode("#ff0000", Encoding.UTF8)); // url color
 
    if (MOCEANV2_MODE == "test") moceanv2_get.Append("&test=1");
 
    // send request
    StringBuilder moceanv2_contents = new StringBuilder();
    try {
 
        System.Net.WebRequest moceanv2_request  = System.Net.WebRequest.Create("http://ads.moceanads.com:80/ad");
        moceanv2_request.Method = "GET";
        moceanv2_request.Timeout = 3000;
        System.Net.HttpWebResponse moceanv2_response = (System.Net.HttpWebResponse)moceanv2_request.GetResponse();
        System.IO.StreamReader moceanv2_reader = new System.IO.StreamReader(moceanv2_response.GetResponseStream());
        moceanv2_contents.Append(moceanv2_reader.ReadToEnd().Trim());
    } catch (Exception) {
        moceanv2_contents.Append("");
    }
    return moceanv2_contents.ToString();
}
</script>


Ruby on Rails install code

<%
require 'net/http'
require 'uri'
require 'md5'
 
def moceanv2_ad(request)
 
    # change to "live" to disable demo mode and show real ads
    moceanv2_mode   = "test"
 
    # prepare url parameters of request
    moceanv2_get = {}
    moceanv2_get["site"]           = "7057"
    moceanv2_get["ua"]          = request.user_agent
    moceanv2_get["ip"]          = request.remote_ip
    moceanv2_get["url"]         = request.request_uri
    moceanv2_get["zone"]        = "12310"
    moceanv2_get["type"]        = "3" # type of ads (1 - text, 2 - image, 4 - richmedia ad, 8 - native ad, 16 - video ad, 32 - audio ad or a combination like 3 = 1+2 (text + image), 7 = 1+2+4 (text + image + richmedia), 15 = 1+2+4+8 (text + image + richmedia + native)
    moceanv2_get["key"]         = "1"
    #moceanv2_get["lat"]         = "1"
    #moceanv2_get["long"]         = "1"
    moceanv2_get["keywords"]    = ""  # keywords to search ad delimited by commas (not necessary)
    moceanv2_get["whitelabel"]  = "0" # filter by whitelabel(0 - all, 1 - only whitelabel, 2 - only non-whitelabel)
    moceanv2_get["premium"]     = "0" # filter by premium status (0 - non-premium, 1 - premium only, 2 - both)
    moceanv2_get["over_18"]     = "0" # filter by ad over 18 content (0 or 1 - deny over 18 content , 2 - only over 18 content, 3 - allow all ads including over 18 content)
    moceanv2_get["count"]       = "1" # quantity of ads
    moceanv2_get["paramBORDER"] = "#000000" # ads border color
    moceanv2_get["paramHEADER"] = "#cccccc" # header color
    moceanv2_get["paramBG"]     = "#eeeeee" # background color
    moceanv2_get["paramTEXT"]   = "#000000" # text color
    moceanv2_get["paramLINK"]   = "#ff0000" # url color
 
 
    moceanv2_get["test"]        = "1" if moceanv2_get == "test"
 
    # send request
    begin
        moceanv2_uri = URI.parse("http://ads.moceanads.com:80/ad")
        moceanv2_request = Net::HTTP::Post.new(moceanv2_uri.path)
        moceanv2_request.set_form_data(moceanv2_get)
        moceanv2_conn = Net::HTTP.new(moceanv2_uri.host, moceanv2_uri.port)
        moceanv2_conn.read_timeout = 3.0
        moceanv2_conn.open_timeout = 3.0
        moceanv2_response = moceanv2_conn.start {|moceanv2_http| moceanv2_http.request(moceanv2_request) }
        moceanv2_contents = moceanv2_response.body
    rescue Timeout::Error => te
        moceanv2_contents = ""
    rescue
        end
    moceanv2_contents
end
%>
<%=
    # copy this snippet elsewhere on your page for display more of ads
    moceanv2_ad(request)
%>


XHTML/WML install code

<div><a href="http://www.moceanmobile.net/adstatic.php?site=41369&zone=164183">Mobile Sites - click here!</a></div>

Ad Request API

Ad request: http://ads.moceanads.com/ad?zone=164183

Please see API documentation for parameters and usage.

NOTE: Ad request contains ad serving domain set for the network. 'ads.moceanads.com' is used by default.

Personal tools