Link Search Menu Expand Document


JavaScript Ad Tags


Last updated on August 10, 2020

You can add JavaScript tags (\<script\>) to an HTML ad request to:

  • Pass third-party parameters from custom apps, for example, by Android and iOS devices using the MoPub or DFP JavaScript tag integrations.
  • Define ad units.
  • Select and queue appropriate ads for the ad units.
  • Display the selected ads in the appropriate ad space.
  • Provide an iframe tag fallback if a browser has JavaScript disabled.
  • Automatically detect various parameters, such as the user’s screen resolution, which ad traffickers can target.
  • Specify standalone, ad unit group, and multi-ad unit requests.
  • Use a client-side impression counting mechanism.

While flexible, JavaScript tags are unforgiving if the resulting ad has bad syntax or formatting, which can negatively impact page rendering and layout.

JavaScript Tool Set

OpenX provides the following JavaScript tools to support customizable ad requests:

  • Asynchronous JavaScript tags. Runs in parallel with the execution of the page to deliver ads to a specified ad unit.
  • Synchronous JavaScript tags. Runs in series with the execution of the page loading to deliver ads to a specified ad unit.
  • OpenX JavaScript tag library: Supports customized ad requests and simplifies how parameter values are sent to the Ad Server. For example, you can use tag library methods to override certain parameters, specify fallback ads, and set third-party impression beacons for your JavaScript ad tags. The tag library is a small file downloaded to the user’s browser from the following path on your delivery server:http://delivery_server_domain/w/1.0/jstag

    The jstag file provides the following JavaScript methods:

    • Instance methods. Set distinct configuration or ad request parameters for a given instantiation of an OX object.
    • Static methods. Set global configuration values and manage global data sets in the OpenX JavaScript tag library.

The OpenX JavaScript Tag Library does not support all ad request parameters. For information about what parameters each method supports, see the corresponding reference page for the specific method.

JavaScript Tag Types

You can implement the following types of JavaScript tags:

Tag typeDescription
StandaloneRequest a single ad inline. OpenX supports three formats for standalone JavaScript ad tags:

   • Generated in the UI: Works in standard and third-party trafficking implementations. Stores ad request details in an OX_ads global array and uses OX_ads.push to add a new ad unit to the ad request queue. Use this method if you are sending the ad tag to a third-party to traffic in another ad server or for ad tags wrapped in a document.write() call.
   • Static method format: Uses the requestAd method to invoke an ad request and show the selected ad.
   • Instance method format: Uses OX instance methods to set up tag attributes, invoke the ad request, and display the appropriate ad.

For details, see Implementing standalone JavaScript tags.
Ad unit groupRequest ads for multiple ad units referenced in a single call by an ad unit group ID (pgid). This type of request is required for companion ad placement. You must use the OpenX UI or API to create ad unit groups.
Multi-ad unitRequests ads for multiple ad units in a single call and facilitate coordination between ad units, for example, competitive exclusion.