Ads on Phone 8

I am very close on this now. I added the Microsoft Windows Ads into my sample corona project.

everything is coming up on my screen. But I have the following issues.

  1. I don’t see the ads ( i think this has something to do with my Grid layout - I am not sure yet )

  2. with the ad code in place I can no longer touch the actual corona screen for some reason.

i will continue to monkey around with it.

Here is mine. You can  copy past it if you like. Make sure  that you can see the new view you add in your grid layout view. it might be off screen. Change your positioning as you need it. This is currently set for middle bottom. 

  <DrawingSurfaceBackgroundGrid x:Name=“fDrawingSurfaceBackgroundGrid” Grid.Row=“1” Margin=“12,0,12,0”>

        <corona:CoronaPanel x:Name=“fCoronaPanel”>

            <UI:AdControl x:Name=“ad1”

                          ApplicationId=“LALALA not telling you”

                          AdUnitId=“or this either”

                          HorizontalAlignment=“Center” 

                          Height=“60” 

                          Margin="-0,-10,0,0" 

                          VerticalAlignment=“Bottom” 

                          Width=“320” 

                          IsAutoCollapseEnabled=“True”/>

        </corona:CoronaPanel>

    </DrawingSurfaceBackgroundGrid>

IF you cant see ads. make sure you put back the default ids so you see the test ad on simulator. if you see test ad but not actual ads then campaign is not on. if you dont see test ad then its either off screen or you might have placed it outside the main grid object

@Rob,

That got it.

I did not think to place the Ad control inside the CoronaPanel. I had created a stack panel and was trying to get that to work.

But your way is better. On my little laptop the simulator went nuts flickering on every frame, but on the divice its smooth.

i added some funky code to toggle the ads on an off, with the Lua dispatch events but it is all working pretty well.

@SpaceWolf

Let me clean up my code a bit and I’ll upload it to my website. I’ll try to tackle this on tuesday evening.

Thanks for the assist Rob and everyone else.

Larry

Great news @doubleslashdesign!

I am looking forward to seeing the ad sample codes :slight_smile:

Glad to help Larry. Notice on google docs they don’t add “name” parameter. I tried this when I needed to hide/unhide it. Adding the name allowed this. Also added extra bits like auto collapses although this will remove the black square if no banner is available so might look like it’s not working. Best to disable this till it’s all working.

Josh it does seem to stop it exiting now thats great thanks

So now I have Google Banners and Google Interstitial and Windows Banners working. 

Happy to help!  Glad it’s working for you now.  :)

Just wanted to chime in here with an FYI. I’ve had native apps on windows phone for a few years now and this is what I have found with advertising:

Pubcenter (microsoft ads)

Fill rate: 69%

Ecpm: $0.32

Admob

Banner ads

Fill rate: 99%

ecpm: $0.06

Inmobi

Banner ads:

Fill rate: 0%

ecpm: ???

I don’t know how interstitial ads will perform. It’s possible they would be better.

My advice for advertising on windows phone is to ALWAYS use pubcenter first, then fall back to admob if pubcenter has no ad to serve.

I have not added the  interstitial google - ad mob. But I will in my next updated version.

I’m almost done with the clean up, and a little write up on my functions.

I’ll have it done by this weekend.

Larry

JOSHUA, I can now invoke the interstitial ID direct from LUA so this is very handy for code re-use.

Im trying to do the same with the banner but while this code is outside the mainPage I am having difficulty adding as a child object:

This line doesnt work as I need top reference / link to ContentPanel which is outside my CS file.

How can I link/reference ContentPanel from the mainPage.cs/xaml to my CS file?

 ContentPanel.Children.Add(bannerAd);

Also running into an issue now with Interstitial ads. Ive noticed a big slow down when using Runtime enter frame events after an Interstitial has been created. It runs well if I dont create the ad but like a dog if I do. It seems that although the ad is dismissed, it is doing something still. I need to be able to remove it.

So, this is the code to create the ad:

interstitialAd = new InterstitialAd(adUnitID);

            AdRequest adRequest = new AdRequest();

            // Enable test ads.

            // adRequest.ForceTesting = true;

            interstitialAd.ReceivedAd += OnAdReceived;

            interstitialAd.LoadAd(adRequest);

            interstitialAd.FailedToReceiveAd += OnFailedToReceiveAd;

            interstitialAd.DismissingOverlay += OnDismissingOverlay;

Now what can I do to remove all that completely? Is there some kind of removeSelf for c#? Do i remove the instance I created :interstitialAd

and then

AdRequest 

OnDismissingOverlay is an empty void which just lets me know it has been dismissed so I just need to place whatever code in there.

?

First, I recommend that you add the AdView (ie: AdMob’s banner ad) to your CoronaPanel.  That way it’ll always be rendered/displayed on top of Corona.  Or at least add your ContentPanel to the CoronaPanel.  You can do so as follows…

   fCoronaPanel.Children.Add(bannerAd);

When you want to remove the ad banner from the page, then you remove it from the “Children” collection.  This is the equivalent to Corona’s DisplayGroupObject:remove() function in Lua.  You can do so as follows…

   fCoronaPanel.Children.Remove(bannerAd);

Hopefully, Google coded this right on their end and set up their AdView to stop requesting ads from the Internet when it has been “Unloaded” from the page, which happens when you remove it.

Regarding interstitial ads slowing down your app, I’ve only noticed this happening the first time I called LoadAd().  I didn’t see any slow-downs after showing/dismissing the interstitial ad or with subsequent calls to LoadAd().  I’ve tested this with our “Physics\ManyCrates” sample app that I cranked up to 60 FPS.

Also, is there a reason why you’re hooking into “enterFrame” events?  What are you using it for?

I dont need to remove the banners. They arent causing any problem. They are fine.

 I need to find away to remove interstitial as in the code above - i need to remove al instances of it and see if that works. I dont know if it will.

What I have running on enterframe  an on screen  touch event running and an audio function that wobbles pitch. It all works fine until an ad comes up an is dismissed. Its as if its still there.

Im just porting something across that works fine on Android and IOS and actually does work on Windows Phone until the Interstitial is dismissed.

The APIs provided by Google’s InterstialAd is very limited.  There is no means of removing anything via their class.  I would assume that Google creates a XAML page when showing an interstial ad and then they remove the page from the app when you back out of it or tap the (x) button.  Also, since it’s .NET based, the garbage collector would not immediately destroy the interstial ad’s page.  So, you could try forcing garbage collection yourself when returning to your MainPage.  You can do that in .NET via the static System.GC.Collect() method.  Just be warned that doing this will likely cause a short performance hit.

   http://msdn.microsoft.com/en-us/library/system.gc.collect(v=vs.110).aspx

Also, does your app perform better without the “enterFrame” event?

I ask because I’m not seeing this performance issue in my interstiad ad example app.  But also, performing a lot of work on every frame is a very expensive thing to do on all platforms.  I suggest that you start looking in your enterFrame code first.

I would normally but it captures motion and redraws on screen. If it goes slower then it wont be as smooth. Also theres an LFO style pitch control happening at the same time and needs to be smooth. I will see about maybe thinning the updates down a little. I wonder if its related to movement events as in mentioned previously. Even so as I said it works fine and as it should If I dont use interstertial ad at all. Maybe Im better of just not using it for this particular project.

I tried that system.gc.collect and no joy. Even nulled everything first. I was wondering how I could possibly use some kind of Destroy or Dispose. 

I see other people have tried this . It looks like there is or was something that might have done the trick for Android but its not available in c#

https://groups.google.com/forum/embed/?place=forum/google-admob-ads-sdk&showsearch=true&showpopout=true&parenturl=https%3A%2F%2Fdevelopers.google.com%2Fmobile-ads-sdk%2Fcommunity%2F#!searchin/google-admob-ads-sdk/remove$20interstitial/google-admob-ads-sdk/TQFMhVHUpwA/yivQ6y-qT3kJ

Is it possible to re enable the “bug” allow me to switch it on so it exits the app and restarts like it used to?

I figured out what it was. I had made an ad banner rotate experiment with windows ad banner(2) and google ad banner and was cycling through hiding and unhiding them. This seemed to be too many banner ads for the system to handle once the interstitial came in. Simple Corona Runtimes slow down.  It is still odd that the interstitial is still hanging round somewhere after it is dismissed. This is Googles lack of function to remove it.

IF you want to recreate my issue  just create three windows ad banners on screen then add this code to Main and it will work as expected until an interstitial comes in.

(just swap the cursor with any small image)

For now Ill stop being greedy and stick to one or two ad banners.

local cursor=display.newImage(“cursor.png”,0,0)

local function runtimeTestFunction()

cursor.x=xPos;

cursor.y=yPos;

end

local function  updatePosition(event)

if event.phase==“began” or event.phase==“moved” then

xPos=event.x;

yPos=event.y;

end

end

Runtime:addEventListener(“enterFrame”,runtimeTestFunction);

Runtime:addEventListener(“touch”,updatePosition);

Also in your C# code try setting the object to NULL after you remove it.

You can go a step further and try to force the Garbage Collection to execute and clean up even further.

Larry