Tracking Ad Impressions and Clicks with Snowplow - Tutorial
Ad impression and click tracking are crucial for marketers and data engineers looking to understand user interactions with ads. With Snowplow, you can effectively track both ad impressions and clicks to build attribution models, analyze campaign effectiveness, and optimize ad spend. This tutorial outlines how to implement Snowplow tracking for these events using the JavaScript tracker, pixel tracker, and click redirects.
Tracking Ad Impressions
There are two primary methods for tracking ad impressions in Snowplow:
- Using the JavaScript Tracker:
- Embed the JavaScript tracker in the ad tag.
- Fire a trackAdImpression event or a custom unstructured event.
- Ensure namespace management to prevent conflicts across multiple ad units on a page.
- Embed the JavaScript tracker in the ad tag.
// Generate a unique namespace to prevent clashes
var rnd = Math.random().toString(36).substring(2);
(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)};
p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//d1fc8wv8zag5ca.cloudfront.net/2.5.3/sp.js","adTracker"));
window.adTracker('newTracker', rnd, 'd3rkrsqld9gmqf.cloudfront.net', {
'encodeBase64': false
});
window.adTracker('trackAdImpression:' + rnd, '67965967893', 'cpa', 10, 'http://www.example.com', '23', '7', '201', '12');
- Using the Pixel Tracker:
- Avoids loading a full JavaScript file
- Add a GET request to the Snowplow collector for a 1x1 transparent pixel.
- Avoids loading a full JavaScript file
<img src="https://collector.snplow.com/i?e=se&p=web&tv=no-js-0.1.0&se_ca=ad&se_ac=impression&se_la={{advertiser_id}}&se_pr={{user_id}}">
Custom Schemas for Ad Impressions
- Define a schema in Iglu Central to accommodate specific ad server data points.
- Example schema:
{
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"self": {
"vendor": "com.snowplowanalytics.snowplow",
"name": "ad_impression",
"version": "1-0-0"
},
"properties": {
"impressionId": { "type": "string" },
"zoneId": { "type": "string" },
"bannerId": { "type": "string" },
"advertiserId": { "type": "string" }
}
}
Tracking Ad Clicks
Tracking ad clicks is more complex due to potential redirection and third-party cookie limitations. Snowplow provides a redirect mechanism to track ad clicks effectively:
- Update the ad link href to redirect through the Snowplow collector.
<a href="https://collector.snplow.com/r/tp2?u=https%3A%2F%2Fexample.com">Track Click</a>
- Parameters can be added to provide additional data points, such as campaign ID, user ID, or cost model.
Key Considerations and Best Practices
- Maintain a consistent schema across impression and click tracking.
- Leverage third-party cookies to link ad interactions with post-click events.
- Consider data privacy implications and user consent for third-party tracking.
For more advanced use cases, consider implementing structured events, custom contexts, or using Snowplow’s pipeline for data enrichment and processing.