Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Ads on Phone 8
Started by doubleslashdesign Aug 25 2014 08:20 AM

61 replies to this topic
ads for windows 8 phone
[TOPIC CONTROLS]
Page 2 of 3 1 2 3
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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. 



[TOPIC: post.html]
#27

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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



[TOPIC: post.html]
#28

spacewolf

[GLOBAL: userInfoPane.html]
spacewolf
  • Contributor

  • 298 posts
  • Enterprise

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.



[TOPIC: post.html]
#29

doubleslashdesign

[GLOBAL: userInfoPane.html]
doubleslashdesign
  • Contributor

  • 727 posts
  • Corona SDK

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



[TOPIC: post.html]
#30

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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);



[TOPIC: post.html]
#31

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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.
?


[TOPIC: post.html]
#32

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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?



[TOPIC: post.html]
#33

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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.



[TOPIC: post.html]
#34

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

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.



[TOPIC: post.html]
#35

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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. 



[TOPIC: post.html]
#36

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

[TOPIC: post.html]
#37

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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?

[TOPIC: post.html]
#38

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

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);


[TOPIC: post.html]
#39

doubleslashdesign

[GLOBAL: userInfoPane.html]
doubleslashdesign
  • Contributor

  • 727 posts
  • Corona SDK

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



[TOPIC: post.html]
#40

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

Yeah already tried all that. Theres something else that Google is doing behind the scenes which you cant remove. If you find a way to remove the interstitial let me know. :) AFAIK There is no function or method that allows it so as soon as AdRequest is created thats when the slowdown starts. Doesnt even need to load the ad. Anyway After removing some of the banners it is better . 



[TOPIC: post.html]
#41

doubleslashdesign

[GLOBAL: userInfoPane.html]
doubleslashdesign
  • Contributor

  • 727 posts
  • Corona SDK

@Spacewolf

 

Here is the code sample I promised.

Actually it is an app template, and contains a PDF document of the entire process as well as explaining some of my source code for creating a template very easy and sample like

 

http://www.larrymeadows.me/books/ComposerFrameWorkV3.zip

 

The PDF doc points to a different download location but my blog kept rewriting the URL and would not let it download.

 

If you have problems or it removes the .zip extension on the end, just add it back and hit enter. It did download in my testing.

 

I plan to use it for a meetup demo.

 

Enjoy Larry



[TOPIC: post.html]
#42

doubleslashdesign

[GLOBAL: userInfoPane.html]
doubleslashdesign
  • Contributor

  • 727 posts
  • Corona SDK

@Rob,

Would you share a sample when you get the Google and AdMob code working?

 

thanks

 

Larry



[TOPIC: post.html]
#43

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

Hello Larry, it's late here and I going away for a few days so just quickly, what have you demonstrated in your example? Just so I don't repeat anything. Or I could just post up everything I've done? All I know is that you can't have more than one or two banners plus an interstitial as they all have some heavy stuff going on and the interstitial conflicts with any other runtime stuff u have going on enter frames. This isn't a problem if u just have one of each anyway. I tried to make a banner rotator. I can post that plus an example of launching a interstitial from corona withiut changing any code in VS.

[TOPIC: post.html]
#44

doubleslashdesign

[GLOBAL: userInfoPane.html]
doubleslashdesign
  • Contributor

  • 727 posts
  • Corona SDK

Sorry, i wrote my post and then took the family out to the movies.

 

My example is a small app template that uses the composer api.

 

It also shows how to implement the windows ad api and send data to and from C# to LUA and vise versa.

 

If you want you can  post up everything you have done, I'll also review it and mess around with the code to see if I can help out with a few things. I have a friend that work locally here at Microsoft, and I know at a couple MVP's that may have an Idea or two on some of the issues.

 

Not sure how fast they will respond to my inquiries but I can show them what is going on and see if they have any ideas on what to look at.

 

Larry



[TOPIC: post.html]
#45

spacewolf

[GLOBAL: userInfoPane.html]
spacewolf
  • Contributor

  • 298 posts
  • Enterprise

@doubleslashdesign

 

Thank you for posting this! I am looking forward to trying it out and integrating a banner into my app. I'll let you know how it goes :)



[TOPIC: post.html]
#46

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

Ok well Im leaving in a couple of hours. Ill paste up what I have done. This is for Interstitials. I also practiced creating my own CS and including it into project as Im new to Visual Studio. So this is a longer way round it but it allows to only need to change the ID from LUA and create my own custom class which I can add my own utilities and reuse that across future projects. (all about work flow me). I maybe have some unnecessary code or might have it incorrect but it works. Jy first Corona projects a few years ago wasnt exactly efficient :)

 

Add the googleAds.dll as reference downloaded with the SDK.

I right click on solution and choose add class. I then select c# class. I name this to whatever I want before or after form Visual Studio . In this example its AdModule.cs. At the top I make sure I add using "GoogleAds" so the top will be something like this:

///////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using GoogleAds;
////////////////
 

I then declare these in the class:

 

   private InterstitialAd interstitialAd;     
   private string ID;
 

In Admodule.cs I have this function

///////////////////////////

   public void createInterstertial(string adUnitID)
        {
           ID = adUnitID;
 
           interstitialAd = new InterstitialAd(ID);
           AdRequest adRequest = new AdRequest();
           
            // Enable test ads.
           //  adRequest.ForceTesting = true;
 
            interstitialAd.ReceivedAd += OnAdReceived;
            interstitialAd.LoadAd(adRequest);
            interstitialAd.FailedToReceiveAd += OnFailedToReceiveAd;
           interstitialAd.DismissingOverlay += OnDismissingOverlay;
         //   adRequest = null;
           // System.GC.Collect();
            
        }

/////////////////////////

 

(note the bottom two lines dont do anything. I wish they did but they dont need to be there. I only tried to null the adRequest as thats the bit that slows down any heavy Runtime EnterFrame methods while running banners at the same time.) 

 

I then add the call backs: Note the dismisss function is useless as theres nothing to remove in Googles ad plugin just yet.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 private void OnAdReceived(object sender, AdEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Ad received successfully");
            interstitialAd.ShowAd();
            
        }
        private void OnDismissingOverlay(object sender, AdEventArgs e)
        {
            Debug.WriteLine("Dismissing interstitial.");
         
          //  interstitialAd = new InterstitialAd(ID);
          //  AdRequest adRequest = new AdRequest();
            //interstitialAd.stopLoading();
           // adRequest = null;
           //interstitialAd = null;
            interstitialAd.ReceivedAd += null;
            interstitialAd.DismissingOverlay += null;
            interstitialAd.FailedToReceiveAd += null;
            interstitialAd = null;
           
            System.GC.Collect();
 
 
            
            
        }
 
        private void OnFailedToReceiveAd(object sender, AdErrorEventArgs errorCode)
        {
            Debug.WriteLine("Failed to receive interstitial with error " + errorCode.ErrorCode);
 
        }
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

 

Then in mainPage.cs I add this to the top to reference my custom class:

 

 AdModules testClass = new AdModules();

 

\\\\\\\\\\\\\\\\\

 

Then obviously  the lua interop bit:

\\\\\\\\\\\\\\\\\

 

fCoronaPanel.Runtime.Loaded += OnCoronaRuntimeLoaded;

 

\\\\\\\\\\\\\

 

Then the function:

 

\\\\\\

   private void OnCoronaRuntimeLoaded(object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e)
        {
 
            e.CoronaRuntimeEnvironment.AddEventListener("admobInterstertial", CoronaAdMobInterstertial);
}
 
\\\\\\\\\\\\\\\\\\\\\\\\\\\
Then this is the code to launch m adModule.cs code:
 
\\\\\\\\\\\\\\\\\\\\\
  private CoronaLabs.Corona.WinRT.ICoronaBoxedData CoronaAdMobInterstertial(
         CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e)
        {
            var adUnitID = e.Properties.Get("adUnitID") as CoronaLabs.Corona.WinRT.CoronaBoxedString;
            if (adUnitID == null)
            {
 
                return CoronaLabs.Corona.WinRT.CoronaBoxedString.From("missing ad unit ID");
            }
 
            testClass.createInterstertial(adUnitID.ToString());
            return null;
        }
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Finally in LUA:
 
local adMobIntertstertialID="123456789bum";
local status=false;
function M.showAdMobInterstertial()
if status==false then
status=true;
Runtime:dispatchEvent({name="admobInterstertial",adUnitID=adMobIntertstertialID});
timer.performWithDelay(10000,function()status=false;end);
end
end
 
 

\\\\\

I made this timer function as a bodge job to block double triggering of ads, or forcing them not to come up until after a certain amount as it crashes if tries to load two before its finished.

So a bit of a rush so hope this is good enough.



[TOPIC: post.html]
#47

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

DOing banners is just the same as Windows ads really:

 

Add this in the mainPage.xaml. dont forget the using googleAds. bit and reference the DLL

\\\\\\\\\

  <GoogleAds:AdView 
                    x:Name="ad4"
                    HorizontalAlignment="Center" VerticalAlignment="Top" 
                    Height="80" Format="Banner"
                    AdUnitID="123456789bum"
                     CharacterSpacing="1"
                    Width="480"/>
\\\\\\
Google dont ask you to put a name in but doing this allows you hide or unhide them FOr instance in my main.cs is this:
\\\\\\\\\\\\\\\\\\\
    private CoronaLabs.Corona.WinRT.ICoronaBoxedData CoronaHideAd4(
CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e)
        {
 
            ad4.Visibility = System.Windows.Visibility.Collapsed;
            ad4.IsEnabled = false;
            return null;
 
        }
 
        private CoronaLabs.Corona.WinRT.ICoronaBoxedData CoronaUnHideAd4(
        CoronaLabs.Corona.WinRT.CoronaRuntimeEnvironment sender, CoronaLabs.Corona.WinRT.CoronaLuaEventArgs e)
        {
 
            ad4.Visibility = System.Windows.Visibility.Visible;
            ad4.IsEnabled = true;
            return null;
 
        }
\\\\\\
 
        private void OnCoronaRuntimeLoaded(object sender, CoronaLabs.Corona.WinRT.CoronaRuntimeEventArgs e)
        {
 
            e.CoronaRuntimeEnvironment.AddEventListener("unHideAd4", CoronaUnHideAd14);
  e.CoronaRuntimeEnvironment.AddEventListener("hideAd4", CoronaHideAd4);
}
\\\\\\\\\\\\\\\\\\\\\\\\
No in LUA I can hide or unhide then (and or any others with names:
 
\\\\\
Runtime:dispatchEvent({name="unHideAd4});
Runtime:dispatchEvent({name="hideAd4});

 

Hope thats enough. Gotta go now :)



[TOPIC: post.html]
#48

Rob...

[GLOBAL: userInfoPane.html]
Rob...
  • Contributor

  • 329 posts
  • Corona SDK

Oh and in my dismiss function there's a load of stuff in there that you can remove. It was me trying different ways to clear it from memory. You could use this to reload a new add request for later.

[TOPIC: post.html]
#49

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Rob,

 

Regarding your dismiss code where you do this...

private void OnDismissingOverlay(object sender, AdEventArgs e)
{
	interstitialAd.ReceivedAd += null;
	interstitialAd.DismissingOverlay += null;
	interstitialAd.FailedToReceiveAd += null;
	interstitialAd = null;
	System.GC.Collect();
}

The "+= null;" part will *not* remove your event handler from the object.  The "+=" operator adds an event handler, and since what you are adding is "null", then the "+=" operation will end up doing nothing.  To remove event handlers, you must do a "-=" operation with the same method or delegate that you original gave the event, like this...

private void OnDismissingOverlay(object sender, AdEventArgs e)
{
	interstitialAd.ReceivedAd -= OnAdReceived;
	interstitialAd.DismissingOverlay -= OnDismissingOverlay;
	interstitialAd.FailedToReceiveAd -= OnFailedToReceiveAd;
	interstitialAd = null;
	System.GC.Collect();
}

The reason is because a .NET class' event field can support multiple event handlers.  You can only remove your event handler by its reference.  Microsoft documents this via the link below.

   http://msdn.microsoft.com/en-us/library/ms366768.aspx

 

That said, I think what you did was relatively harmless.  However, if you were adding an event handler to a "static" event, then the consequence is that it'll end up keeping your event handler object alive for the life-time of your application, which is the garbage collected language equivalent of a "memory leak".  Just something to be aware of.



[TOPIC: post.html]
#50

spacewolf

[GLOBAL: userInfoPane.html]
spacewolf
  • Contributor

  • 298 posts
  • Enterprise

When implementing my google ads interstitial ad, I first tried reusing the InterstitialAd object and just requesting a new ad with it every time. This will only display an ad the first time. Any subsequent ads will NOT display on the screen. So just make sure every time you want to load and show an ad, you create a new InterstitialAd object! 

 

Just a gotcha I ran into and wasted some time figuring out why it didn't work.




[topic_controls]
Page 2 of 3 1 2 3
 
[/topic_controls]