Ad Tags and Testing

Finding the Ad Tag

Once your ad unit has been saved, the ad tag can be obtained from the ‘View Ad Tag’ link, next to the ad unit name on the edit ad unit page. (Monetization > Websites & Ad Units > Website name > Ad Unit name > View Ad Tag )

https://s.yimg.com/oo/cms/products/flurry-docs/publisher/images/view_ad_tag_453a4621e.png

Loading the Ad Tag

All of the ad tags listed here should be loaded with within the <body>...</body> tags; they should not be placed the <head> section.

Standard Ad Tag

This ad tag will work when hardcoded directly on the page. It will not work for SafeFrames or when sandboxed, please use the safeFrame ad tag

Remember for “Replace” tags which use <div> tags to set the ad position, the <div> tag also needs to be hardcoded on the page:

<div class="native-ad-{adUnitCode}"></div>

Example Flurry Ad Tag

<script type="text/javascript">
window.native = window.native || [];
window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");
window.apiKey = "P55VS9SY2WQXH7TTF5ZW";

(function(d) {
  var script = d.createElement("script");
  script.async = true;
  script.src = "https://s.yimg.com/dy/ads/native.js";
  d.body.appendChild(script);
})(document);
</script>

Requesting multiple ad units

To request more than one ad unit per page, you should ideally combine the ad tags into one. To do this you take the value of window.native.push(“…”) from each ad unit and combine them into one JavaScript Ad Tag.

For example this ad tag is requesting 2 ad units on the same page, using only one ad tag:

<script type="text/javascript">
window.native = window.native || [];
window.native.push(
  "833b5519-edb7-47c0-88be-1152bcae7870",
  "921c5211-dca9-12e1-76be-4d41ba3e3811"
);
window.apiKey = "P11VS9SY2WQXH7TTF5ZY";

(function(d) {
  var script = d.createElement("script");
  script.async = true;
  script.src = "https://s.yimg.com/dy/ads/native.js";
  d.body.appendChild(script);
})(document);
</script>

Self-injecting Ad Tag

These ad tags automatically insert the required <div> tag for “Replace” ad units. These should only be used when you can guarantee the ad tag will be placed exactly where the ad should appear. If you decide to use this approach for multiple replace placements on the page, the script id value must be incremented for each new block.

Important: The adUnitCode values in these two lines must be updated with the values for your ad unit and must match:

  • window.native.push(“833b5519-edb7-47c0-88be-1152bcae7870”);

  • container.className = “native-ad-833b5519-edb7-47c0-88be-1152bcae7870”;

These tags will insert the ad immediately above where the ad tag is placed on the page.

<script type="text/javascript" id="native-1">
var scriptId = document.getElementById("native-1");
var scriptIdParent = scriptId.parentNode;
var container = document.createElement("div");
container.className = "native-ad-833b5519-edb7-47c0-88be-1152bcae7870";
scriptIdParent.insertBefore(container, scriptId);

window.native = window.native || [];
window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");
window.apiKey = "P11VS9SY2WQXH7TTF5ZY";

(function(d) {
  var script = d.createElement("script");
  script.async = true;
  script.src = "https://s.yimg.com/dy/ads/native.js";
  d.body.appendChild(script);
})(document);
</script>

For Google Ad Manager (DFP) implementations use the following tag format:

<script type="text/javascript">
 var win = window.top;
 var doc = win.document;
 var frameElementId = window.frameElement.id;
 var frameElement = doc.getElementById(frameElementId);
 var frameElementParent = frameElement.parentNode;
 var container = doc.createElement("div");
 container.className = "native-ad-833b5519-edb7-47c0-88be-1152bcae7870";
 frameElementParent.insertBefore(container, frameElement);

 win.apiKey = "P11VS9SY2WQXH7TTF5ZY";
 win.native = win.native || [];
 win.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

 var script = doc.createElement("script");
 script.async = true;
 script.src = "https://s.yimg.com/dy/ads/native.js";
 doc.body.appendChild(script);
 frameElement.style.display = "none";
 </script>

SafeFrame Ad Tag

If rendering of the ad must happen within an iframe (e.g. for security reasons) the script will require you set window.publisherUrl (note: this must match one of the URLs added to the website record). The ad unit should also be set to use “Replace” method of insertion but you will not need to create a placeholder element for iframe units. The script will automatically create a container element inside the frame to render the native ad placement to.

 <script type="text/javascript">
 window.native = window.native || [];
 window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

 window.apiKey = "P55VS9SY2WQXH7TTF5ZW";
 window.publisherUrl = "https://yourdomain.com/";

 (function(d) {
   var script = d.createElement("script");
   script.async = true;
   script.src = "https://s.yimg.com/dy/ads/native.js";
   d.body.appendChild(script);
 })(document);
</script>

AMP Ad Tag

Native ad units can be loaded in AMP using the <amp-embed> element (note it requires a width and height value). The values for data-key, data-code and data-url can be obtained from the default ad tag found in the edit ad Unit page. The value of data-key should match the apiKey value, dataCode should match the adUnitCode value found in the default ad tag under the array push (window.native.push("{adUnitCode}") ), and the value of data-url should be a URL matching one of the URLs added to the website record). The ad unit should be set to use “Replace” method of insertion but you will not need to create a placeholder element.

Example

<amp-embed width="400" height="400"
   type="yahoonativeads"
   data-key="P55VS9SY2WQXH7TTF5ZW"
   data-code="833b5525-edb7-47c0-88be-1152bcae7870"
   data-url="https://techcrunch.com">
 </amp-embed>

Note: if you are using Google Ad Manager (GAM) to insert ads on your AMP pages you should use the safeFrame ad tag.

Universal Module Loading

We support all the standard module definitions AMD, ESM, CJS and browser. The values for code and apiKey can be found in the default ad tag located at the top of the edit ad Unit page

AMD Example

<script src="require.js"></script>
<script>
 requirejs(['https://s.yimg.com/dy/ads/native.js'], function(native) {
 native.load({
  code: '833b5525-edb7-47c0-88be-1152bcae7870',
  apiKey: 'P55VS9SY2WQXH7TTF5ZW'
  });
 });
</script>

ESM Example

import Native from './native';

Native.load({
 apiKey: 'P3VYQ352GKX74CFTRH7X',
 code: 'dc1bd112-8be4-4606-99f4-414932c9b82a'
 });

Ad Feedback

Ad feedback enables users to dismiss and provide feedback on specific ads. To enable ad feedback on an ad unit, add the enableAdFeedback property to your section config of your JS snippet. This feature is Optional and not required.

Change:

window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

To:

window.native.push({
 code: "833b5519-edb7-47c0-88be-1152bcae7870",
 enableAdFeedback: true;
});

If enabled, an icon will appear in the upper right-hand corner while hovering over the ad on desktop, but will always be present when using mobile web.

https://s.yimg.com/oo/cms/products/flurry-docs/publisher/images/adFeedback_eedec8dcb.png

Passbacks

When zero ads are returned you have the option to use section-based passback methods vs. globals. If you change the default script to use an object instead of a string, you can assign callbacks and other items directly to the section.

Section-based passback method

Change:

window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

To:

window.native.push({
 code: "833b5519-edb7-47c0-88be-1152bcae7870",
 passbackHandler: function(section){
   console.log(section.code, section.message);
   // do something if this adunit returned 0 ads
 }
});

Global passback method

A basic client-side passback can be run using the nativePassbackHandler global method. The nativePassbackHandler is a basic function which runs when the total number of ads returned is zero. By adding the following lines to the ad tag you can enable a basic client-side passback:

window.nativePassbackHandler = function(section){
 if (section.code === "833b5519-edb7-47c0-88be-1152bcae7870") {
   // do something if this section code returned 0 ads
  }
 };

Handling Duplicate Ads

When two or more ad units are loaded there is the potential that identical ads may be returned. To avoid this you can add this optional line to the ad tags:

window.nativePreventDuplicates = true;

If one of the ad units has a Max Ads Requested value greater than 1, the duplicate ad will be skipped and the alternative ad shown. Where 2 or more of the ad units have a Max Ads Requested value of 1, the duplicate ad will not be shown. This may result in some placements appearing empty so to avoid this you can also use the Duplicate Handler to do something when duplicate ads are returned, like returning an in-house ad or passback to another ad source.

section-based method

Change:

window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

To:

window.native.push({
 code: "833b5519-edb7-47c0-88be-1152bcae7870",
 duplicateHandler: function(creativeId, section){
   console.log(creativeId, section);
   // dome something when duplicate ad detected
 }
});

global method

window.nativeDuplicateHandler = function(creativeId, section){
 // do something when a duplicate has been detected
 };

Error Handler

You can control error handling by using the nativeErrorHandler global method. The optional nativeErrorHandler method will only execute if the ad request fails.

section-based method

Change:

window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

To:

window.native.push({
 code: "833b5519-edb7-47c0-88be-1152bcae7870",
 errorHandler: function(section){
   console.log(section.code, section.error);
   // do something when error detected
 }
});

global method

Add the following lines to the ad tag at the bottom before the closing </script> tag:

window.nativeErrorHandler = function(section){
 // add error handling logic here
};

Success Handler

You can use the optional Success Handler to do things like control the display of custom ad container based on whether you received ads or not. The success Handler method will only execute if the ad succeeded and returned ads.

section-based method

Change:

window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

To:

window.native.push({
 code: "833b5519-edb7-47c0-88be-1152bcae7870",
 successHandler: function(section){
   console.log(section.code, section.totalAds);
   // do something when ads are returned
 }
});

global method

Add the following lines to the ad tag at the bottom before the closing </script> tag:

window.nativeSuccessHandler = function(section){
 // console.log(section.code, section.totalAds);
};

3rd Party Click Tracking

If you need to utilise 3rd Party Click tracking this can be done via a URL or UTM parameters using the clickTrackingUrls method which will run when a native ad is clicked on. As with the other methods, this can either be applied at the section or global level.

section-based method

Change:

window.native.push("833b5519-edb7-47c0-88be-1152bcae7870");

To:

window.native.push({
 code: "833b5519-edb7-47c0-88be-1152bcae7870",
 clickTrackingUrls: ['https://trackingurl.com', 'https://trackingurl2.com']
});

global method

Add the following lines to the ad tag at the bottom before the closing </script> tag:

window.nativeClickTrackingUrls = ['https://trackingurl.com', 'https://trackingurl2.com'];

Testing Prior to Launch

Before launching any ad unit, it is important to check that the ad unit is functioning as expected.

How to Test the Ad Unit

Ideally you should place the ad unit on a test page or in staging environment to fully test the ad tag, especially if integrating via DFP, an iframe or an ad server.

Alternatively, you can quickly check position and layout of the ad unit by pasting the JavaScript from the ad tag directly into the console of your developer tools.

You should repeat this test in multiple browsers.

How to Identify the Ad Call

  1. Open the Developer console in your browser

  2. Select the Network tab

  3. Search for getAds and Identify the item with a name starting getAds.do?locale=...

If you cannot locate the ad call you should:

  • Firstly check that the ad tag has been implemented on the test page

  • Check that the staging URL has been added to the Publisher record

  • For Flurry.com Ad Tags: App Publishing > Websites & Ad Units > Edit Pencil

  • Check for that there are no special characters (for example “curly” quotation marks) or spaces in the ad tag which might break the ad tag’s JavaScript and stop it executing the ad call.

If you have checked these and cannot identify the reason for the ad request not executing please reach out to your Partner Manager, with the link to the test page, for assistance.

Items to Check

Once you have the ad tag loaded on the page, you should check for the following:

1: Check that the ad loaded and is in the correct position

If no ad is rendered check the following:

  • you are using the correct ad unit for the page/position

  • Verify the XPath in use is valid

2: Check the Viewability Beacon has fired

In developer tools, in the network tab, search for for mbcsc

An example full beacon url is:

https://ir2.beap.gemini.yahoo.com/mbcsc?bv=1.0.0&es=Pdn6F4UGIS_VixbksF7o89qGJocQWNAly7kLpoUOKOt6Hn0pn4cVP_.pV_06kz4AJX3JTVizDMjtkVLwRTf4qAmpds40VFblqLSEkPO86ysgz01iuM4nT24mXMrDNlzdfM2GyV6ZpDw9IsmTRPMGna0qCDGueXijW3f6oOkcPZasFtYH6O_g4YcBfCWdLJwlcW9LSmP69UMuFq9r4MGv0OQ92zJZEpT067YnjtfbnQjvIyOTyfF4.fANch7y6pEF_aAH2tP.E7KxXvrlCnzJEx3bpANa1jQ5a0ob0zB5.WiJD3mueZqyrPh6Knf0FOnsRMCukqpcl3PSdesVGekLOjYe93LqSqz0by6uhnrES74vKhdrR31yq_Q22dvfywQZ9JTJegmVJ1NbQCB8AiA-&ap=pp%3Dm%2Cpi%3D98

If this is present then it means the viewability beacon is firing and will record the impression

3: Click on the ad to check it takes you to the advertiser site

If you are taken to another page, check that you are using the {click_url} macro for every a href attribute.

If you are not able to click on the ad, check that you have firstly included at least one <a> tag with href="{click_url}". Depending on how you have constructed your ad tag’s template, you may also need to set the display property to display: block in the <a> elements’s style attribute.

4: Check all required features are present

The ad should contain at minimum the following ad elements:

  • Ad Image {image}

  • Ad Title {title}

  • Gemini Logo {gemini} or {gemini_alt}

  • Sponsor Name {sponsor}

  • Click urls {click_url}

  • Ad Label {sponsorLabel} or your own ad label.