Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1040 from ngokevin/uaupdate
Browse files Browse the repository at this point in the history
refresh UA tracking code (bug 1103180)
  • Loading branch information
ngokevin committed Mar 9, 2015
2 parents d8f3b35 + c814651 commit 417762a
Show file tree
Hide file tree
Showing 36 changed files with 887 additions and 393 deletions.
2 changes: 1 addition & 1 deletion src/media/js/app_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define('app_list',
z.body.on('click', '.app-list-filters-expand-toggle', utils._pd(function() {
expand = !expand;
initTileState();
z.doc.trigger('scroll'); // For defer image loading.
z.doc.trigger('image-deferrer--load');
}));

z.page.on('loaded reloaded_chrome', function() {
Expand Down
35 changes: 17 additions & 18 deletions src/media/js/apps_buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ define('apps_buttons',
'core/user', 'core/utils', 'core/views', 'core/z'],
function(apps, cache, caps, defer, l10n,
log, login, models, notification, payments,
requests, settings, tracking_events, urls, user, utils,
requests, settings, trackingEvents, urls, user, utils,
views, z) {
var logger = log('buttons');
var gettext = l10n.gettext;
var apps_model = models('app');
var appModel = models('app');

z.page.one('iframe-install-loaded', function() {
markBtnsAsInstalled();
Expand Down Expand Up @@ -45,15 +45,15 @@ define('apps_buttons',

// Fetch the product from either model cache or data attr.
var $btn = $(this);
var product = apps_model.lookup($btn.closest('[data-slug]').data('slug')) ||
var product = appModel.lookup($btn.closest('[data-slug]').data('slug')) ||
$btn.data('product');
func.call(this, product);
};
}

var launchHandler = _handler(function(product) {
apps.launch(product.manifest_url);
tracking_events.track_app_launch(product);
trackingEvents.trackAppLaunch(product);
});

function install(product, $button, loginPopup) {
Expand Down Expand Up @@ -99,7 +99,7 @@ define('apps_buttons',
var def = defer.Deferred();

// Create a reference to the button.
var $this = $button || $(this);
$button = $button || $(this);
var _timeout;

// If the user has already purchased the app, we do need to generate
Expand All @@ -111,9 +111,10 @@ define('apps_buttons',
if (product.payment_required) {
// The app requires a payment.
logger.log('Starting payment flow for', product.name);

// Save the old text of the button.
$this.data('old-text', $this.find('em').text());
setInstallBtnState($this, gettext('Purchasing'), 'purchasing');
setInstallBtnState($button, gettext('Purchasing'), 'purchasing');

var purchaseOpts = {
// This will be undefined unless a window was created
Expand All @@ -124,9 +125,9 @@ define('apps_buttons',
logger.log('Purchase flow completed for', product.name);

// Update the button to say Install.
setInstallBtnState($this, gettext('Install'), 'purchased');
setInstallBtnState($button, gettext('Install'), 'purchased');
// Save the old text of the button.
$this.data('old-text', $this.find('em').text());
$this.data('old-text', $button.find('em').text());

// Update the cache to show that the app was purchased.
user.update_purchased(product.id);
Expand Down Expand Up @@ -174,21 +175,19 @@ define('apps_buttons',
}

function start_install() {
// Track the search term used to find this app, if applicable.
tracking_events.track_search_term();
tracking_events.track_app_install_begin(product, $this);
trackingEvents.trackAppInstallBegin($button);

// Make the button a spinner.
$this.data('old-text', $this.find('em').text())
$button.data('old-text', $button.find('em').text())
.addClass('spinning');

// Temporary timeout for hosted apps until we catch the appropriate
// download error event for hosted apps (in iframe).
if (!product.is_packaged && !product.payment_required) {
_timeout = setTimeout(function() {
if ($this.hasClass('spinning')) {
if ($button.hasClass('spinning')) {
logger.log('Spinner timeout for ', product.name);
revertButton($this);
revertButton($button);
notification.notification({
message: gettext('Sorry, we had trouble fetching this app\'s data. Please try again later.')
});
Expand Down Expand Up @@ -253,7 +252,7 @@ define('apps_buttons',
cache.bust(urls.api.url('installed'));
}

def.resolve(installer, product, $this);
def.resolve(installer, product, $button);
}).fail(function(error) {
if (error) {
notification.notification({message: error});
Expand Down Expand Up @@ -285,11 +284,11 @@ define('apps_buttons',
// multiple instances of the same button on the page.
mark_installed(product.manifest_url);
});
tracking_events.track_app_install_success(product, $this);
trackingEvents.trackAppInstallSuccess($button);
logger.log('Successful install for', product.name);
}, function() {
revertButton($this);
tracking_events.track_app_install_fail(product, $this);
revertButton($button);
trackingEvents.trackAppInstallFail($button);
logger.log('Unsuccessful install for', product.name);
});

Expand Down
11 changes: 7 additions & 4 deletions src/media/js/desktop_promo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Content for the desktop promo carousel.
*/
define('desktop_promo',
['core/capabilities', 'core/l10n', 'core/urls', 'core/utils',],
function(caps, l10n, urls, utils) {
['core/capabilities', 'core/l10n', 'core/urls', 'core/utils',
'tracking_events'],
function(caps, l10n, urls, utils, trackingEvents) {
'use strict';
var gettext = l10n.gettext;

Expand Down Expand Up @@ -40,8 +41,10 @@ define('desktop_promo',
text: gettext('Store and share any type of file with Box.'),
},
].map(function(item) {
item.url = utils.urlparams(item.url, {src: 'desktop-promo'});
return item;
item.url = utils.urlparams(item.url, {
src: trackingEvents.SRCS.desktopPromo
});
return item;
})
};
});
19 changes: 13 additions & 6 deletions src/media/js/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
*/
define('feed',
['collection_colors', 'edbrands', 'core/l10n', 'core/nunjucks',
'core/urls', 'core/utils', 'underscore', 'utils_local'],
'core/urls', 'core/utils', 'tracking_events', 'underscore',
'utils_local'],
function(colors, brands, l10n, nunjucks,
urls, utils, _, utils_local) {
urls, utils, trackingEvents, _,
utils_local) {
'use strict';
var gettext = l10n.gettext;

Expand Down Expand Up @@ -47,26 +49,31 @@ define('feed',
feedItem.isPreview = true;
break;
}
feedItem.src = 'featured-app';
feedItem.src = trackingEvents.SRCS.featuredApp;
break;
case 'brand':
feedItem.color = get_brand_color_class(feedItem);
feedItem.name = brands.get_brand_type(feedItem.type, feedItem.apps.length);
feedItem.src = 'branded-editorial-element';
feedItem.src = trackingEvents.SRCS.brand;
break;
case 'collection':
if (feedItem.type == 'promo') {
feedItem.isCollPromo = true;
} else {
feedItem.isCollListing = true;
}
feedItem.src = 'collection-element';
feedItem.src = trackingEvents.SRCS.collection;
break;
case 'shelf':
feedItem.src = 'operator-shelf-element';
feedItem.src = trackingEvents.SRCS.shelf;
break;
}

// Some cases, we want to persist the previous src, like Desktop Promo.
if (utils.getVars().src in trackingEvents.PERSISTENT_SRCS) {
feedItem.src = utils.getVars().src;
}

// Get the Feed detail page URL for the item.
if (feedItem.isApp) {
feedItem.landingUrl = urls.reverse('app', [feedItem.app.slug]);
Expand Down
25 changes: 12 additions & 13 deletions src/media/js/helpers_local.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ define('helpers_local',
['apps', 'categories', 'compat_filter', 'content-ratings',
'core/format', 'core/helpers', 'core/models', 'core/nunjucks',
'core/settings', 'core/urls', 'core/utils', 'core/z', 'feed', 'regions',
'user_helpers', 'utils_local'],
function(apps, categories, compat_filter, iarc,
'tracking_events', 'user_helpers', 'utils_local'],
function(apps, categories, compatFilter, iarc,
format, base_helpers, models, nunjucks,
settings, urls, utils, z, feed, regions,
user_helpers, utils_local) {
trackingEvents, user_helpers, utils_local) {
var filters = nunjucks.require('filters');
var globals = nunjucks.require('globals');

// developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
// toLocaleDateString() is unreliable ; on Firefox Android and FxOS, it
// will return the date in m/d/Y format, even if you try to pass custom
// locale and/or options!.
// To avoid having to ship a full re-implementation, we use
// Intl.DateTimeFormat(), which is equivalent but only present if the
// underlying platform has a full implementation, and fall back to Y-m-d.
// This gives us a pretty date format (e.g. Saturday, February 15, 2014) on
// desktop, and leaves something somewhat universal on phones (2014-02-15).
// toLocaleDateString() on FxAndroid and FxOS returns m/d/Y even if passing
// custom locale + options! To not ship full re-implementation, use
// Intl.DateTimeFormat(), which is equivalent, but only present if
// underlying platform has full implementation. Else fall back to Y-m-d.
// Pretty date format (e.g. Saturday, February 15, 2014) on desktop
// Something more universal (2014-02-15) on phones.
var dateFormat;
if (typeof Intl !== 'undefined' &&
typeof Intl.DateTimeFormat !== 'undefined') {
Expand Down Expand Up @@ -94,14 +92,15 @@ define('helpers_local',

/* Global variables, provided in default context. */
globals.CATEGORIES = categories;
globals.DEVICE_CHOICES = compat_filter.DEVICE_CHOICES;
globals.DEVICE_CHOICES = compatFilter.DEVICE_CHOICES;
globals.feed = feed;
globals.iarc_names = iarc.names;
globals.NEWSLETTER_LANGUAGES = settings.NEWSLETTER_LANGUAGES;
globals.REGIONS = regions.REGION_CHOICES_SLUG;
globals.user_helpers = user_helpers;
globals.PLACEHOLDER_ICON = urls.media('fireplace/img/icons/placeholder.svg');
globals.compat_filter = compat_filter;
globals.compat_filter = compatFilter;
globals.trackingEvents = trackingEvents;

/* Helpers functions, provided in the default context. */
function indexOf(arr, val) {
Expand Down
2 changes: 1 addition & 1 deletion src/media/js/image-deferrer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ define('image-deferrer', ['underscore', 'core/urls', 'core/z'], function(_, urls
}

// Defer image loading.
z.win.on('scroll resize', scrollListener);
z.win.on('scroll resize image-deferrer--load', scrollListener);

function loadImages() {
// Calculate viewport loading boundaries (vertical).
Expand Down
9 changes: 8 additions & 1 deletion src/media/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,14 @@ require([
consumer_info.promise.done(function() {
logger.log('Triggering initial navigation');
if (!z.spaceheater) {
z.page.trigger('navigate', [window.location.pathname + window.location.search]);
var navigateArgs = [window.location.pathname +
window.location.search];
var searchQuery = utils.getVars().q;
if (window.location.pathname == urls.reverse('search') &&
searchQuery) {
navigateArgs.push({search_query: searchQuery});
}
z.page.trigger('navigate', navigateArgs);
} else {
z.page.trigger('loaded');
}
Expand Down

0 comments on commit 417762a

Please sign in to comment.