This API allows access to advertising content from the Cxense Advertising platform either by using REST or Javascript as the transport protocol.
Basic Concepts
To receive advertising content, an advertising search (impression request) request needs to be made to the Cxense Advertising platform.
Cxense Advertising has two search API's that provide interfaces to request advertising content impressions:
-
the search REST API; and
-
the JavaScript search API.
The REST API provides an interface to make HTTP impression requests to the Cxense Advertising platform to receive results in HTML or XML form. The JavaScript API provides a method to embed a hook directly into content which makes an asynchronous call to the Cxense Advertising platform.
REST Search API
Impression Request
The default and only REST action is a GET on the Cxense Advertising REST search API.
The REST request requires the following form 1:
|
1 Impression requests will not fail without parameters. However, asId is mandatory for delivering impressions.
Requirements for (k=), (l=) and (cat=) depend on the matching criteria of the specified AdSpace in asId=.
Usage of the REST APIs will still record statistics (such as increased impression counts) and impact metrics used to rank the ad (such as click through rate). To avoid this, you can use the sandbox environment. Please contact the Cxense Advertising customer support team for access.
Search Parameters
Each REST API search request accepts parameters.
|
Parameter |
Description |
Default |
Example |
Mandatory |
|---|---|---|---|---|
|
|
AdSpace Id. The identifier of the advertising space that impressions are for. |
n/a |
|
Yes |
|
|
Media format. The media type for the response. |
|
|
No |
|
|
Keywords. The keywords to use as matching criteria. Individual keyword parmeters (' |
n/a |
|
No |
|
|
Context. The "context" for the request, often a URL. |
n/a |
|
No |
|
|
Category. Specifies the registered category name that this advertisement will match. |
n/a |
|
No |
|
|
Location. The location to use as matching criteria. |
n/a |
|
No |
|
geo |
Geo location. The coordinates to use as geospatial matching criteria. Format is latitude,longitude,distance/accuracy in km's. |
n/a |
geo=-37.6832,144.583,1 |
No |
|
|
Pagination works in two modes:
If you wish to use render templates you must control pagination manually as the adserver is unable to determine whether creatives will fit in your allocated space. |
n/a |
|
No |
|
|
Language. The languages in which results apply. ISO language code. |
n/a |
|
No |
|
|
User ID. Typically set to a session ID from your application server. Automatically set if you are using the JavaScript tag. |
n/a |
|
No |
|
Destination URL prefix. This can be added to do click tracking. Will be prepended to the destination URL |
n/a |
|
No |
|
|
Set this flag to true to get HTTPS-versions of click URLs and content URLs |
|
|
No |
|
|
The function name for the jsonp callback. Note that the media type (via the |
n/a |
|
No |
|
|
The The |
n/a |
|
No |
|
|
Filters the duration of video creatives. The values are in milliseconds. |
n/a |
|
No |
|
tzo |
(Optional) The Timezone the request is being made for, in minus minutes (I.e. Melbourne is GMT+10, so we would pass in -600) |
Obtained from the clients browser by Javascript |
tzo=-600 (Melbourne is 10 hours ahead of UTC) |
No |
Parameter Constraints
|
Parameter |
Constraint |
|---|---|
|
|
If an impression request application is likely to have greater than 10 unique keyword parameter terms, parameter strings must be broken into multiple ' For example:
has 12 terms in the keyword string: ' should be re-written as: ' Care must be taken to choose logical boundaries if specifying multiple ' Impression search terms greater than 10 for end-user typed terms issued as direct values for the ' An example might be where you map the navigated location of your site onto keyword terms e.g. 'Home -> Products -> Electronics -> Computer -> Laptop -> Home -> Gaming -> Intel i7' Concatenating the above as terms to user inputted keyword terms may trigger this constraint. |
Look and Feel Parameters
The look and feel for advertising content returned by the Cxense Advertising REST API can be customized. As with the search parameters described above, look and feel parameters can also be applied globally or to individual AdSpaces.
|
Parameter |
Description |
Default |
Example |
|---|---|---|---|
|
|
The ad colour. Standard text colour for text ads. |
rgb(156,156,156) |
|
|
|
The ad margin. This contains the margin to place
|
|
|
|
|
The background colour for the presentation. Useful for
|
rgb(255,255,255) |
|
|
|
The link colour. This is the colour applied to the
|
|
|
|
|
The title colour for the ad. This is the first line of
|
|
|
|
|
The link title emphasis colour. This is invoked for
|
|
|
|
|
Ad text alignment (CSS text-align). All valid CSS values
|
|
|
|
|
Base font to use for all text in the ad (CSS font shorthand property).
|
|
|
|
|
Font to use for title text in the ad (CSS font shorthand property).
|
|
|
|
|
Font to use for link text in the ad (CSS font shorthand property).
|
|
|
|
|
Text decoration to use for all text in the ad (CSS text-decoration).
|
|
|
|
|
Text decoration to use for title text in the ad (CSS text-decoration).
|
|
|
|
|
Text decoration to use for link text in the ad (CSS text-decoration).
|
|
|
|
|
Font weight to use for ad text with emphasis (see above) (CSS font-weight).
|
|
|
|
|
Font weight to use for ad title text with emphasis (CSS font-weight).
|
|
|
Impression Result
|
Element |
Attribute |
Description |
|---|---|---|
|
|
|
The impression search result container. |
|
|
|
The page number in the result set. |
|
|
|
For navigation of the result set. See the |
|
|
|
The matched space impression details. |
|
|
|
The AdSpace identifier provided by |
|
|
|
The matched ad impression sequence for the page. |
|
|
|
An impression instance. |
|
|
|
The unique identifier for the ad. |
|
|
|
An instance of the available Creative Templates described below. |
|
|
|
The URL to that, if clicked, will register a click event to be processed. |
Impression Result XML Format:
|
Ad Result Types
An ad impression has a Creative Template type:
-
Text
-
Image
-
Flash
-
Combo
-
Third Party
Note: If creating a smart-phone app or any other customer-facing interface that cannot be updated easily, be sure that the interface you're creating can handle all the different ad formats that your campaign is likely to use.
Common Creative XML Elements and Attibutes
|
Element |
Attribute |
Description |
|---|---|---|
|
|
|
An instance of a Creative Template type |
|
|
|
Version of the Creative Template type |
|
|
|
Unique identifier for the creative instance. |
|
|
|
The URL to request on click of the ad. |
|
|
|
The base URL to which you can append the content ID to form a complete reference to the media to display. Note that you can simply concatenate the ID to the base URL (the base URL will always end in a trailing slash or other valid terminator). |
Text Creative
|
Element |
Attribute |
Description |
|---|---|---|
|
|
|
The text creative title |
|
|
|
The sequence of content lines for the creative. |
|
|
|
Content on a Text Creative template may have several content lines. |
|
|
|
The URL to render for display. |
Text Creative Template XML Format:
|
Image Creative
|
Element |
Attribute |
Description |
|---|---|---|
|
|
|
CDN location of image creative. |
|
|
Complete URI of the image creative. |
|
|
|
Description of the uploaded creative file. |
|
|
|
The file name of the creative uploaded. |
|
|
|
The Image Creative Template specifications. |
|
|
|
Height dimension of the creative. |
|
|
|
Width dimension of the creative. |
Image Creative Template XML Format:
|
Flash Creative
|
Element |
Attribute |
Description |
|---|---|---|
|
|
|
Flash creative's location on CDN. |
|
|
Flash creative's back-up image location on CDN. |
|
|
Complete URI to the Flash creative. |
|
|
Complete URI to the Flash creative's back-up image. |
|
|
|
Description of the uploaded creative file. |
|
|
|
The file name of the creative uploaded. |
|
|
|
The file name of a backup image for the Flash creative. |
|
|
|
The Image Creative Template specifications. |
|
|
|
This will be blank once Error rendering macro 'jira' : com.atlassian.confluence.macro.MacroExecutionException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target is deployed into production.
|
|
|
|
Height dimension of the creative. |
|
|
|
Width dimension of the creative. |
|
|
|
Maximum upload file size [KB]. |
|
|
|
Contains version information about respective |
|
|
|
The lookup key for the version. |
|
|
|
The numeric version of Flash. |
|
|
|
Number of frames per second. |
|
|
|
The lookup key for the frameRate. |
|
|
|
The numeric number of frames per second. |
Flash Creative Template XML Format:
|
Combo Creative
|
Element |
1st Level Attribute |
2nd Level Attribute |
Description |
|---|---|---|---|
|
|
|
|
The combo creative title |
|
|
|
|
The sequence of content lines for the creative. |
|
|
|
|
Content on a Text Creative template may have several content lines. |
|
|
|
|
A container for each of the uploaded images. |
|
|
|
|
A container for each of the uploaded image's information. |
|
|
|
|
Name of the image. |
|
|
|
|
CDN location of the combo creative's image. |
|
|
|
|
Complete URI of the combo creative's image. |
|
|
|
|
The file name of the uploaded images. |
|
|
|
|
Height dimension of the creative. |
|
|
|
|
Width dimension of the creative. |
Combo Creative Template XML Format:
|
Example
http://adserver.cxad.cxense.com/adserver/search?media=html&k=white&asId=0000000000027f7a&lf-lc=gray&lf-am=10%2010%2010%2010&cat=0000000000002735
HTML Result payload:
|
XML Result payload:
|
Third-Party Creative
|
Element |
1st Level Attribute |
2nd Level Attribute |
Description |
|---|---|---|---|
|
|
|
|
The third-party creative title |
|
|
|
Complete URI of the first image found in a third-party creative (unlike for other creatives, this image will not be found on the CDN as it will be hosted by a third-party) |
|
|
|
Complete URI of the first image found in a third-party creative. |
|
|
|
|
A container for the fields of data inputted for the third party. |
|
|
|
|
The field name and raw data inputted. |
|
|
|
|
A container for the third party data that has been extracted from the data inputted. |
|
|
|
|
A container for each of the third-party images that have been extracted from the third party data. |
|
|
|
|
The third-party image's source. |
|
|
|
|
The third-party image's width. |
|
|
|
|
The third-party image's height. |
|
|
|
|
The third-party image's alt text. |
|
|
|
imgBorder |
The third-party image's border. |
|
|
|
The URL for the click. |
Third-Party Creative Template XML format:
|
JavaScript Cxense Advertising Search API
The JavaScript search API provides a method to make advertising search requests directly from content e.g. an HTML web page would have the JavaScript embedded into the appropriate location to render advertising content returned by the search.
The JavaScript search API makes an asynchronous call to the Cxense Advertising platform to optimize the experience of the user with the native content of the page.
The initial JavaScript code snippet to use can be obtained from the applicable Publishing space AdSpace Script tag. The script snippet has two script elements that:
-
loads the core cX JavaScript library; and
-
inserts an AdSpace into the host content.
The script works for both HTTP and HTTPS pages. The schema selection is automatic, so it does not need to be configured. Also refer to our Advanced javascript examples page for information on template-driven rendering for ad presentation.
The script which loads the Cxense Advertising JavaScript library of functions need not be changed and should be inserted into host content as is. An example of this script is as follows:
|
Each snipped copied from the AdSpace definition from the Cxense Advertising UI will include the above script to load the cX JavaScript library. If multiple AdSpaces are inserted into host content, the above script snippet need only be inserted once; however, separation of the the load script is not required.
The code snippet obtained from the Cxense Advertising UI also includes the AdSpace insertion call insertAdSpace is shown below:
|
The code above asynchronously executes the a call to search Cxense Advertising platform for advertising impressions. The result, should there be criterion matches for the AdSpace will be the default HTML result containing the ads. The advertising result format is defined in the Cxense Advertising REST API definition.
The insertAdSpace call in the AdSpace insertion script above contains the following parameters. None of the parameters require modification from the code snipped copied from the Cxense Advertising UI, but are as follows for reference:
|
Parameter |
Description |
Default |
|---|---|---|
|
|
The AdSpace identifier |
n/a - obtain from the UI. Does not change. |
|
|
(Optional) The width per ad unit in the result set |
0 |
|
|
(Optional) The height per ad unit in the result set |
0 |
|
|
(Optional) Defines the anticipated number of units to receive on the dimension 1 |
0 |
|
|
(Optional) Defines the anticipated number of units to receive on the dimension 1 |
0 |
|
(Optional) Absolute sizing option. Use this if the adspace has a size that is not a multiple of the adUnitWidth |
N/A |
|
(Optional) Absolute sizing option. Use this if the adspace has a size that is not a multiple of the adUnitHeight |
N/A |
|
(Otional) The Cxense Advertising platform backend to use. Can be either "production" or "sandbox". |
"production" |
|
(Optional) Delay the ad space impression and rendering until the ad space becomes visible (scrolled into view) |
false |
|
(Optional) The id of any element to append the ads into in the DOM tree |
N/A |
|
(Optional) The id of any element to insert the ads before in the DOM tree2 |
Defaults to an element with id: 'insertAdSpaceBeforeThis_' + adSpaceId (used to be 'scriptForAdSpace_' + adSpaceId, and that will still work (backwards compatible)) |
|
|
(Optional) Set to true to allow text content to overflow the ad unit size in the vertical direction. |
false |
|
(Optional) Reference to a function that will received a callback when receiving impressions results |
N/A |
|
(Optional) The URL of the render template to use for the layout of the ad space |
N/A |
|
(Optional) Use the URL hash fragment on IE6 and IE7 for cross-frame messaging |
false |
|
(Optional) Use the render template that has been mapped to this adSpaceId in the Render Template Mapper |
false |
|
|
(Optional) The Cxense Advertising platform REST URL to use. If possible, use the "backend" paremeter instead. |
The Cxense Advertising platform URL on which the space was created e.g. production/sandbox/dev/demo |
|
|
(Optional) Same as above, but for HTTPS. If possible, use the "backend" paremeter instead. |
The Cxense Advertising platform HTTPS URL on which the space was created e.g. production/sandbox/dev/demo |
1 The number of units will be constrained by the original AdSpace creation.
2 The adspace is inserted before the element (not inside) to avoid size contraint problems with elements that have default styles specifying margins and padding.
Specifying Cxense Advertising search API Parameters
The default AdSpace insertion JavaScript snippet obtained from the UI can be modified to include additional Cxense Advertising REST API parameters. Parameters can be added:
-
Globally; or
-
To individual AdSpace insertion requests.
The example AdSpace insertion above does not include REST API parameters: an AdSpace associated to a CPM product need not have parameters for example. However, REST API parameters can be added to the JavaScript executed request. The following example shows global parameters set using the variable cx_props.
-
Targeting parameters
-
k, keyword -
cat, category
-
-
Look and Feel parameters
-
lf-am, ad margin -
lf-ac, ad color
-
Whether an lf- parameter is set globally or by individual space insertion, the name of the lf- parameters used in the JavaScript API must be quoted. e.g.
'lf-lc':'red'
The effect of adding the cx_props variable is that all AdSpaces inserted into the host content by the JavaScript API will have the same parameters appliet to their Cxense Advertising REST API request i.e. Similar to
http://adserver.cxad.cxense.com/adserver/search?media=html&k=white&asId=0000000000027f7a&lf-lc=red&lf-am=10%2010%2010%2010&cat=0000000000002735
|
Alternatively, parameters can be added directly to an individual AdSpace insertion script as follows:
|
Specifying keywords
Keywords can be added to the ad search request by setting the 'k' property:
|
The keywords property can also be set on each AdSpace individually:
|
Customising the look and feel of results.
Customising the look and feel of search results is done by adding parameters to the request for ads. The actual parameter names/details are outlined in ImpressionRequest. The actual provision of these parameters is done through the JavaScript code currently inserted into the publishers page. The code snippet below shows how these parameters can be supplied. All of these parameters are optional as we have our default colour scheme that is used, however if the publisher wishes to change the presentation they can feel free to do so.
Parameters are prefixed with "lf-" for "look and feel" to hopefully prevent any clashes with ActionConstant values used by search. Basic details are listed below for each of the current parameters however the JavaDoc for ImpressionRequest should be consulted for the most up-to-date information.
-
lf-ac: the ad colour. Standard text colour for text ads. -
lf-am: the ad margin. This contains the margin to place around each ad being presented. Defaults to 0 if nothing is supplied. -
lf-bg: the background colour for the presentation. Useful for setting a "site specific" colour so the ad presentation blends with the publisher's site. -
lf-lc: the link colour. This is the colour applied to the destination/display URL for the ad. -
lf-tc: the title colour for the ad. This is the first line of a text creative. -
lf-tmc: the link title emphasis colour. This is invoked for matching criteria highlighting within an ads content. It has to be a different colour as the title is set to bold and there is no other way to define differentiate between matching criteria substitutions and the standard title text.
|
The look and feel can also be set on each AdSpace individually:
|
Setting query parameter from URL parameter
In a setting where you are adding ads to a search page, you might want to pass on the query that the user has typed in to the adserver.
You can pass the query in the 'k' parameter. If you have the user's query in a URL parameter, it can be read out and passed along to the adserver like this:
|
Controlling ad space resizing
In the normal case, the ad space is rendered in an IFrame with an initial size, and after the ad impression results have been received from the ad server, the iframe is resized to fit the number of ads returned.
You can control the resizing of an iframe by two methods:
-
The "resizeToContentSize" parameter
-
In a custom onImpressionResult handler function
The iframe is always resized. The difference is the method used to resize it.
Normal resizing
In the normal case, it is the number of ads returned that controls the resizing. The size is calculated from the number of ads like this:
If the adspace is horzontal, calculate new width:
-
new width = number of ads returned * (adUnitWidth + marginLeft + marginRight)
If the adSpace is vertical, calculate new height.
-
new height = number of ads returned * (adUnitHeight + marginTop + marginBottom)
And so the adSpace resizes to a new size that is a multiple of the ad unit height or width + margins.
The "resizeToContentSize" flag
But in some cases, the returned ads have different heights. This can happen if one ad has just one line of text, but the second ad has three lines of text.
The "resizeToContentSize" flag specifies that:
-
Each ad unit is sized with a minimum height of adUnitHeight (and not a fixed height)
-
The new height is the sum (not the multiple) of the ad heights for the individual ads
E.g, if I have two ads returned, and the first has one line of text and the second ad has three lines of text:
-
Ad1: 1 line of text, height: 40px;
-
Ad2: 3 lines of text, height: 62px;
Then, when the "resizeToContentSize" is set to true, the adSpace is resized to the size of the actual content, and not the number of ads,
and in this case that becomes:
-
new height = height of ad1 + height of ad2 = 40px + 62px = 102px
Custom resizing
If you do not want the resizing to happen at all, you can do like this:
|
Also, you can do any other type of resizing in this handler, like:
-
Resize the content in a different way
-
Resize other element (like outer frames or border objects) as well as the iframe (return true or no return to keep default sizing of the iframe).
Specifying the target window / frame for ad clicks
This function is now available within the Adspace configuration page (Publishing > Folder > AdSpace > Configuration), as such, this functionality is no longer required to manually set.
The target of an ad click can be set with the clickTargetFrame parameter. As describe above, it can be set globally or on an individual AdSpace.
The value can be any of the standard HTML special names (e.g. "_blank", "_top", etc.) or any name of a frame, iframe or window.
The default value is "_top".
|
Opening a custom-styled window in the onclick handler
Sometimes it's desirable to let an ad open the destination URL in a custom-styles window / popup when clicked.
That can be set by providing the wanted styling in the following parameter:
|
The windowName and openSpecs parts are the same as with any normal call top window.open(..):
Adding some sample values, gives something like:
|
Note that this will work only on text and image creatives. Flash will take the click event and it's up to the Flash ad how to deal with the click.
Adding custom publisher click tracking
A custom click tracker can be added by setting the "destinationUrlPrefix" parameter (or the short-form "dup").
The value if this parameter will be prepended to the destination URL. The concatenation is done by just putting the one string in front of the other. No escaping is performed.
|
If the original destination URL is "http://advertiser1.com/" then the browser will be redirected to the URL:
The click tracker must extract the real destination URL, and finally redirect the browser to this URL.
Passing custom variables from publisher page through to destination URL
Custom parameters can be passed through to the destination URL by setting the "destinationUrlParameters" property:
|
or
|
The custom parameters are added to the configured destination URL, and the resulting request will look like this:
|
The system automatically handles whether it should use "?" or "&" for the first parameter.
NB! In the current release, the destination URL cannot have it's URL path component completely missing (to make sure that a valid URL is constructed). The URL path can be as short as just "/", but is must be present.
Examples:
-
Good: "http://a.com/", "http://a.com/a", "http://a.com/a.html", "http://a.com/a.jsp?b=1&c=2"
-
The only bad: "http://a.com" (URL path component completely missing)