Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.

Sending background hits da2d4d

Benjamin Diolez edited this page May 5, 2026 · 1 revision

Data collection / Android / Advanced features / Sending background hits

Utility of identification

Identification enables you to distinguish hits sent following direct usage of your application from hits sent in the background, automatically and independently of the user, with the help of AsyncTask for example.

Tagging

The tracker possesses a context object, which possesses a property, backgroundMode. This is BackgroundMode-type enumeration.

By default, this property is set to Normal. In all cases of tagging automatic behaviours independent of the user, it should be set to Task.

To tag these types of operations, you must initialise a new tracker within your class in the case of a Service.

In the case of an AsyncTask, it is recommended to use a dedicated instance of the tracker. Should you wish to use a single instance of the tracker, please remember to reset the property to Normal at the end of AsyncTask execution.

Tagging examples

  1. Tagging a service
public class DemoService extends IntentService {

    private Tracker tracker;

    public DemoService(String name) {
        super(name);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        tracker = ATInternet.getInstance().getTracker("serviceTracker");
        tracker.Context().setBackgroundMode(Context.BackgroundMode.Task);
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        // Do the work associated with the service

        tracker.Gestures().add("intent received").sendDownload();
    }
}
  1. Tagging an AsyncTask with a dedicated tracker
new AsyncTask<String, String, String>() {
            Tracker tracker = ATInternet.getInstance().getTracker("asyncTaskTracker");

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                tracker.Context().setBackgroundMode(Context.BackgroundMode.Task);
            }

            @Override
            protected String doInBackground(String... params) {
                tracker.Gestures().add("async task").sendDownload();
                return null;
            }
}.execute();
  1. Tagging an AsyncTask with a global tracker
new AsyncTask<String, String, String>() {
            Tracker tracker = ATInternet.getInstance().getDefaultTracker();

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                tracker.Context().setBackgroundMode(Context.BackgroundMode.Task);
            }

            @Override
            protected String doInBackground(String... params) {
                tracker.Gestures().add("async task").sendDownload();
                return null;
            }

            @Override
            protected void onPostExecute(String s) {
                super.onPostExecute(s);
                tracker.Context().setBackgroundMode(Context.BackgroundMode.Normal);
            }
        }.execute();
}

Last update: 05/04/2018

Wiki contents

Clone this wiki locally