Skip to main content


You are reading documentation for an outdated version. Here’s the latest one!

Assuming you have completed the Java Tracker Setup for your project, you are now ready to initialize the Java Tracker.

Importing the module

Import the Java Tracker's classes into your Java code like so:

import com.snowplowanalytics.snowplow.tracker.*;
import com.snowplowanalytics.snowplow.tracker.emitter.*;
import com.snowplowanalytics.snowplow.tracker.http.*;

That's it - you are now ready to initialize a Tracker instance.

Creating a Tracker

To instantiate a tracker in your code (can be global or local to the process being tracked) simply instantiate the Tracker interface with the following builder patterm:

Tracker.TrackerBuilder(Emitter : emitter, String : namespace, String : appId)
.platform(enum DevicePlatforms)

For example:

Tracker tracker = new Tracker.TrackerBuilder(emitter, "AF003", "cf")
Argument NameDescriptionRequired?Default
emitterThe Emitter object you createYesNull
namespaceThe name of the tracker instanceYesNull
appIdThe application IDYesNull
subjectThe subject that defines a userNoNull
base64Whether to enable base 64 encodingNoTrue
platformThe device the Tracker is running onNoServerSideApp


The emitter to which the tracker will send events. See Emitters for more on emitter configuration.

To attach a new Emitter to the Tracker:

Emitter emitter = BatchEmitter.builder()

Tracker tracker = new Tracker.TrackerBuilder(emitter, "AF003", "sp")


The user which the Tracker will track. This should be an instance of the Subject class. You don't need to set this during Tracker construction; you can also include a Subject object with the actual event; this will override the Tracker attached subject.

In fact, you don't need to create a subject at all. If you don't, though, your events won't contain user-specific data such as timezone and language.

To attach a new Subject to the Tracker:

Subject subject = SubjectBuilder.builder()

Tracker tracker = new Tracker.TrackerBuilder(emitter, "AF003", "sp")

For a full list of supported platforms, please see the Snowplow Tracker Protocol.