Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track every reasonable click in android app?

I need to track an event each time user clicks on any clickable view in my app. I want to do this generally so e.g. in my main activity.
I know I can override onUserInteraction() or dispatchTouchEvent() but these are running even for the clicks which are not clickable views.

I don't need to differ between clickable views, just the fact it is clickable is enough.
In an ideal case, I would also differentiate the Up button from other clicks.

Is this possible?

like image 447
Smeagol Avatar asked Mar 22 '21 15:03

Smeagol


People also ask

How do I distribute Android apps for testing?

Distribute your app to testersSelect your Firebase project when prompted. On the Releases page, select the app you want to distribute from the drop-down menu. Drag your app's APK file to the console to upload it. When the upload completes, specify the tester groups and individual testers you want to receive the build.

Is there a location app for Android?

Google Find My Device is a free app that allows you to trace your phone. You can track any device on your Android phone with this software.


1 Answers

In my opinion, there's no flawless implementation for what you want to achieve.

One possible way is using a OnClickListener wrapper. This needs you or your team to enforce using this wrapper on any clickable views' OnClickListener. But you cannot cover the views in third party library.

public class OnClickListenerWrapper implements OnClickListener {
    private OnClickListener listener
    public OnClickListenerWrapper (OnClickListener listener) {
        this.listener = listener;
    }
    public void onClick(View view) {
        // Logic of tracking
        listener.onClick(view);
    }
}
like image 152
bbsimon Avatar answered Sep 20 '22 01:09

bbsimon