From 86fa149640a034ebf58d92e7fe9659a9e855df3d Mon Sep 17 00:00:00 2001 From: Manas Tungare Date: Wed, 22 Oct 2014 16:35:18 -0700 Subject: [PATCH] Enable Analytics to track if upcoming change to API v3 breaks users --- src/background.js | 2 +- src/browser_action.js | 7 +++++++ src/context_menu.js | 1 + src/feeds.js | 3 +++ src/manifest.json | 5 +++-- src/utils.js | 34 ++++++++++------------------------ 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/background.js b/src/background.js index cf60281..bf47fdd 100644 --- a/src/background.js +++ b/src/background.js @@ -68,6 +68,7 @@ background.BadgeProperties; * Initializes the background page by registering listeners. */ background.initialize = function() { + utils.startAnalytics_(); background.initMomentJs_(); background.listenForRequests_(); background.listenForTabUpdates_(); @@ -210,5 +211,4 @@ background.updateBadge = function(props) { } }; - background.initialize(); diff --git a/src/browser_action.js b/src/browser_action.js index 9d60ba9..58ebaf8 100644 --- a/src/browser_action.js +++ b/src/browser_action.js @@ -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_(); @@ -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); @@ -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(); diff --git a/src/context_menu.js b/src/context_menu.js index 4d541c8..8d3db04 100644 --- a/src/context_menu.js +++ b/src/context_menu.js @@ -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; diff --git a/src/feeds.js b/src/feeds.js index a2e44bc..6ad9559 100644 --- a/src/feeds.js +++ b/src/feeds.js @@ -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 = {}; @@ -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; @@ -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() { diff --git a/src/manifest.json b/src/manifest.json index baf529e..df0cc0d 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -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", @@ -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": [ diff --git a/src/utils.js b/src/utils.js index 7ba5953..f957f4c 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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); };