Problem with AdSessions / Adcalls

Hello,

unfortunately i am a totally programming noob.

i have an unity app project where i have included gley‘s advertising asset plugin „mobile ads“.

i use this plugin to display admob and unity ads in the defined mediation order that i want to set.

however i followed gley‘s documents how to initiate the ad calls and everything works well.

my problem now is, that i have added a ad call to run an interstitial ad showing everytime a user pushes a reset button.

but in my game this button is pressed very often and the users get to see the interstitial ads way too often (this button is pressed 3-4 times per minute).

my question is, could you help me to find out how to set a counter/time so that the ads are only called every x time that the button is pressed?

hope you can help me.

You can obtain the current time with System.DateTime.Now.

You can store it however you like, either in a GameManager or a static variable, something to track “last time ad shown.”

On subsequent attempts to show an ad you can check that time again, then use the System.DateTime.Subtract() method (with the “last time ad shown” variable) to see how much time has passed since the last ad set.

Based on that span you can decide if it is time to show a new ad.

And obviously if you do, you would store that time in the “last time ad shown”

thanks a lot, kurt!

i will try that.

hi,

somebody suggested to use this basic method to show ads randomly every x time.

float a=Random.Range(0,5); if(a==3) { //show AD }

would this work to put ad call like this?

If the random number generator returns the value 3 many times in a row, the user will suddenly get a burst of ads, and then if it doesn’t return a 3 for a long time, the user will see no ads.

If you consider that “working”, then yes it will work.

thanks! i have implemented that and it is working.
but as you said it can be that the numbers do not get called for a longer time.

is there any simple way to implement such a code where i define that the ad is called really every 3rd time each call?

Certainly. Increment an integer somewhere that persists the length of the game, and when it reaches 3, do two things: set it back to zero and show your advert.

You can make the integer static to trivially easily do it, but it will still return to zero the next time you launch.

If you need it to persist from session to session, use PlayerPrefs, perhaps something like:

Here’s an example of simple persistent loading/saving values using PlayerPrefs:

https://pastebin.com/icJSq5zC

Useful for a relatively small number of simple values.

thanks a lot!
i will try that