Using the UnrulyX Native API

UnrulyX’s has a client side API (Application Programming Interface), The following callbacks are available to all publishers.

onFallback()

Called when no ad is returned from the UnrulyX exchange. This can be used to either execute additional javascript and/or write a javascript tag (such as a 1×1 tag) as a fallback. The returned string should be valid HTML, or empty string.

Args: None
Expected Return Value: String

Example

<script> 
  var unruly = window.unruly || {};
  unruly.native = unruly.native || {};
  unruly.native.placementId = "XXXX"; 
  unruly.native.onFallback = function(){
    return "<scr"+"ipt type='text/javascript' src='http://www.googletagservices.com/tag/js/gpt.js'>" + "googletag.pubads().definePassback('/network_ID/first_level_ad_unit/second_level_ad_unit', [1, 1]).display();" + "</scr" + "ipt>";
  }; 
</script>

onAdLoaded()

Args: None
Expected Return Value: No

Called when an ad has been returned from UnrulyX exchange. To configure the callback, add a property called onAdLoaded to your unruly.native object, pointing to a function that will be called only when a revenue delivering ad has been returned from the exchange. Below is an example Placement Tag using the onAdLoaded callback, again with placeholder values. When implementing your own onAdLoaded callback, you must use the Placement Tag given to you by your Unruly contact.

Example

<script> 
  var unruly = window.unruly || {};
  unruly.native = unruly.native || {}; 
  unruly.native.placementId = "XXXX";
  unruly.native.onAdLoaded = function(){ 
    //called when a revenue generating ad has been returned from the exchange
  }; 
</script> 
<script src="//video.unrulymedia.com/native/publisher­marker.js"></script> 

onAdDismissed()

Args: None
Expected Return Value: No

Called when an ad has been dismissed, either by the user or automatically. To configure the callback, add a property called onAdDismissed to your unruly.native object, pointing to a function that will be called only when the ad is dismissed. Below is an example Placement Tag using the onAdDismissed callback, again with placeholder values. When implementing your own onAdDismissed callback, you must use the Placement Tag given to you by your Unruly contact.

Example

<script> 
  var unruly = window.unruly || {};
  unruly.native = unruly.native || {}; 
  unruly.native.placementId = "XXXX";
  unruly.native.onAdDismissed = function(){ 
    //called when the ad is dismissed, either by the user or automatically
  }; 
</script> 
<script src="//video.unrulymedia.com/native/publisher­marker.js"></script> 

onFinished()

Args: None
Expected Return Value: No

Called when the native loader has finished fetching an ad from UnrulyX exchange. To configure the callback, add a property called onFinished to your unruly.native object, pointing to a function that will be called when the ad has either been displayed or cannot display an ad. Below is an example Placement Tag using the onFinished callback, again with placeholder values. When implementing your own onFinished callback, you must use the Placement Tag given to you by your Unruly contact.

Example

<script> 
  var unruly = window.unruly || {};
  unruly.native = unruly.native || {}; 
  unruly.native.placementId = "XXXX";
  unruly.native.onFinished = function(){ 
    //native loader has finished fetching an ad from the exchange, the will still be called if no ad is returned
  }; 
</script> 
<script src="//video.unrulymedia.com/native/publishermarker.js"></script> 

disclosureMessage

Value: String

Overrides the default disclosureMessage of Advertisement. Empty string removes the disclosure message.

Example

<script> 
  var unruly = window.unruly || {};
  unruly.native = unruly.native || {};
  unruly.native.siteId = 1234;
  unruly.native.disclosureMessage = "my custom disclosure message";
</script> 
<script src="//video.unrulymedia.com/native/native-loader.js"></script>