Comment embeds: track embed views without PII

Use the anonymous event tracker on embed views to prevent sending
any personally identifiable information.
This commit is contained in:
David Wick
2015-02-10 13:01:10 -08:00
parent 3cef415158
commit dd82ca82bc
5 changed files with 19 additions and 4 deletions

View File

@@ -122,6 +122,7 @@ clicktracker_url = /click
uitracker_url = /pixel/of_discovery.png
# embeds pixel tracking url
eventtracker_url = /pixel/of_delight.png
anon_eventtracker_url = /pixel/of_diversity.png
# google analytics token
googleanalytics =
# google analytics events sampling rate. Valid values are 1-100.

View File

@@ -82,6 +82,7 @@ def set_up_embed(embed_key, sr, thing, showedits):
c.embed_config = {
"eventtracker_url": g.eventtracker_url or "",
"anon_eventtracker_url": g.anon_eventtracker_url or "",
"created": iso_timestamp,
"showedits": showedits,
"thing": {

View File

@@ -174,6 +174,7 @@ def js_config(extra_config=None):
"clicktracker_url": g.clicktracker_url,
"uitracker_url": g.uitracker_url,
"eventtracker_url": g.eventtracker_url,
"anon_eventtracker_url": g.anon_eventtracker_url,
"comment_embed_scripts": js.src("comment-embed", absolute=True, mangle_name=False),
"static_root": static(''),
"over_18": bool(c.over18),

View File

@@ -62,9 +62,10 @@
var tracker = new App.PixelTracker({
url: config.eventtracker_url,
anonymousUrl: config.anon_eventtracker_url,
});
tracker.send(createPayload(type, 'view'));
tracker.send(createPayload(type, 'view'), {anonymous: true});
function trackLink(e) {
var el = this;

View File

@@ -2,12 +2,23 @@
var PixelTracker = App.PixelTracker = function(options) {
this._pixelTrackingUrl = options.url;
this._anonymousPixelTrackingUrl = options.anonymousUrl;
};
PixelTracker.prototype.send = function(payload, callback) {
PixelTracker.prototype.send = function(payload, options, callback) {
// Overload #send(payload, callback)
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
callback = callback || function() {};
if (!this._pixelTrackingUrl || !payload) {
var url = options.anonymous ?
this._anonymousPixelTrackingUrl : this._pixelTrackingUrl;
if (!payload || !url) {
callback();
return;
@@ -19,7 +30,7 @@
var buster = Math.round(Math.random() * 2147483647);
image.onload = callback;
image.src = this._pixelTrackingUrl +
image.src = url +
'?r=' + buster +
'&data=' + encodeURIComponent(JSON.stringify(payload));
};