Skip to content

Commit

Permalink
Ads: track external links on ads landing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwick committed Feb 13, 2015
1 parent c8b9a84 commit cd6e489
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
6 changes: 5 additions & 1 deletion reddit_about/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class About(Plugin):
'about-team.js',
'about-postcards.js',
prefix='about/',
)
),
'advertising': Module('advertising.js',
'advertising.js',
prefix='advertising/',
),
}

def add_routes(self, mc):
Expand Down
35 changes: 35 additions & 0 deletions reddit_about/public/static/js/advertising/advertising.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
!function(r, $) {
'use strict';

$(function() {
$('a[href]').on('click', function(e) {
var el = this;
var $el = $(el);
var href = $el.attr('href');
var linkHost = href.match(/^https?:\/\/([^\/]+)/) && RegExp.$1;

// only tracking external links
if (linkHost === window.location.host) {
return true;
}

// get the name of the nearest parent element with a selfserve-* css class
// so the sales team can tell which instance of the link it is
var parentClass = $el.closest('[class^=selfserve]').attr('class');
var newTab = !!(el.target && el.target === '_blank');
var callback = newTab ? undefined : function() {
window.location.href = el.href;
};

r.analytics.fireGAEvent(
'advertising',
'external-link',
_.compact([parentClass, href]).join(':'),
undefined,
undefined,
callback);

return newTab;
});
});
}(r, jQuery);
2 changes: 1 addition & 1 deletion reddit_about/templates/advertising.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ <h1>${thing.banner.title}</h1>
<div class="col-4">
<a href="${thing.create_ad_url}" class="create-ad-button primary-button button">${_("create an ad")}</a>
<small>${_("budget larger than $30k?")}<br>
<a href="http://bit.ly/redditadvertising">${_("contact our sales team")}</a></small>
<a href="https://redditadvertising.typeform.com/to/OiZLa5">${_("contact our sales team")}</a></small>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions reddit_about/templates/advertisingpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
${parent.stylesheet()}
${less_stylesheet('selfserve.less')}
</%def>

<%def name="javascript_bottom()">
${parent.javascript_bottom()}
<% from r2.lib import js %>
${unsafe(js.use('advertising'))}
</%def>

0 comments on commit cd6e489

Please sign in to comment.