Quite a few of Windows Phone developers would like to make money from their apps and games. The best way to do that for US based developers (and hopefully Europeans in the future) at this moment is Microsoft’s own pubCenter. In addition to accepting US developers only, it also serves ads to US customers exclusively. Fortunately it let’s you know when it can’t serve an ad via events so you can react accordingly in your app. And there’s no better way to utilize that unused inventory than using AdDuplex.
Jeff Weber, the creator of one of the best (if not THE best) Windows Phone games – Krashlander, was kind enough to share his fallback code with us. What it does is displays pubCenter ad control when it can display and ad, but when it can’t it falls back to AdDuplex ad control.
The sample code
Both controls are just placed in a simple StackPanel and AdDuplex is set to Collapsed by default.
In code-behind event handlers are attached to pubCenter control events and depending on the result of the pubCenter request either AdDuplex or pubCenter control is collapsed and the other one is displayed.
IMPORTANT: in case you decide to implement the layout in a way that pubCenter control overlaps AdDuplex control, don’t be fooled by the fact that pubCenter control visually collapses when there’s no ad to display. It still occupies the space and catches all the taps rendering AdDuplex control unclickable. So the key is to explicitly set Microsoft’s control to Collapsed.
Thanks to Jeff for this simple but proven code snippet and check out his awesome game if you haven’t already.