Skip to content

Commit

Permalink
Update: Analytics now will store channel name in local storage so it …
Browse files Browse the repository at this point in the history
…will not request omahaproxy for channel list
  • Loading branch information
jarrodek committed Apr 8, 2016
1 parent e2f28ac commit 4487668
Showing 1 changed file with 88 additions and 33 deletions.
121 changes: 88 additions & 33 deletions app/scripts/libs/app.analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ arc.app.analytics.setAnalyticsPermitted = function(permitted) {
});
});
};

/**
* Initialize and set up custom dimmenstion that are used by the app.
*/
Expand Down Expand Up @@ -168,8 +169,6 @@ arc.app.analytics._setCustomDimmensions = function() {
* This information will be used in compliance with Google Analytics terms & conditions
* which disallows any user information to be send to the GA server.
* It's only for statistical reports.
*
* TODO: Add possibility to disable tracking code in settings.
*/
arc.app.analytics._setAppUid = function() {
var setUid = function(uuid) {
Expand Down Expand Up @@ -206,55 +205,111 @@ arc.app.analytics._setChromeChannel = function() {
if (arc.app.analytics.debug) {
console.log('Setting up chrome channel');
}
arc.app.analytics._loadCSV()
.then(function(obj) {
if (!(obj instanceof Array)) {
return;
arc.app.analytics._getChannelName()
.then((channel) => {
if (!channel) {
if (arc.app.analytics.debug) {
console.info('[Google Analytics] Chrome Channel can\'t be determined.');
}
let chromeVersion = arc.app.utils.chromeVersion;
for (let i = 0, size = obj.length; i < size; i++) {
let system = obj[i];
for (let k = 0; k < system.versions.length; k++) {
var version = system.versions[k];
/*jshint camelcase: false */
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
if (version.current_version === chromeVersion ||
version.previous_version === chromeVersion) {
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
/*jshint camelcase: true */
let channel = version.channel;
for (let j = 0, len = arc.app.analytics._trackers.length; j < len; j++) {
arc.app.analytics._trackers[j].set('dimension3', channel);
}
if (arc.app.analytics.debug) {
console.info('[Google Analytics] Setting up custom dimension #%d: %s', 3, channel);
}
return;
}
return;
}
for (let j = 0, len = arc.app.analytics._trackers.length; j < len; j++) {
arc.app.analytics._trackers[j].set('dimension3', channel);
}
if (arc.app.analytics.debug) {
console.info('[Google Analytics] Setting up custom dimension #%d: %s', 3, channel);
}
})
.catch(function(cause) {
if (arc.app.analytics.debug) {
console.info('Unable to download Chrome channels list', cause);
}
});
};

arc.app.analytics._getChannelName = function() {
return arc.app.analytics._getChannelInfo()
.then((channel) => {
if (channel) {
return channel;
}
return arc.app.analytics._loadCSV();
})
.then((result) => {
if (typeof result === 'string') {
return result;
}
if (!(result instanceof Array)) {
return null;
}
let chromeVersion = arc.app.utils.chromeVersion;
let channel = null;
for (let i = 0, size = result.length; i < size; i++) {
let system = result[i];
for (let k = 0; k < system.versions.length; k++) {
var version = system.versions[k];
/*jshint camelcase: false */
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
if (version.current_version === chromeVersion ||
version.previous_version === chromeVersion) {
// jscs:enable requireCamelCaseOrUpperCaseIdentifiers
/*jshint camelcase: true */
channel = version.channel;
break;
}
}
})
.catch(function(cause) {
if (arc.app.analytics.debug) {
console.info('Unable to download Chrome channels list', cause);
}
});
}
if (channel) {
return arc.app.analytics._setChannelInfo(channel)
.then(() => channel);
}
return null;
});
};
/**
* Loads a CSV data with chrome data.
*
* @return {Object} Promise will result with parsed object of the current channels.
*/
arc.app.analytics._loadCSV = function() {

var init = {
//mode: 'no-cors',
cache: 'force-cache'
};
return fetch('https://omahaproxy.appspot.com/all.json', init)
var os = arc.app.utils.osInfo.osName.toLocaleLowerCase();
if (os.indexOf('win') !== -1) {
os = 'win';
} else if (os.indexOf('mac') !== -1) {
os = 'mac';
} else if (os.indexOf('linux') !== -1) {
os = 'linux';
} else {
os = null;
}
var url = 'https://omahaproxy.appspot.com/all.json';
if (os) {
url += '?os=' + os;
}
return fetch(url, init)
.then(function(response) {
return response.json();
});
};
arc.app.analytics._getChannelInfo = function() {
return new Promise(function(resolve) {
chrome.storage.local.get({'chromeChannel': null}, function(result) {
resolve(result.chromeChannel);
});
});
};
arc.app.analytics._setChannelInfo = function(channel) {
return new Promise(function(resolve) {
chrome.storage.local.set({'chromeChannel': channel}, function() {
resolve();
});
});
};
arc.app.analytics._setupAnalyticsListener = function() {
arc.app.analytics._trackers.forEach(function(tracker) {
arc.app.analytics._addDebugListeners(tracker);
Expand Down

0 comments on commit 4487668

Please sign in to comment.