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
?
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
}
For the new google play services api:
// from google-play-services.jar
import com.google.android.gms.ads.*;
AdListener adListener = new AdListener() {
@Override
public void onAdOpened() {
tracker.trackEvent(
"AdMob", // Category
"AdView", // Action
"Clicked", // Label
1);
}
};
In new API AdListener is no longer an interface - it is abstract class:
public abstract class AdListener {
public void onAdLoaded() {}
public void onAdFailedToLoad(int errorCode) {}
public void onAdOpened() {}
public void onAdClosed() {}
public void onAdLeftApplication() {}
}
Currently AdMob provides default integration with google analytics. We just need to link analytics account with Admob.
Reference: https://support.google.com/admob/answer/3508177?hl=en-GB
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.