Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. Golang Tracker
  6. Initialization


Import the library

Import the Golang Tracker library like so:

import "" OR import "" # When using modules
Code language: PHP (php)

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 "" OR import sp "" # When using modules
Code language: PHP (php)

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

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:

import sp "" emitter := sp.InitEmitter(sp.RequireCollectorUri("com.acme")) tracker := sp.InitTracker(sp.RequireEmitter(emitter))
Code language: JavaScript (javascript)

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(sp.RequireCollectorUri("com.acme")) tracker := sp.InitTracker( sp.RequireEmitter(emitter), sp.OptionSubject(subject), sp.OptionNamespace("namespace"), sp.OptionAppId("app-id"), sp.OptionPlatform("mob"), sp.OptionBase64Encode(false), )
Code language: JavaScript (javascript)


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.

If you’d like to learn more about Snowplow Insights you can book a demo with our team, or if you’d prefer, you can try Snowplow technology for yourself quickly and easily.