Reporting changes - Report PolyGerrit page (without any PII) to Google Analytics. - Ramp up sample rate to 100%. - Disable built-in page tracking since it's not tracking PolyGerrit. Change-Id: I88dab62d440ae04ca68726915c7dc28cda6ca6a2
diff --git a/background.js b/background.js index 7941bb0..7f038a8 100644 --- a/background.js +++ b/background.js
@@ -14,7 +14,7 @@ var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-73551813-1']); -_gaq.push(['_trackPageview']); +_gaq.push(['_setSiteSpeedSampleRate', 100]); (function() { var ga = document.createElement('script'); @@ -26,17 +26,25 @@ })(); var RequestType = { - NAV: 'nav', + NAV: 'nav-report', TIMING: 'timing-report', }; -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { - if (request.type === RequestType.TIMING) { - var detail = request.detail; - _gaq.push(['_trackTiming', detail.category, detail.name, detail.value]); - } else if (request.type === RequestType.NAV) { - _gaq.push(['_trackPageview', request.url]); +chrome.runtime.onMessage.addListener(function(request) { + var detail = request.detail; + if (detail.host) { + _gaq.push(['_setDomainName', detail.host]); } + + switch (request.type) { + case RequestType.TIMING: + var time = Math.round(detail.value); + _gaq.push(['_trackTiming', detail.category, detail.name, time]); + break; + case RequestType.NAV: + _gaq.push(['_trackPageview', detail.value]); + break; + }; }); function loadImage(path, width, height) {
diff --git a/content.js b/content.js index d96f0ae..55a2804 100644 --- a/content.js +++ b/content.js
@@ -12,16 +12,24 @@ // See the License for the specific language governing permissions and // limitations under the License. (function() { - // TODO(andybons): Integrate with the Gerrit JS API. Since this is loaded - // before the Gerrit object is in scope, this type of integration may require - // an event to be fired to indicate that the Gerrit object is available. var appEl = document.querySelector('gr-app'); var isPolyGerrit = !!appEl; + if (isPolyGerrit) { - // TODO(andybons): Track actions and integrate with the Gerrit JS API. - // PageJS isn't in scope and is a pain to latch on to for navigation events. - document.addEventListener('timing-report', function(e) { - chrome.runtime.sendMessage({type: 'timing-report', detail: e.detail}); + var reportToBackground = function(e) { + e.detail.host = location.host; + chrome.runtime.sendMessage({type: e.type, detail: e.detail}); + }; + document.addEventListener('timing-report', reportToBackground); + document.addEventListener('nav-report', reportToBackground); + } else { + chrome.runtime.sendMessage({ + type: 'nav-report', + detail: { + value: '/#/', // Report GWT UI as dashboards landing url. + host: location.host, + }, }); } + })();
diff --git a/manifest.json b/manifest.json index 9fca4ae..39a68fb 100644 --- a/manifest.json +++ b/manifest.json
@@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Gerrit UI Switcher", "description": "Easily switch between the current Gerrit UI and the new PolyGerrit UI", - "version": "0.5.1", + "version": "0.5.2", "background": { "scripts": [ "background.js"