Link Search Menu Expand Document

PDF

JavaScript OX Static Methods

Publishers

Last updated on January 16, 2019


There is one global OX object per page. Use OX static methods to set global configuration values or to manage global data sets in the OpenX JavaScript tag library.

Note that the responses for these OX static methods are all void operations.

Method nameDescriptionRecommended placement in HTML sourceOrder
addVariableSpecify a key-value pair to add to all ad requests for the current page view.HeaderBefore requestAd
frameCreativesDetermine if creatives returned by that instance are framed (true). If not set, use the default provided by the OX object instance.BodyBefore requestAd
loadAsynchronously request an ad for the ad unit and display it in the appropriate ad space.BodyBefore recordAction
recordActionTrack conversions.BodyN/A
recordSegmentsAssign users to or remove them from audience segments.BodyN/A
requestAdInvoke a single ad request without the setup and use of an OX object. It fetches the ad for the ad unit and displays it in the appropriate ad space.BodyBefore recordAction
setGatewaySet the base URL for the ad gateway for all instances of an ad tag in the given document.HeaderBefore requestAd
setRefererURLIndicates the referring URL for the current page view.HeaderBefore requestAd

Static Methods Reference

This section contains reference documentation of all OX static methods listed above.


addVariable

Click to expand section


This method allows you to set a custom key-value pair (KVP) for all instances of the OX object. This way, you can set up a single, global KVP within a given pageview.

You must pass this method before the requestAd method.


Parameters

ParameterDescriptionRequired?
key, valueThe custom variable.Yes

Examples

OX.addVariable("gender","male");

Where gender is a custom key and male is a custom value.

A standalone JavaScript ad tag with the addVariable method might look like the following:

<script type="text/javascript"
src="http://delivery_server_domain/w/1.0/jstag">
</script>

<script type="text/javascript">
OX.addVariable("gender","male");
OX.addVariable("age","40");
OX.requestAd({"auid":"8"});
</script>

Where:

  • src="http://delivery_server_domain/w/1.0/jstag: A request to fetch the OpenX JavaScript tag library.

  • gender: A custom key.

  • male: A custom value.

  • age: Another custom key.

  • 40: Another custom value.

  • OX.requestAd({"auid":"auid"});: The requestAd method, which must be passed after addVariable.


frameCreatives

Click to expand section


This method determines the default framing behavior for ads loaded in the current page. You can override this behavior for specific instances or requests. The default value is false (disabled). These settings are overridden by features that add iframes automatically, such as auto-refresh.

Example

OX.frameCreatives(false);

load

Click to expand section


The load method:

  • Makes a single ad request and does not require setup and use of an OX object instance.
  • Accepts a JSON object of parameters to pass to the ad gateway.
  • Calls the gateway for an ad.
  • Writes it to the DOM using document.write().

Parameters

ParameterDescriptionRequired?
auidAd unit ID for the ad to be displayed.Yes
fallbackThe fallback ad to serve for the ad space when OpenX has no ad to serve for an ad request.No
frameCreativesDetermines if fetched creatives are framed or not (true/false).No
imp_beaconThe third-party impression beacon to use when OpenX serves an actual ad.No
rClick redirect URL.No
rdThe refresh delay, or primary trigger for refreshing an iframe, expressed in seconds (an integer ≥ 1). This overrides any server-side refresh delay setting for this ad unit or its container site.No
refReferring URL.No
rmThe maximum number of refreshes for ads displayed through the ad tag, expressed as a positive integer. For example, a value of 5 results in the display of 6 ads, including the initial display (non-refresh) and 5 subsequent displays (refreshes). This overrides any server-side refresh max setting for this ad unit or its container site.No
slot_idID of the element to render in.No
tgThe window target for anchors.No
tidID for content topic of the current page.No
urlPage URL.No
useridCustomer-provided user ID.No

Examples

OX.load({"auid":"1"});

load example with multiple parameters:

  OX.load({"auid":"12345",
    "tid":"4",
    "tg":"_top",
    "userid":"ABC",
    "r":"http://www.example.com",
    "imp_beacon":"<iframe src='myplace.com'></iframe>",
    "fallback":"<iframe src=/test/ads/468x60-unicef.gif></iframe>",
    "frameCreatives":"true"});

recordAction

Click to expand section


This method is reserved for use by JavaScript-based conversion tags. The recordAction method accepts a JSON array to pass to the gateway for tracking conversions.


Parameters

ParameterDescriptionRequired?
auidAd unit ID of the ad to be displayed.Yes
rClick redirect URL.No
refReferring URL.No
tgThe window target for anchors.No
tidContent topic ID of the current page.No
urlPage URL.No
useridUser ID to set in the request.No

Example

OX.recordAction({"cvid":"123"});

recordSegments

Click to expand section


Assign a user to an audience segment (using the add parameter), remove a user from an audience segment (using the del parameter), or both. This method accepts a JSON array, which can pass multiple segment IDs.


Parameters

ParameterDescriptionRequired?
addThe ID for the audience segment to add the user to.Yes
channelTracks the source of the audience segmentation calls (maximum of 16 UTF-8 characters).No
delThe ID for the audience segment to remove the user from.Yes
expiresAutomatically disables the segmentation beacon after the specified date, using the format YYYY-MM-DD.No
useridThe user ID to set in the request.No

Examples

To add the user to a segment:

OX.recordSegments({"add":"1","channel":"homepage"});

To remove the user from a segment:

OX.recordSegments({"del":"6"});

To simultaneously add users to and remove users from a segment:

OX.recordSegments({"add":"1,5,7", "del":"4,6,8"});

requestAd

Click to expand section


The requestAd method:

  • Makes a single ad request and does not require setup and use of an OX object instance.
  • Accepts a JSON object of parameters to pass to the ad gateway.
  • Requires the auid parameter. Its other parameters are optional.
  • Immediately calls the gateway for an ad.
  • Writes it to the DOM using document.write().

Parameters

ParameterDescription
afThe comma-delimited list of API frameworks supported on the user’s mobile device, which can be one or more of the following:

2 (VPAID 2.0)
3 (MRAID 1.0)
4 (ORMMA)
5 (MRAID 2.0)
6 (MRAID 3.0)
7 (OMID-1)

Note: This setting will be overridden by any API framework setting in the ad unit.
appBundleThe bundle (“package”) ID of a mobile app.
appNameThe name of a mobile app.
appStoreURLThe app store URL for the app.
auid (required)Ad unit ID of the ad to be displayed.
aumfAd unit’s market floor.
aungfAd unit’s non-guaranteed floor price.
coordsA geolocation coordinates object, which provides latitude, longitude, and (optionally) other properties.
ifaString value of the OS’s advertising ID.
lmtNotes whether or not limit ad tracking is enabled.
fallbackThe fallback ad to serve for the ad space when OpenX has no ad to serve for an ad request.
frameCreativesDetermines if fetched creatives are framed (true/false).
gwGateway URL (delivery server) to use for this request.
imp_beaconThe third-party impression beacon to use when OpenX serves an actual ad.
mdMarket disabled (disable OpenX Ad Exchange) for this ad request if set to true.
nsDisable audience segmentation for this ad request if set to true.
openrtbAn object literal or JSON string representing an OpenRTB bid request. For more details, see setOpenRTBParameters.
rThe click redirect URL.
rdRefresh delay or primary trigger for refreshing an iframe expressed in seconds (an integer ≥ 1). This overrides any server-side refresh delay setting for this ad unit or its container site.
refReferring URL.
rmMaximum number of refreshes for ads displayed through the ad tag, expressed as a positive integer. For example, a value of 5 results in the display of 6 ads, including the initial display (non-refresh) and 5 subsequent displays (refreshes). This overrides any server-side refresh max setting for this ad unit or its container site.
tgTarget window in which to open clicked ads.
tidContent topic ID for the ad request.
urlPage URL.
useridCustomer-provided user ID.
varsCustom key value pairs (KVPs) used to provide additional information about your ad space.

Examples

OX.requestAd({"auid":"1"});

requestAd example with multiple parameters:

OX.requestAd({"auid":"12345",
"tid":"4",
"tg":"_top",
"userid":"ABC",
"r":"http://www.example.com",
"ifa":"43043FE3-6BA9-4515-8209-6E0AC6AE1ADF",
"lmt":false,
"imp_beacon":"<iframe src='myplace.com'></iframe>",
"fallback":"<iframe src=/test/ads/468x60-unicef.gif></iframe>",
"vars":{"key1":"value1","key2":"value2"},
"frameCreatives":"true"});

setGateway

Click to expand section


This method sets the base URL of the ad gateway for all instances of the OX object in the current pageview.


Parameters

ParameterDescriptionRequired?
urlURL of the gateway communicating with the Ad Server.Yes

Example

setGateway setting the domain of the delivery server:

OX.setGateway("http://delivery_server_domain/w/1.0/");

setRefererURL

Click to expand section


Use this method to indicate the ‘referer’ URL of the page. In most cases, the OpenX JavaScript tag library detects the ‘referer’ URL of the page from the HTTP headers. In some cases, it is not possible to detect the ‘referer’ correctly, due of various browser security restrictions. You can call setRefererURL directly in these cases as necessary to override the value detected by the OpenX tag library.


Parameters

ParameterDescriptionRequired?
urlReferring URL of the page.Yes

Example

OX.setRefererURL("http://www.example.com");