Tracking email sends, opens and clicks with Snowplow is very common. In this post we detail how to do the above.
1. Tracking email sends
How you do this depends on how you’re sending emails.
If you’ve written your own application to send emails, you’d use one of our trackers to record the send event: if it was a Python app that sent the email you’d record it using our Python tracker, or a Java app you’d use a Java tracker.
If you’re using a third party email provider e.g. SendGrid or Mandrill, depending on the provider it may be possible to automatically grab this data via our webhooks. You would configure the mail provider to stream event-level data into your Snowplow pipeline: instructions on how to do this can be found here. If you’re using a third party that we do not currently support, then let us know and we can look at adding support for that third party.
2. Tracking email opens
Again, how you do this depends on how you’re sending emails.
If you’re sending your own emails, you’d embed a Snowplow pixel in the email and decorate the query string parameter with the different data points that you wanted to pass into Snowplow. An example would be:
<img src="://my.collector.url/i?e=se&p=web&tv=no-js-0.1.0&se_ca=email&se_ac=open&se_la={{email_id}}&se_pr={{recipient_id}}">
When the email is opened the pixel will be fetched and the event recorded.
In the above example we’re recording the event as a custom structured event. You can decipher the meaning of each name/value pair on the query string by referring to the Snowplow Tracker Protocol. Note that:
- The parameters
e
(event),p
(platform) andtv
(tracker version) are required for the event to pass validation - The other parameters
se_ca
,se_ac
,se_la
andse_pr
are specific to custom structured events. If you were recorded the event using another event ‘type’ you’d pick different parameters. Custom structured events are a good option if you can fit the data you want to record in the five fields (category, action, label, property and value) that the event includes. - In the example we’ve assumed that the
{{email_id}}
and{{recipient_id}}
will be dynamically populated into the property and label fields, so that you record which email was opened, and who opened it.
A tip: use the Iglu Webhook to record email opens where you’ve defined your own email open schema
If you want to record more data than the custom structured events support, or you’d prefer to define your own schema, we recommend sending the data into Snowplow using the Iglu Webhok. This enables you to send data points for your own unstructured event as a set of name values pairs on a querystring directly (rather than composing a self-describing JSON). If you had a simple email_open schema like the following:
{
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Schema for an 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
}
Your tag would look like:
<img src="://my.collector.url/com.snowplowanalytics.iglu/v1?schema=iglu%3Acom.mycompany%2Femail_open%2Fjsonschema%2F1-0-0&emailId={{email_id}}&recipientId={{recippientId}}">
Note:
- The url host is the collector host, as before
- The path is /com.snowplowanalytics.iglu/v1, to indicate to Snowplow that this should use the Iglu webhook. (Rather than the 1x1 pixel that is served from
/i
- The Iglu schema then needs to be sent as one of the parameters.
- The different fields in the schema can then be passed in as name/value parameters on the querystring
Tracking clicks on links in emails
The most common route to tracking clicks in emails is to decorate any links in the email with querystring parameters (e.g. utm
parameters). Then when a user clicks on the link, the page view that results will be recorded into Snowplow will the relevant information on the email and recipient sent through on the querystring parameters. This is described here.
In some cases it may not be possible to use the above method (e.g. if you’re driving traffic to a website you don’t own / have tracking setup on). In this case you might want to record the click via a redirect on the collector. Click tracking this way works as follows:
- You update the
href
element in your links to the Snowplow collector. That means that when a user clicks on a link in an ad, they get taken to your Snowplow collector, so that the click event can be recorded - You set the URL path to
/r/tp2
to thehref
. This tells the Snowplow collector that it should record a uri redirect, and then redirect the user to the URL specified below (see 3): - You add a new parameter
&u={{url}}
to the collector URL in tehhref
element, where the{{url}}
parameter is the URL that the user should be forwarded to after the click is tracked in Snowplow. The collector uses this to correctly redirect the user to the correct target URL, after the click has been tracked - OPTIONAL. In addition, you can add other name/value pairs to the URL querystring as per the Snowplow Tracker Protocol. That means you can choose how to describe / schema the click event and what data points you want to record with each click event. (E.g. pass in the different fields available in your ad server.) Note that if you do this the event will be set to the event type indicated by the e= parameter on the querystring, and the uri-redirect will be recorded as a context.
The example below is a link that will redirect to our github repo:
Check us out on <a href="http://collector.snplow.com/r/tp2?u=https%3A%2F%2Fgithub.com%2Fsnowplow">Github</a>
https%3A%2F%2Fgithub.com%2Fsnowplow
For more information see our guide to click tracking.