Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

Commit

Permalink
Enable Analytics to track if upcoming change to API v3 breaks users
Browse files Browse the repository at this point in the history
  • Loading branch information
manastungare committed Oct 22, 2014
1 parent f0de40b commit 86fa149
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ background.BadgeProperties;
* Initializes the background page by registering listeners.
*/
background.initialize = function() {
utils.startAnalytics_();
background.initMomentJs_();
background.listenForRequests_();
background.listenForTabUpdates_();
Expand Down Expand Up @@ -210,5 +211,4 @@ background.updateBadge = function(props) {
}
};


background.initialize();
7 changes: 7 additions & 0 deletions src/browser_action.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ browseraction.CALENDAR_UI_URL_ = 'https://www.google.com/calendar/';
* Initializes UI elements in the browser action popup.
*/
browseraction.initialize = function() {
utils.startAnalytics_();
_gaq.push(['_trackEvent', 'Popup', 'Shown']);
browseraction.fillMessages_();
browseraction.installButtonClickHandlers_();
browseraction.showLoginMessageIfNotAuthenticated_();
Expand Down Expand Up @@ -87,20 +89,24 @@ browseraction.fillMessages_ = function() {
*/
browseraction.installButtonClickHandlers_ = function() {
$('#show_quick_add').on('click', function() {
_gaq.push(['_trackEvent', 'Quick Add', 'UI Shown']);
$('#quick-add').slideDown(200);
$('#quick-add-event-title').focus();
});

$('#sync_now').on('click', function() {
_gaq.push(['_trackEvent', 'Fetch', 'Manual Refresh']);
chrome.extension.sendMessage({method: 'events.feed.fetch'},
browseraction.showEventsFromFeed_);
});

$('#show_options').on('click', function() {
_gaq.push(['_trackEvent', 'Options', 'View']);
chrome.tabs.create({'url': 'options.html'});
});

$('#quick_add_button').on('click', function() {
_gaq.push(['_trackEvent', 'Quick Add', 'Event Created']);
var event = /** @type {CalendarEvent} */ ({});
event.title = event.description = $('#quick-add-event-title').val().toString();
event = utils.processEvent(event);
Expand All @@ -118,6 +124,7 @@ browseraction.showLoginMessageIfNotAuthenticated_ = function() {
// Check if we're authenticated or not, and display either the "Login Now"
// message, or show the tab strip.
if (!chrome.extension.getBackgroundPage().feeds.isAuthenticated) {
_gaq.push(['_trackEvent', 'Popup', 'Not Authenticated']);
$('#error').show();
$('#calendar-events').hide();

Expand Down
1 change: 1 addition & 0 deletions src/context_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ menu.installContextMenu_ = function() {
* @private
*/
menu.onClicked_ = function(info, tab) {
_gaq.push(['_trackEvent', 'Context Menu', 'Shown']);
var event = /** @type {CalendarEvent} */ ({});
event.title = info.selectionText;
event.url = tab.url;
Expand Down
3 changes: 3 additions & 0 deletions src/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ feeds.fetchCalendars = function() {
var storedCalendars = storage['calendars'] || {};

$.get(feeds.CALENDAR_LIST_FEED_URL_, function(data) {
_gaq.push(['_trackEvent', 'Fetch', 'CalendarList']);
feeds.isAuthenticated = true;

var calendars = {};
Expand Down Expand Up @@ -131,6 +132,7 @@ feeds.fetchCalendars = function() {
});

}).error(function(response) {
_gaq.push(['_trackEvent', 'Fetch', 'Error', response.statusText]);
chrome.extension.sendMessage({method: 'sync-icon.spinning.stop'});
if (response.status === 401) {
feeds.isAuthenticated = false;
Expand Down Expand Up @@ -229,6 +231,7 @@ feeds.fetchEventsFromCalendar_ = function(feed, callback) {

$.get(feedUrl, (function(feed) {
return function(data) {
_gaq.push(['_trackEvent', 'Fetch', 'Events']);
feeds.isAuthenticated = true;
var events = [];
$(data).find('entry').each(function() {
Expand Down
5 changes: 3 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"manifest_version": 2,
"name": "__MSG_google_calendar_extension_name__",
"description": "__MSG_google_calendar_extension_desc__",
"version": "1.4.7.2",
"version": "1.4.8",
"default_locale": "en",
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCzO8gAn6n4s5Ohs50F2lmLGsO0FVKIwYyro8qZHlU+9pF85wGBEqoNwSeawr+AZdLgtnQRkIgatLM68EX8sB0DErp3Ds4qCvY8VufvvDIoqxdKtC3QlFxR9PoUZMY7/4lb/OadWnr0UjekxcSNVyk6nqZkTFCcE7RWDMDZ8qwqsQIDAQAB",

"icons": {
"16": "icons/event_calendar-lb16.png",
Expand All @@ -27,7 +28,7 @@
"https://www.google.com/calendar/*"
],

"content_security_policy": "script-src 'self' https://www.google.com; object-src 'self'",
"content_security_policy": "script-src 'self' https://www.google.com https://ssl.google-analytics.com; object-src 'self'",

"background": {
"scripts": [
Expand Down
34 changes: 10 additions & 24 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,14 @@ utils.getFirstFieldText = function(element, selector) {
};


/**
* Adapted from:
* http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color
* @param {string} color A hex color (e.g. '#ff0000').
* @param {number} amount How much to lighten or darken the color by.
* @return {string} The lightened or darkened color.
*/
utils.darkenColor = function(color, amount) {
color = color.substring(1); // Remove the '#'.
var num = parseInt(color, 16);
var r = (num >> 16) + amount;
var b = ((num >> 8) & 0x00FF) + amount;
var g = (num & 0x0000FF) + amount;

var rStr = (r.toString(16).length < 2) ? '0' + r.toString(16) : r.toString(16);
var gStr = (g.toString(16).length < 2) ? '0' + g.toString(16) : g.toString(16);
var bStr = (b.toString(16).length < 2) ? '0' + b.toString(16) : b.toString(16);

var newColor = g | (b << 8) | (r << 16);
newColor = newColor.toString(16);
if (newColor.length == 5) {
newColor = '0' + newColor;
}
return '#' + newColor;
utils.startAnalytics_ = function() {
window._gaq = window._gaq || [];
_gaq.push(['_setAccount', 'UA-21917188-3']);

var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
};

0 comments on commit 86fa149

Please sign in to comment.