Ad impression and click tracking with Snowplow
It is possible to track both ad impression events and ad click events into Snowplow. That means if you’re a Snowplow user buying display ads to drive traffic to your website or app, you can track not only what users do once they click through onto your site or app, but what ads they have been exposed and whether or not they clicked any of them. This is paticularly useful for companies building attribution models, for example.
In this guide, we describe how to implement Snowplow tracking for ad impression and ad click events.
1. Tracking ad impressions
trackAdImpression event (or define your own ad impression event and corresponding schema and use the
trackUnstructEvent). Alternativey, you can configure a pixel tracker (image tag) to load in the ad tag and record the impression event.
In both cases, assuming you are using either the Clojure Collector or the Scala Stream Collectors, a third party cookie will be set / recorded with each event. (In the
network_userid field in the
events table.) This should make it straightforward to identify who the ad was shown to, and join that event with any subsequent events recorded for that user.
Level up your marketing attribution with our advanced guideDownload
You can view a complete example on Github.
In general, different ad servers make different data points available in the ad tag. Common data points include:
- A user (3rd party cookie) ID
- Other user data (e.g. any segments that the user belongs to)
- A set of data points describing the ad servered (ad ID, campaign ID, the target URL, advertiser ID etc.)
- A set of data points describing where the ad is served (publisher ID, banner ID)
It is therefore common to consult your ad server documentation and write your own ad impression schema that accommodates those data points that your ad server makes available to you. We would be thrilled to have users contribute schemas for the major different ad servers to our public Iglu Central schema registry.
1b. Using the pixel tracker to track ad impressions
Notes on the above example:
- The URL host is should be the URL for the collector. You should substitude your collector URL for
/ifetches a transparent 1×1 pixel from the collector
- The querystring parameters determine what data is sent through to Snowplow, as per the Snowplow Tracker Protocol.
- It is a requirement that the following fields are all set:
e. This gives the event type – in this case we have used a custom structured event, denoted by the
p. This gives the platform. Note that there are only a finite number of allowed values – we recommend setting this to
webfor ad impression tracking
tv. This gives the tracker version. This can take any value: you may want to use this to version the different pixel tags you integrate in your ad tags
- We’ve assumed that the ad server will dynamically substitute the correct URL encoded values for
and. Please consult your ad server documentation to make sure you use the correct notation so that this substitution works.
The above example uses a custom structured event to record the ad impression. This has the benefit of simplicity. It is, however, limited – you only have four string fields and one numeric field for all your ad impression data. For that reason you may want to define your own ad impression schema, and base this around the actual data points your ad server makes available to you. That means you’d record the event as a custom unstructured event. Your querystring would need to include a URL encoded self describing JSON for your ad impression event.
A tip: using the Iglu webhook to record ad impressions where you’ve defined your own ad impression schema
Constructing pixel tags to pass data using unstructured events can be fiddly: that is because you have to compose a self-describing JSON, URL-encode it and then add it to a querystring.
A simple approach can be to use an Iglu webhook. 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 we take our standard ad impression schema, for example:
Your pixel tag would then look something like this:
- 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
- The iglu schema then needs to be sent as one of the parameters. This is
iglu:com.snowplowanalytics.snowplow/ad_impression/jsonschema/1-0-0in the above example, but URL encoded
- The different fields in the schema can then be passed in as name/value parameters on teh querystring
2. Tracking ad clicks
Tracking ad clicks is more difficult than tracking link clicks on e.g. your own website for two reasons:
Snowplow supports ad click tracking using redirects in the collector. Ad click tracking works as follows:
- You update the
hrefelement in your ad 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
href. This tells the Snowplow collector that it should record a uri redirect event, and then redirect a user to a URL specified below (see 3)
- You add a new parameter
&u=to the collector URL in the
hrefelement, where the “ 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 redidirect will be recorded as a context.
The example below is a link that will redirect to our Github repo
For more information see our guide to click tracking.