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. Pixel Tracker

Pixel Tracker

Maintained

What is the Pixel tracker?

The Pixel tracker is an HTML-only tracking tag (no JavaScript) to track opens / views of HTML content that does not support JavaScript. Examples of use cases include HTML emails.

In a normal JavaScript tag, the name-value pairs of data that are sent through to the Snowplow collector via the querystring are calculated on the fly by the JavaScript. (Examples of data points that are calculated on the fly include user_id, or browser_features.)

In an environment where JavaScript is not permitted, these values need to be set in advance and hardcoded into the tracking tag. As a result, if you want to record a different page_title, for example, for several different HTML-only web pages using the tracking code, you will need to generate a different tracking tag for each of those different web pages, with the right page_title set for each.

Anatomy of a Pixel tracking tag

An example tag is shown below:

<!--Snowplow start plowing--> <img src="http://collector.acme.com/i?&e=pv&page=Root%20README&url=http%3A%2F%2Fgithub.com%2Fsnowplow%2Fsnowplow&aid=snowplow&p=web&tv=no-js-0.1.0" /> <!--Snowplow stop plowing-->

Some things to note about the tag:

  1. It is a straightforward <img ...> tag, that results in the GET request to the Snowplow tracking pixel
  2. The endpoint is set to a Clojure collector that we are running at collector.snplow.com.
  3. Five data points are passed on the query string: the event type (pageview), the page name (Root README), the URL (http://github.com/snowplow/snowplow), the application id (snowplow), the platform (web) and the tracker version (no-js-0.1.0)

A warning about using the Pixel tracker on domains you do not own

When using the Pixel tracker with the Clojure collector, the Clojure collector sets a network_userid and drops this on a browser cookie.

Care must therefore be exercised when using the Pixel tracker on domains that you do not own. It is your responsibility to abide by the terms and conditions of any domain owner for domains where you post content including uploading Pixel tracking tags. Some domain owners forbid 3rd parties from dropping cookies on their domains. It is your responsibility to ensure you do not violate the terms and conditions of any domain owners that you work with.

Setting up the pixel tracker

Identify the event you wish to track

Identify the event you wish to track. This may be opening a particular email that is sent out via your email marketing system, or viewing a product you are selling on a 3rd party marketplace.

Use the wizard to create the tracking code

Navigate to the wizard.

Enter an application ID.

If you are running Snowplow to track user behaviour across multiple applications, you may want to have a different application ID for each. Most Snowplow users track behaviour across a single website or webapp. For those users, it probably makes sense to set the application ID to the same value they use on their core website.

Select http or https depending on the scheme used on the pageview you wish to track.

If you are tracking a user opening an email, you should use https. If you’re tracking a pageview on a 3rd party website where you’re showing some content, you will need to check the scheme for the particular page you wish to track.

Enter a page title for the page.

Make it descriptive: it should be obvious from this field in the data what event this is referring to.

You may optionally enter a page URL.

The Clojure collector and Cloudfront collector will be able to deduce the URL directly (without relying on a value entered in a query string), so this can be safely left out if you wish.

Select the type of collector you’re using and enter the relevant details. 

If you’re using the Cloudfront collector you will need to enter the Cloudfront subdomain. If you’re using the Clojure collector (or any other collector) you will need to enter the endpoint collector URL.

Select the `Generate Pixel tracking tag button.

The tracking code will be displayed below the wizard. Copy this to the clipboard.

Insert the tracking code into the page you wish to track

If this is an HTML email, you will need to insert it in the email. If it is a webpage hosted on a third party site, you will need to add it to your source code.

Considerations when using the Pixel tracker, especially with the Clojure collector

The behaviour of the Pixel tracker is very different if used with the Clojure collector than with the Cloudfront collector.

When used with the Cloudfront collector, no user_id is set, because this has to be done client-side using JavaScript. As a result, we cannot use the data to count e.g. the number of unique views of an HTML email or a Github README that contain the Pixel tracking tag. This limits the scope of the analysis that can be performed on the data.

On the other hand, when used with the Clojure collector, a user_id is set. That is because it is set server side. The Clojure collector then drops a cookie with the stored user_id on the user’s browsers. If you were using this to track views of Github READMEs, for example, you would then be able to track specific user browsing behaviour across your site and your Github repos.

That is great from an analytics perspective. However, you need to make sure that you are not violating the terms and conditions of any service providers by dropping the cookie. For example, eBay expressively forbid the dropping of cookies on product listings. It is your responsibility to make sure you abide by the terms and conditions of any service providers you use, when employing that Pixel tracker, in particular in conjunction with the Clojure collector. if you are tracking behaviour on domains that are not your own, it is your responsibility to abide by the terms and conditions of that domain owner.

Click tracking

You can use the Pixel tracker for click tracking aka URI redirects:

  • Set your collector path to {{collector-domain}}/r/tp2?{{name-value-pairs}} – the /r/tp2 tells Snowplow that you are attempting a URI redirect
  • Add a &u={{uri}} argument to your collector URI, where {{uri}} is the URL-encoded URI that you want to redirect to
  • On clicking this link, the collector will register the link and then do a 302 redirect to the supplied {{uri}}
  • As well as the &u={{uri}} parameter, you can populate the collector URI with any other fields from the Snowplow Tracker Protocol

Example:

Check out <a href="http://collector.acme.com/r/tp2?u=https%3A%2F%2Fgithub.com%2Fsnowplow%2Fhuskimo">Huskimo</a>

Snowplow converts the &u={{uri}} argument into a com.snowplowanalytics.snowplow/uri_direct self-describing JSON.

How Snowplow attaches the uri_redirect to the event depends on what other Tracker Protocol fields you attached to the event:

  1. If you attached an &e={{event type}} to your event, then the uri_redirect will be added to the contexts array of your event
  2. If you did not attach an &e={{event type}} to your event, then this event will be treated as an unstructured event and the uri_redirect will be attached as the event itself

Further sources of information

For further information on the Pixel tracker, see this introductory blog post.