Reputation: 3881
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
?
Upvotes: 8
Views: 2997
Reputation: 2170
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
Upvotes: 0
Reputation: 22054
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() {}
}
Upvotes: 3
Reputation: 3881
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
}
Upvotes: 11