Permalink
Browse files

Bug 821016: Add download click tracking to direct link.

* Refactor for more DRY.
* Fix some jshint complaints.

Code by Jon Petto.
  • Loading branch information...
1 parent 608741d commit 9c2ed10e9c4fd2d6cddc62d9b5ba97a62e8da423 @pmac pmac committed Dec 22, 2012
Showing with 27 additions and 16 deletions.
  1. +27 −16 media/js/firefox/new.js
View
@@ -1,4 +1,4 @@
-;(function($, Modernizr, _gaq, site) {
+;(function(window, $, Modernizr, _gaq, site) {
'use strict';
if (site.platform === 'android') {
@@ -15,28 +15,43 @@
$('body').addClass('ready-for-scene2');
});
+ function ga_track() {
+ if (_gaq) {
+ // track download click
+ _gaq.push(['_trackPageview',
+ '/en-US/products/download.html?referrer=new-b']);
+ }
+ }
+
+ function dl_redirect(url) {
+ // delay redirect to ensure GA tracking occurs
+ window.setTimeout(function() {
+ window.location.href = url;
+ }, 300);
+ }
+
// Bind events on domReady.
$(function() {
// Pull Firefox download link from the download button and add to the
// 'click here' link.
// TODO: Remove and generate link in bedrock.
var $li = $('.download-list li:visible').filter(':first');
- var ff_dl_link = $li.find('a:first').attr('href');
- $('#direct-download-link').attr('href', ff_dl_link);
+ var ff_dl_url = $li.find('a:first').attr('href');
+ $('#direct-download-link').attr('href', ff_dl_url).on('click', function(e) {
+ e.preventDefault();
+ ga_track();
+ dl_redirect($(this).attr('href'));
+ });
// Trigger animation after download.
var $scene2 = $('#scene2');
var $stage = $('#stage-firefox');
var $thankYou = $('.thankyou');
$('.download-firefox').on('click', function(e) {
- // cancel natural event
e.preventDefault();
+ var $link = $(this);
+ ga_track();
- // track download click
- if (_gaq) {
- _gaq.push(['_trackPageview',
- '/en-US/products/download.html?referrer=new-b']);
- }
if (!Modernizr.csstransitions) {
$scene2.css('visibility', 'visible');
$stage.animate({
@@ -49,16 +64,12 @@
// transitionend fires multiple times in FF 17, including
// before the transition actually finished.
// Work-around with setTimeout.
- setTimeout(function() {
+ window.setTimeout(function() {
$thankYou.focus();
}, 500);
}
- // delay natural event
- var that = this;
- setTimeout(function() {
- window.location.href = $(that).attr('href');
- }, 300);
+ dl_redirect($link.attr('href'));
});
});
-})(window.jQuery, window.Modernizr, window._gaq, window.site);
+})(window, window.jQuery, window.Modernizr, window._gaq, window.site);

0 comments on commit 9c2ed10

Please sign in to comment.