diff --git a/gulpfile.js b/gulpfile.js index 2171d37966..7a0d1deb54 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -106,6 +106,12 @@ gulp.task('lib', ['clean:lib'], function () { src: [paths.npmDir + 'sweetalert/dist/sweetalert.css', paths.npmDir + 'sweetalert/dist/sweetalert.min.js', paths.npmDir + 'angular-sweetalert/SweetAlert.js'], dest: paths.libDir + 'sweetalert' + }, + { + src: [paths.npmDir + 'angulartics-google-analytics/lib/angulartics*.js', + paths.npmDir + 'angulartics/src/angulartics.js' + ], + dest: paths.libDir + 'angulartics' } ]; diff --git a/package.json b/package.json index 7c2210495e..0f86f4b4b2 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "q": "1.4.1", "angularjs-slider": "5.5.0", "sweetalert": "1.1.3", - "angular-sweetalert": "1.1.1" + "angular-sweetalert": "1.1.1", + "angulartics": "1.2.1", + "angulartics-google-analytics": "0.2.1" } } diff --git a/src/background.js b/src/background.js index 539299d2c2..93bff0ecfe 100644 --- a/src/background.js +++ b/src/background.js @@ -1,3 +1,4 @@ +var isBackground = true; var utilsService = new UtilsService(); var cryptoService = new CryptoService(); var tokenService = new TokenService(); diff --git a/src/manifest.json b/src/manifest.json index eadb9b9efc..b72d802e1e 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -12,6 +12,7 @@ "96": "images/icon96.png", "128": "images/icon128.png" }, + "content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'", "content_scripts": [ { "js": [ "content/autoFill.js" ], @@ -32,6 +33,7 @@ "lib/sjcl/bitArray.js", "lib/q/q.js", "scripts/tld.js", + "scripts/analyticsCode.js", "models/api/requestModels.js", "models/api/responseModels.js", "models/dataModels.js", @@ -47,7 +49,8 @@ "services/autofillService.js", "services/appIdService.js", "services/passwordGenerationService.js", - "background.js" + "background.js", + "scripts/analytics.js" ], "persistent": true }, diff --git a/src/popup/app/app.js b/src/popup/app/app.js index 397e36415a..6c203b2799 100644 --- a/src/popup/app/app.js +++ b/src/popup/app/app.js @@ -3,6 +3,8 @@ 'ui.router', 'ngAnimate', 'toastr', + 'angulartics', + 'angulartics.google.analytics', 'bit.directives', 'bit.services', diff --git a/src/popup/index.html b/src/popup/index.html index 07f96dc877..16bb3c5285 100644 --- a/src/popup/index.html +++ b/src/popup/index.html @@ -14,6 +14,8 @@ + + @@ -23,6 +25,8 @@ + + diff --git a/src/scripts/analytics.js b/src/scripts/analytics.js new file mode 100644 index 0000000000..db04d45041 --- /dev/null +++ b/src/scripts/analytics.js @@ -0,0 +1,26 @@ +var gaUtils = chrome.extension.getBackgroundPage().utilsService, + gaTrackingId = null; + +if (gaUtils.isChrome()) { + gaTrackingId = 'UA-81915606-6'; +} +else if (gaUtils.isFirefox()) { + gaTrackingId = 'UA-81915606-7'; +} +else if (gaUtils.isEdge()) { + gaTrackingId = 'UA-81915606-9'; +} +else if (gaUtils.isOpera()) { + gaTrackingId = 'UA-81915606-8'; +} + +if (gaTrackingId) { + ga('create', gaTrackingId, 'auto'); +} + +// Removes failing protocol check. ref: http://stackoverflow.com/a/22152353/1958200 +ga('set', 'checkProtocolTask', function () { }); + +if (typeof isBackground !== 'undefined') { + ga('send', 'pageview', '/background.html'); +} diff --git a/src/scripts/analyticsCode.js b/src/scripts/analyticsCode.js new file mode 100644 index 0000000000..d17b25d22a --- /dev/null +++ b/src/scripts/analyticsCode.js @@ -0,0 +1,5 @@ +(function (i, s, o, g, r, a, m) { +i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { +(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), +m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) +})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');