JavaScript OX Static Methods
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 name | Description | Recommended placement in HTML source | Order |
---|---|---|---|
addVariable | Specify a key-value pair to add to all ad requests for the current page view. | Header | Before requestAd |
frameCreatives | Determine if creatives returned by that instance are framed (true). If not set, use the default provided by the OX object instance. | Body | Before requestAd |
load | Asynchronously request an ad for the ad unit and display it in the appropriate ad space. | Body | Before recordAction |
recordAction | Track conversions. | Body | N/A |
recordSegments | Assign users to or remove them from audience segments. | Body | N/A |
requestAd | Invoke 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. | Body | Before recordAction |
setGateway | Set the base URL for the ad gateway for all instances of an ad tag in the given document. | Header | Before requestAd |
setRefererURL | Indicates the referring URL for the current page view. | Header | Before 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
Parameter | Description | Required? |
---|---|---|
key , value | The 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"});
: TherequestAd
method, which must be passed afteraddVariable
.
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
Parameter | Description | Required? |
---|---|---|
auid | Ad unit ID for the ad to be displayed. | Yes |
fallback | The fallback ad to serve for the ad space when OpenX has no ad to serve for an ad request. | No |
frameCreatives | Determines if fetched creatives are framed or not (true /false ). | No |
imp_beacon | The third-party impression beacon to use when OpenX serves an actual ad. | No |
r | Click redirect URL. | No |
rd | The 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 |
ref | Referring URL. | No |
rm | The 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_id | ID of the element to render in. | No |
tg | The window target for anchors. | No |
tid | ID for content topic of the current page. | No |
url | Page URL. | No |
userid | Customer-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
Parameter | Description | Required? |
---|---|---|
auid | Ad unit ID of the ad to be displayed. | Yes |
r | Click redirect URL. | No |
ref | Referring URL. | No |
tg | The window target for anchors. | No |
tid | Content topic ID of the current page. | No |
url | Page URL. | No |
userid | User 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
Parameter | Description | Required? |
---|---|---|
add | The ID for the audience segment to add the user to. | Yes |
channel | Tracks the source of the audience segmentation calls (maximum of 16 UTF-8 characters). | No |
del | The ID for the audience segment to remove the user from. | Yes |
expires | Automatically disables the segmentation beacon after the specified date, using the format YYYY-MM-DD . | No |
userid | The 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
Parameter | Description |
---|---|
af | The 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. |
appBundle | The bundle (“package”) ID of a mobile app. |
appName | The name of a mobile app. |
appStoreURL | The app store URL for the app. |
auid (required) | Ad unit ID of the ad to be displayed. |
aumf | Ad unit’s market floor. |
aungf | Ad unit’s non-guaranteed floor price. |
coords | A geolocation coordinates object, which provides latitude, longitude, and (optionally) other properties. |
ifa | String value of the OS’s advertising ID. |
lmt | Notes whether or not limit ad tracking is enabled. |
fallback | The fallback ad to serve for the ad space when OpenX has no ad to serve for an ad request. |
frameCreatives | Determines if fetched creatives are framed (true /false ). |
gw | Gateway URL (delivery server) to use for this request. |
imp_beacon | The third-party impression beacon to use when OpenX serves an actual ad. |
md | Market disabled (disable OpenX Ad Exchange) for this ad request if set to true . |
ns | Disable audience segmentation for this ad request if set to true . |
openrtb | An object literal or JSON string representing an OpenRTB bid request. For more details, see setOpenRTBParameters . |
r | The click redirect URL. |
rd | 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. |
ref | Referring URL. |
rm | 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. |
tg | Target window in which to open clicked ads. |
tid | Content topic ID for the ad request. |
url | Page URL. |
userid | Customer-provided user ID. |
vars | Custom 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
Parameter | Description | Required? |
---|---|---|
url | URL 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
Parameter | Description | Required? |
---|---|---|
url | Referring URL of the page. | Yes |
Example
OX.setRefererURL("http://www.example.com");