Track Admob Event in the Google Analytics

admob, android, google-analytics

Solution

I found the solution.

Implement the `AdMob` interface `AdListener` for your `Activity`.

public interface AdListener {
  public void onReceiveAd(Ad ad);
  public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error);
  public void onPresentScreen(Ad ad);
  public void onDismissScreen(Ad ad);
  public void onLeaveApplication(Ad ad);
}

Then set listener for `AdView` element.

adView.setAdListener(this);

And override `onPresentScreen` method for tracking events if user clicks on Ads.

onPresentScreen - Called when an Activity is created in front of your app, presenting the user with a full-screen ad UI in response to their touching ad.

private GoogleAnalyticsTracker tracker;
...
@Override
public void onPresentScreen(Ad arg0) {
    tracker.trackEvent(
            "AdMob",    // Category
            "AdView",   // Action
            "Clicked",  // Label
            1);         // Value
}

Problem

Is it possible to track `Admob` event that the user clicked on the ads in the `Google Analytics` . I use `AdMob` for showing ads. I want to track every click on ads in `Google Analytics`. How can I set up `Event`?

Original source