Blog

Tracking Email Events (Sends, Opens, and Clicks) with Snowplow: A Comprehensive Tutorial

By
Snowplow Team
&
June 26, 2024
Share this post

Tracking email events such as sends, opens, and clicks is crucial for understanding user engagement and optimizing email campaigns. In this tutorial, we will detail how to implement email tracking using Snowplow, leveraging both custom structured events and the Iglu webhook for more advanced use cases.

Prerequisites

  • Snowplow pipeline set up with a functioning collector

  • Basic knowledge of email delivery systems (e.g., SendGrid, Mandrill)

  • Familiarity with structured and unstructured events in Snowplow

  • Access to the Iglu schema registry

1. Tracking Email Sends

Email send events can be tracked in two ways:

  • Custom Email Sending Application:
    • If you have developed your own email sending application, use the appropriate Snowplow tracker to record the send event. For example, a Python application can use the Python tracker, while a Java application can use the Java tracker.

  • Example for Python tracker:

from snowplow_tracker import Tracker, Emitter

emitter = Emitter('my.collector.url')
tracker = Tracker(emitter)
tracker.track_struct_event(
    category="email",
    action="send",
    label=email_id,
    property=recipient_id
)
  • Third-Party Email Providers:
    • If you are using email providers such as SendGrid or Mandrill, configure webhooks to stream event-level data into Snowplow. Refer to the specific provider’s documentation for webhook configuration.

2. Tracking Email Opens

Email opens are typically tracked using a tracking pixel embedded in the email. This pixel is a 1x1 image with a specific URL containing query parameters that record the event in Snowplow.

Basic Tracking Pixel Implementation:

<img src="http://my.collector.url/i?e=se&p=email&tv=no-js-0.1.0&se_ca=email&se_ac=open&se_la={{email_id}}&se_pr={{recipient_id}}">
  • e: Event type (structured event)

  • p: Platform (set to email to distinguish from web events)

  • se_ca: Category (email)

  • se_ac: Action (open)

  • se_la: Label (email ID)

  • se_pr: Property (recipient ID)

3. Advanced Open Tracking Using the Iglu Webhook

For more complex data tracking, utilize the Iglu webhook to send custom schemas. Define a schema in Iglu and reference it in the tracking pixel URL.

Sample Schema:

{
  "$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
  "description": "Schema for email open event",
  "self": {
    "vendor": "com.mycompany",
    "name": "email_open",
    "format": "jsonschema",
    "version": "1-0-0"
  },
  "type": "object",
  "properties": {
    "emailId": { "type": "string" },
    "recipientId": { "type": "string" }
  },
  "additionalProperties": false
}

Tracking Pixel with Iglu Webhook:

<img src="http://my.collector.url/com.snowplowanalytics.iglu/v1?schema=iglu%3Acom.mycompany%2Femail_open%2Fjsonschema%2F1-0-0&emailId={{email_id}}&recipientId={{recipient_id}}">

4. Tracking Clicks on Email Links

Link clicks can be tracked by appending query parameters to the target URL or by redirecting through the Snowplow collector.

Using Query Parameters:

Update your email links to include query parameters that will be captured by the Snowplow tracker on the destination webpage.

Example:

<a href="https://example.com?utm_source=email&utm_medium=email&utm_campaign={{campaign_id}}&emailId={{email_id}}">Click Here</a>

Redirect Through the Snowplow Collector:

Alternatively, use a redirect to log the click event before redirecting the user:

<a href="http://my.collector.url/r/tp2?u=https%3A%2F%2Fexample.com&emailId={{email_id}}&recipientId={{recipient_id}}">Click Here</a>

5. Best Practices for Email Tracking

  • Ensure that recipient IDs are appropriately hashed or encrypted to protect user data.

  • Monitor the collector’s capacity, especially when implementing click tracking with redirects. Scale up instances if necessary to handle increased traffic.

  • Periodically review schema definitions to align with evolving data requirements.

Conclusion

Implementing email event tracking with Snowplow provides valuable insights into email campaign performance and user engagement. By leveraging structured events, the Iglu webhook, and click tracking through redirects, you can build a comprehensive email tracking strategy that integrates seamlessly with your Snowplow pipeline.

Subscribe to our newsletter

Get the latest content to your inbox monthly.

Get Started

Whether you’re modernizing your customer data infrastructure or building AI-powered applications, Snowplow helps eliminate engineering complexity so you can focus on delivering smarter customer experiences.