MicroChipKid
MicroChipKid

Reputation: 41

Ionic 3: How to show Interstitial Ad via AdMob based on 10 button clicks

I need some assistance. So I have successfully added Admob free to my ionic 3 app. using this plugin : https://github.com/ratson/cordova-plugin-admob-free.

I got the interstitial ad to show but once the app has ran for the first time. I don't think this is user friendly so I would like to add a function that will display the ad every 10 button clicks. I would like this to count any button clicks throughout the app not just a specific page. I don't know where would be the best place to implement the function.

I have tried searching for various ways to implement this but most articles are about adding it in android or ios. I also used ionic 1 articles and tried to hack it make it work for ionic 3 but i had no luck. I also searched on here but have not found any working solutions. Cant anyone help me please?

Upvotes: 0

Views: 722

Answers (1)

Gowtham
Gowtham

Reputation: 3233

  1. create a provider and declare a variable which has type int and value 0 initially.
  2. create a function which increments the declared variable when called.
  3. Inside the function which increments the variable count, you can have a condition something like this,

    if (num % 10 == 0){      // checks if the input is divisible by 10 
         //call your interstitial admob function;
         //increment the variable   
    }else{
         //increment the variable
    }
    
  4. Call this provider function wherever you have button click.

Hope that works!

Upvotes: 1

Related Questions