We’ve migrated our documentation to a new site, which means some URLs have changed.
Audience

Example 1 - Simple image ad

This example renders a single banner image ad:

image2012-7-5 15_8_44.png

Ad tag to be placed on the publisher page:

<!-- Ad tag begin -->
<div id="insertAdSpaceBeforeThis_000000000077eca4" style="display:none"></div>
<script type="text/javascript">
    (function() { try { var scriptEl = document.createElement('script'); scriptEl.type = 'text/javascript'; scriptEl.async = 'async';
    scriptEl.src = ('https:' == document.location.protocol) ? 'https://scdn.cxense.com/cx.js' : 'http://cdn.cxense.com/cx.js';
    var targetEl = document.getElementsByTagName('script')[0]; targetEl.parentNode.insertBefore(scriptEl, targetEl); } catch (e) {}; }());
</script>
<script type="text/javascript">
    var cX = cX || {}; cX.callQueue = cX.callQueue || [];
    cX.callQueue.push(['insertAdSpace', {
        adSpaceId:'000000000077eca4', //The ID of the AdSpace in the Admanager
        adUnitWidth: 728, adUnitHeight: 90, //hard-coded ad Unit size
        initialHorizontalAdUnits:1, initialVerticalAdUnits:1,
        renderTemplateUrl: 'TemplateExample1.html', // the render template reference - see the code block below
        k:'image', //a hard coded reference to a know Ad in the sandbox
        backend: 'sandbox' //remove for non-testing environments
 }]);
</script>
<!-- Ad tag end end -->


Template code "TemplateExample1.html":

<!DOCTYPE html>
<html>
<head>
    <title>Image ad template example</title>
    <style type="text/css">
        html, body { margin: 0; padding: 0; }
        .template { display: none; }
    </style>
</head>
<body>
 
    <!-- Include the cx.js script -->
    <script type="text/javascript" src="http://cdn.cxense.com/cx.js"></script>
 
    <!-- The ads are inserted into this div: -->
    <div id="adSpace">
 
        <!-- This is the invisible template that is used to instanciate the ad -->
        <div id="adsTemplate" class="template">
        <!--%
        var ads = data.searchResult.spaces[0].ads;
        for (var i = 0; i < ads.length; i++) {
            var ad = ads[i];
            %-->
            <a class="url" tmp:href="{{ad.clickUrl}}" target="_blank">
                <img tmp:src="{{ad.creative.source}}" border="0" width="728" height="90" alt=""/>
            </a>
            <!--%
         }
         %-->
       </div>
    </div>
 
    <!-- Insert AdSpace -->
    <script type="text/javascript">
        var cX = cX || {}; cX.callQueue = cX.callQueue || [];
        cX.callQueue.push(['insertAdSpace', {
            templateElementId: 'adsTemplate',
            targetElementId: 'adSpace',
            forwardHashArgs: true
        }]);
    </script>
</body>
</html>


JSON wire data:

{ "searchResult": {
    "pageNumber": 0,
    "contentBaseURL": "http://c803413.r13.cf2.rackcdn.com/",
    "actionBaseURL": "http://adserver.sandbox.cxad.cxense.com/adserver/action",
    "previous": "",
    "next": "",
    "spaces": [
        {
            "id": "000000000077eca4",
            "adUnitWidth": 728, "adUnitHeight": 90,
            "isVerticallyOriented": false,
            "ads": [
                {
                    "id" :"000000000077e2fe",
                    "creative": {
                        "type": "com.fastsearch.admomentum.plugins.imagecreative.feature.ImageCreativeFeature",
                        "formatVersion": "1.0",
                        "id": "000000000077e35e",
                        "contentServerId": "d39f0f8c77614aba5b65542f5c01318304474bd307c26b2300a98a6075c5bcbe.gif",
                        "source": "http://c803413.r13.cf2.rackcdn.com/d39f0f8c77614aba5b65542f5c01318304474bd307c26b2300a98a6075c5bcbe.gif",
                        "description": "Amazon AD",
                        "filename": "amazon.gif",
                        "spec": {
                            "height": 90,
                            "width": 728
                        },
                        "destinationUrl": "http://www.amazon.com"
                    },
                    "contextToken": "AAAAAAB37KQAAAAAAHfi)gAAAAAAd*Ne)sygKvGhQj*NRfiZPUl8Dw4wHzAuMDAxMjU1H0VVUgAAAAEAAAE4VzJmIQAAAAA(",
                    "clickUrl": "http://adserver.sandbox.cxad.cxense.com/adserver/click/AAAAAAB37KQAAAAAAHfi)gAAAAAAd*Ne)sygKvGhQj*NRfiZPUl8Dw4wHzAuMDAxMjU1H0VVUgAAAAEAAAE4VzJmIQAAAAA("
                }
            ]
        }
    ]
}}


Live example here:

http://dev1.cxpublic.com/templates/TemplateExample1_TestPage.html

Last updated: