Skip to main content


Import the libraryโ€‹

Import the Golang Tracker library like so:

import ""

You will need to refer to the package as tracker. If you wish to use something shorter (or if tracker is already taken):

import sp ""

The package can now be referred to as sp rather than tracker.

You will also need to import a storage implementation for the emitter - you can select from two that we have created or implement your own following the supplied interface.

The in-memory or SQLite3 implementations can be pulled from the following packages:

import storagememory "" // Maps to tracker.InitStorageMemory() in v2


import storagesqlite3 "" // Maps to tracker.InitStorageSQLite3(<dbname>) in v2

The Storage interface can be found in

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

Creating a trackerโ€‹

The simplest tracker initialization only requires you to provide the URI of the collector to which the tracker will log events and a storage implementation:

import storagememory ""
import sp ""

emitter := sp.InitEmitter(sp.RequireCollectorUri("com.acme"), sp.RequireStorage(*storagememory.Init()))
tracker := sp.InitTracker(sp.RequireEmitter(emitter))

There are other optional builder functions:

Function NameDescriptionRequired?Default
RequireEmitterThe emitter to which events are sentYesnil
OptionSubjectThe user being trackedNonil
OptionNamespaceThe name of the tracker instanceNo``
OptionAppIdThe application IDNo``
OptionPlatformThe platform the Tracker is running onNosrv
OptionBase64EncodeWhether to enable base 64 encodingNotrue

A more complete example:

subject := sp.InitSubject()
emitter := sp.InitEmitter(
tracker := sp.InitTracker(


Accepts an argument of an Emitter instance pointer; if the object is nil will panic. See Emitters for more on emitter configuration.


The user which the Tracker will track. Accepts an argument of a Subject instance pointer.

You don't need to set this during Tracker construction; you can use the tracker.SetSubject() method afterwards. 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.


If provided, the namespace argument will be attached to every event fired by the new tracker. This allows you to later identify which tracker fired which event if you have multiple trackers running.


The appId argument lets you set the application ID to any string.


By default we assume the Tracker will be running in a server environment. To override this provide your own platform string.


By default, unstructured events and custom contexts are encoded into Base64 to ensure that no data is lost or corrupted. You can turn encoding on or off using the Boolean OptionBase64Encode function with either true or false passed in.

Was this page helpful?