Assuming you have completed the Python Tracker Setup for your Python project, you are now ready to initialize the Python Tracker.
Importing the module
Require the Python Tracker’s module into your Python code like so:
from snowplow_tracker import Subject, Tracker, Emitter
Code language: JavaScript (javascript)
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:
e = Emitter("d3rkrsqld9gmqf.cloudfront.net")
t = Tracker(e)
Code language: JavaScript (javascript)
There are other optional keyword arguments:
Argument Name | Description | Required? | Default |
---|---|---|---|
emitters | The emitter to which events are sent | Yes | None |
subject | The user being tracked | No | subject.Subject() |
namespace | The name of the tracker instance | No | None |
app_id | The application ID | No | None |
encode_base64 | Whether to enable base 64 encoding | No | True |
A more complete example:
tracker = Tracker( Emitter("d3rkrsqld9gmqf.cloudfront.net") , namespace="cf", app_id="cf29ea", encode_base64=False)
Code language: JavaScript (javascript)
emitters
This can be a single emitter or an array containing at least one emitter. The tracker will send events to these emitters, which will in turn send them to a collector.
subject
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 use the Tracker.set_subject
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.
namespace
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.
app_id
The app_id
argument lets you set the application ID to any string.
encode_base64
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 encode_base64
argument.