Problem with expandable sample creative from iab.net/mraid?

965 views
Skip to first unread message

Mike Chevett

unread,
Oct 18, 2013, 10:58:21 AM10/18/13
to ormma-di...@googlegroups.com
The IAB provides expandable and interstitial examples here: http://www.iab.net/media/file/MRAID_AD_EXAMPLES.zip

You'll see the expandable example does something like the following in ad_loader.js:

1: document.write("<script src=\"mraid.js\"></script>");
2: var state = mraid.getState();


The problem here is that the mraid.js file referenced on line 1 will not be loaded by line 2, so I don't understand how this example is expected to work.  This example generates an 'Uncaught ReferenceError: mraid is not defined'

So, shouldn't the expandable creative example be considered invalid?  Thanks a lot!

Nathan Carver

unread,
Oct 18, 2013, 11:14:13 AM10/18/13
to ormma-di...@googlegroups.com
Mike,

You've identified a known weakness in the identification of mraid ads. You can use JavaScript to identify as MRAID, but also need JavaScript to check for the "mraid" object.

In some SDKs, this code works fine. It succeeds in containers where the "mraid" JavaScript namespace is always available. I think this is more common these days. The need to identify if an ad is MRAID and provide different containers is much less now than when MRAID started.

So while I think the example is OK, it fails to highlight the problem that the mraid namespace may not be available. All good code should check for the existence of methods and objects before using them...sort of like using a getDocumentById('foobar').style without checking that foobar exists first.

I know the IAB is working on a new round of MRAID creatives that will be used for 2.0 compliance testing. These should serve as stronger examples for best-practice coding.

Thanks,
-Nathan



--
You received this message because you are subscribed to the Google Groups "ORMMA-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ormma-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Mike Chevett

unread,
Oct 18, 2013, 12:57:20 PM10/18/13
to ormma-di...@googlegroups.com
Hey Nathan, I really appreciate the fast response!

If my SDK doesn't support this example, then is my SDK still considered MRAID compliant?

The 2.0 spec has a section entitled "Standard Web Technologies" that states "The ad designer should be able to develop and test the ad unit in a web browser".  So, I want to create an mraid.js file and serve it from my ad server to make my creatives preview-able in a standard desktop browser.  This is very do-able for most of the MRAID creatives I've seen.  

I've included some examples below.  Example #1 works great.  Example #2 is clearly wrong and Example #3 is what the iab.net expandable example does.  Example #2 and #3 both have the same problem, but example #2 illustrates that problem in a very clear manner.


Example #1: Great!
<script src="mraid.js"></script>
<script>
 console.log(mraid.getState)); // this works great and follows standard browser behavior 
</script>

Example #2: Wrong!
<script>
 console.log(mraid.getState));
</script>
<script src="mraid.js"></script>

Example #3: Wrong just like #2, but is confusing
<script>
  document.write('<script src="mraid.js"></'+/script>');
  console.log(mraid.getState()); // expecting this to work implies a magical browser 
</script>

The spec says MRAID creatives can be developed/tested in a browser, but then provides an example that cannot work in a browser.  Isn't that a problem?  Did this make any sense?  Thanks again!

Nathan Carver

unread,
Oct 18, 2013, 4:28:58 PM10/18/13
to ormma-di...@googlegroups.com
Hi Mike,

MRAID creatives can be tested in a browser under a couple of conditions
* They don't call any MRAID methods
* They gracefully degrade when the mraid namespace is unavailable
* The relative mraid.js provided by the publisher provides an MRIAD implementation for web
* You are using the IAB WebTester http://webtester.mraid.org/

Agreed that of your three examples, only the first one follows best practice.

It is important to note that not all creatives use the HTML <script> tag to identify as MRAID ads. Many will use DOM insertion, and a small few will still use document.write. For those creatives, the developer must use defensive coding practices to protect against using the mraid namespace before it instantiates.

Thanks,
-Nathan
Reply all
Reply to author
Forward
0 new messages