Skip to content

Commit

Permalink
track feed loading errors closes #4140
Browse files Browse the repository at this point in the history
  • Loading branch information
myleshorton committed Apr 28, 2016
1 parent 312cccf commit ce17b34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Expand Up @@ -3,7 +3,7 @@
/*
Feeds directive shows localStorge cached feeds if available, and fetch server
in same time. It re-renders the feeds when remote feeds fetched, or calls
onError() if failed to fetch. The feeds will be cached for 24 hours.
onError() if failed to fetch.
*/
angular.module('feeds-directives', []).directive('feed', ['feedService', '$compile', '$templateCache', '$http', function (feedService, $compile, $templateCache, $http) {
return {
Expand All @@ -13,7 +13,7 @@ angular.module('feeds-directives', []).directive('feed', ['feedService', '$compi
onFeedsLoaded: '&',
onError: '&onError'
},
controller: ['$scope', '$element', '$attrs', '$q', '$sce', '$timeout', 'feedCache', function ($scope, $element, $attrs, $q, $sce, $timeout, feedCache) {
controller: ['$scope', '$element', '$attrs', '$q', '$sce', '$timeout', 'feedCache', 'gaMgr', function ($scope, $element, $attrs, $q, $sce, $timeout, feedCache, gaMgr) {
$scope.$watch('finishedLoading', function (value) {
if ($attrs.postRender && value) {
$timeout(function () {
Expand Down Expand Up @@ -69,7 +69,7 @@ angular.module('feeds-directives', []).directive('feed', ['feedService', '$compi
render(feedsObj);
deferred.resolve(feedsObj);
} else {
feedService.getFeeds(url, $attrs.fallbackUrl).then(function (feedsObj) {
feedService.getFeeds(url, $attrs.fallbackUrl, gaMgr).then(function (feedsObj) {
console.log("fresh copy of feeds loaded");
feedCache.set(url, feedsObj);
render(feedsObj);
Expand Down
Expand Up @@ -2,7 +2,7 @@

angular.module('feeds-services', []).factory('feedService', ['$q', '$http', function ($q, $http, $sce) {

var getFeeds = function (feedURL, fallbackURL) {
var getFeeds = function (feedURL, fallbackURL, gaMgr) {
var deferred = $q.defer();

var handleResponse = function (response) {
Expand All @@ -16,6 +16,7 @@ angular.module('feeds-services', []).factory('feedService', ['$q', '$http', func

var handleError = function(response) {
if (response.status) {
gaMgr.trackFeedError(response.config.url, response.status);
if (response.config.url !== fallbackURL) {
$http.get(fallbackURL).then(handleResponse, handleError);
return;
Expand Down
8 changes: 7 additions & 1 deletion src/github.com/getlantern/lantern-ui/app/js/services.js
Expand Up @@ -214,6 +214,11 @@ angular.module('app.services', [])
ga()('send', 'event', 'feed-' + name);
};

var trackFeedError = function(url, statusCode) {
var eventName = 'feed-loading-error-' + url + "-status-"+statusCode;
ga()('send', 'event', eventName);
};

var enableTracking = function() {
console.log("enabling ga.")
enabled = true;
Expand All @@ -234,7 +239,8 @@ angular.module('app.services', [])
trackSocialLink: trackSocialLink,
trackLink: trackLink,
trackBookmark: trackBookmark,
trackFeed: trackFeed
trackFeed: trackFeed,
trackFeedError: trackFeedError
};
})
.service('apiSrvc', function($http, API_URL_PREFIX) {
Expand Down

0 comments on commit ce17b34

Please sign in to comment.