How to detect interstitial ad is clicked by user?

Viewed 617

Is there any way to detect when the user taps on the interstitial ads? I tried but did not find any callbacks for detecting interstitial ad clicks.

Any workaround for detecting the same would also be very helpful.

I want to detect ads click to prevent users from generating fake clicks for interstitial ads.

3 Answers

Google added back the removed interstitialAd callback onAdClicked() on SDK 20.4.0. Looks like they removed it and 6 months later realized they messed up and decided to add it back :)

Added the onAdClicked() callback to FullScreenContentCallback.

See the AdMob SDK release notes for details.

I’ve found that upgrading AdMob SDK to the latest version is a must.

You can utilize the combination of ActivityLifecycleCallbacks and WindowCallback.

  • The ActivityLifecycleCallbacks enables you to observe every Activity lifecycle event that occurs in your app. All in one place.
  • The WindowCallback enables you to intercept many window events. One of the events that gets fired by the system that we are particularly interested in is dispatchTouchEvent.

Now, here is the strategy:

  1. Register our GlobalActivityLifecycleListener in the Application class
class MyApplication : Application() {

    override fun onCreate() {
        super.onCreate()
        registerActivityLifecycleCallbacks(GlobalActivityLifecycleListener())
    }
}
  1. Check if the currently displayed Activity is an Ad Activity. If yes, register our AdWindowCallbacks
class GlobalActivityLifecycleListener : Application.ActivityLifecycleCallbacks {
    //...
    override fun onActivityResumed(activity: Activity) {
        if (isAdActivity(activity)) {
            registerWindowCallbacks(activity)
        }
    }
    
    private fun registerWindowCallbacks(activity: Activity) {
        val currentWindow = activity.window
        /*This is needed to forward the events from our callback back to the original
        callback after we are done with the processing*/
        val originalCallbacks = currentWindow.callback
        currentWindow.callback = AdWindowCallbacks(originalCallbacks)
    }
}
  1. Intercept/process user touch events
class AdWindowCallbacks(private val originalCallback: Window.Callback) : Window.Callback {
    //...
    override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
        //TODO process user touch event
        return originalCallback.dispatchTouchEvent(event)
    }
}

From there, you can detect the common gestures and act accordingly.

I understand your point.

But technically there is no way to track the Interstitial ad clicks by user.

If you closely monitor the behavior, these ads are opened in a new page within your app. You can confirm them by logging onPause in your calling Activity.

And when user performs clicks on these ads, they are taken to respective destination either to Play Store or URL opened in mobile browser depending on the nature of the Ads.

As mentioned in comment section by @Daxesh Vekaria, you can set Frequency capping in your AdMob console

or try some other solution as suggested by @FreeLearning

EDIT 1 :

In worst case, you can try implementing fullScreenContentCallback. But as per the documentation it doesn't provide any click callbacks.

Related