?> Snowplow Python Tracker 0.5.0 released | Snowplow
Snowplow Outperforms GA4 in GigaOm Comparative Evaluation.
Read More
  1. Home
  2. Blog
  3. Releases

Snowplow Python Tracker 0.5.0 released

Jump to

We are happy to announce the release of version 0.5.0 of the Snowplow Python Tracker! This release is focused mainly on synchronizing the Python Tracker’s support for POST requests with the rest of Snowplow, but also makes its API more consistent.

In this post we will cover:

  1. POST requests
  2. New feature: multiple emitters
  3. More consistent API for callbacks
  4. More consistent API for tracker methods
  5. UUIDs
  6. Bug fix: flushing an empty buffer
  7. Upgrading
  8. Support

1. Updated POST requests

The POST requests sent by the Python Tracker have been changed in three ways:

  • All numerical fields (such as event timestamp) are now converted to strings, so that they can be handled by the same logic that handles fields in GET requests
  • Instead of being sent to mycollector.cloudfront.com/i, POST requests are now sent to mycollector.cloudfront.com/com.snowplowanalytics.snowplow/tp2 to flag that they use a slightly different tracker protocol from GET requests
  • The content-type for POSTs is now set to “application/json; charset=utf-8”

2. New feature: multiple emitters

It is now possible to create a tracker instance which sends events to multiple emitters by supplying an array of emitters to the tracker constructor:

from snowplow_tracker.tracker import Tracker get_emitter = Emitter("d3rkrsqld9gmqf.cloudfront.net") post_emitter = Emitter("d3rkrsqld9gmqf.cloudfront.net", method="post") t = Tracker([get_emitter, post_emitter], namespace="cf", app_id="my-app-id")

After constructing the tracker, you can add more emitters:

new_emitter = Emitter("drywb53f72ag6j.cloudfront.net") t.add_emitter(new_emitter)

All events created by the tracker will be sent all three emitters.

3. More consistent API for callbacks

In version 0.4.0, the Emitter class was introduced. Emitters could be given two callbacks: on_success and on_failure. Whenever the Emitter’s buffer of events was flushed and a request returned with status code not equal to 200, the on_failure callback would be called with two arguments: the number of requests that succeeded, and an object containing the event data for the requests that failed.

The second argument was handled inconsistently. In the case of GET requests, it was an array of dictionaries, each dictionary containing the name-value pairs for an event. In the case of POST requests, it was a stringified JSON.

This release changes the second argument given to the callback in the POST request case to be of the same form as for the GET request case. This means that the same on_failure callback function will work with both types of request.

4. More consistent API for tracker methods

In version 0.4.0, the value returned by the tracker methods was variable. If the method caused a synchronous request to be sent, the status code of that request was returned. Otherwise, the tracker instance was returned, allowing chained method calls like:

t.track_screen_view("title screen").track_struct_event("products", "viewed product", "magenta paint")

This version eliminates the former behavior. All tracker methods now return self, and so can be safely chained.

5. UUIDs

Previous versions of the Tracker sent a random 6-digit transaction ID used by Snowplow to prevent duplication of events. These were not sufficiently unique, so we have replaced them with version 4 UUIDs, which becomes the enriched event’s event_id (instead of generating a new event_id in the Snowplow Enrich process).

6. Bug fix: flushing an empty buffer

Version 0.4.0 had a bug where flushing an emitter configured to send POST requests when its buffer was empty caused it to send POST request with no events in. This behavior has been eliminated.

7. Upgrading

The release version of this tracker (0.5.0) is available on PyPI, the Python Package Index repository, as snowplow-tracker. Download and install it with pip:

$ pip install snowplow-tracker --upgrade

Or with setuptools:

$ easy_install -U snowplow-tracker

For more information on getting started with the Snowplow Python Tracker, see the setup page.

8. Support

Please get in touch if you need help setting up the Snowplow Python Tracker or want to suggest a new feature. You may find the wiki page useful. And raise an issue if you find any bugs!

More about
the author

Snowplow Team
View author

Ready to start creating rich, first-party data?

Image of the Snowplow app UI