mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-01 13:13:36 +01:00
move google analytics to measurements protocol so that we can get rid of custom CSP
This commit is contained in:
parent
293308b8bb
commit
56bd98fa43
@ -12,7 +12,6 @@
|
|||||||
"96": "images/icon96.png",
|
"96": "images/icon96.png",
|
||||||
"128": "images/icon128.png"
|
"128": "images/icon128.png"
|
||||||
},
|
},
|
||||||
"content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'",
|
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"js": [ "content/autoFill.js" ],
|
"js": [ "content/autoFill.js" ],
|
||||||
@ -28,7 +27,6 @@
|
|||||||
"lib/sjcl/bitArray.js",
|
"lib/sjcl/bitArray.js",
|
||||||
"lib/q/q.js",
|
"lib/q/q.js",
|
||||||
"scripts/tld.js",
|
"scripts/tld.js",
|
||||||
"scripts/analyticsCode.js",
|
|
||||||
"models/api/requestModels.js",
|
"models/api/requestModels.js",
|
||||||
"models/api/responseModels.js",
|
"models/api/responseModels.js",
|
||||||
"models/dataModels.js",
|
"models/dataModels.js",
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
<script src="../lib/jquery/jquery.js"></script>
|
<script src="../lib/jquery/jquery.js"></script>
|
||||||
<script src="../lib/bootstrap/js/bootstrap.js"></script>
|
<script src="../lib/bootstrap/js/bootstrap.js"></script>
|
||||||
<script src="../lib/clipboard/clipboard.js"></script>
|
<script src="../lib/clipboard/clipboard.js"></script>
|
||||||
<script src="../scripts/analyticsCode.js"></script>
|
|
||||||
<script src="../scripts/analytics.js"></script>
|
<script src="../scripts/analytics.js"></script>
|
||||||
|
|
||||||
<script src="../lib/angular/angular.js"></script>
|
<script src="../lib/angular/angular.js"></script>
|
||||||
|
@ -1,15 +1,52 @@
|
|||||||
var gaTrackingId = chrome.extension.getBackgroundPage().utilsService.analyticsId();
|
var gaTrackingId = chrome.extension.getBackgroundPage().utilsService.analyticsId();
|
||||||
|
var gaFunc = null;
|
||||||
|
window.ga = function (action, param1, param2, param3, param4) {
|
||||||
|
if (!gaFunc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (gaTrackingId) {
|
gaFunc(action, param1, param2, param3, param4);
|
||||||
ga('create', gaTrackingId, 'auto');
|
};
|
||||||
|
|
||||||
|
function gaTrackEvent(options) {
|
||||||
|
return '&t=event&ec=' + (options.eventCategory ? encodeURIComponent(options.eventCategory) : 'Event') +
|
||||||
|
'&ea=' + encodeURIComponent(options.eventAction) +
|
||||||
|
(options.eventLabel ? '&el=' + encodeURIComponent(options.eventLabel) : '') +
|
||||||
|
(options.eventValue ? '&ev=' + encodeURIComponent(options.eventValue) : '') +
|
||||||
|
(options.page ? '&dp=' + encodeURIComponent(options.page) : '') +
|
||||||
|
(document && document.title ? '&dt=' + encodeURIComponent(document.title) : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// version dimension
|
function gaTrackPageView(pagePath) {
|
||||||
ga('set', 'dimension1', chrome.runtime.getManifest().version);
|
return '&t=pageview&dp=' + encodeURIComponent(pagePath) +
|
||||||
|
(document && document.title ? '&dt=' + encodeURIComponent(document.title) : '');
|
||||||
// Removes failing protocol check. ref: http://stackoverflow.com/a/22152353/1958200
|
|
||||||
ga('set', 'checkProtocolTask', function () { });
|
|
||||||
|
|
||||||
if (typeof isBackground !== 'undefined') {
|
|
||||||
ga('send', 'pageview', '/background.html');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chrome.extension.getBackgroundPage().appIdService.getAnonymousAppId(function (gaAnonAppId) {
|
||||||
|
gaFunc = function (action, param1, param2, param3, param4) {
|
||||||
|
if (action !== 'send' || !param1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var version = encodeURIComponent(chrome.runtime.getManifest().version);
|
||||||
|
var message = 'v=1&tid=' + gaTrackingId + '&cid=' + gaAnonAppId + '&cd1=' + version;
|
||||||
|
|
||||||
|
if (param1 === 'pageview' && param2) {
|
||||||
|
message += gaTrackPageView(param2);
|
||||||
|
}
|
||||||
|
else if (param1 === 'event' && param2) {
|
||||||
|
message += gaTrackEvent(param2);
|
||||||
|
}
|
||||||
|
else if (typeof param1 === 'object' && param1.hitType === 'event') {
|
||||||
|
message += gaTrackEvent(param1);
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
request.open('POST', 'https://www.google-analytics.com/collect', true);
|
||||||
|
request.send(message);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof isBackground !== 'undefined') {
|
||||||
|
ga('send', 'pageview', '/background.html');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
(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');
|
|
@ -8,10 +8,18 @@ function initAppIdService() {
|
|||||||
throw 'callback function required';
|
throw 'callback function required';
|
||||||
}
|
}
|
||||||
|
|
||||||
makeAndGetAppId('appId');
|
makeAndGetAppId('appId', callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
function makeAndGetAppId(key) {
|
AppIdService.prototype.getAnonymousAppId = function (callback) {
|
||||||
|
if (!callback || typeof callback !== 'function') {
|
||||||
|
throw 'callback function required';
|
||||||
|
}
|
||||||
|
|
||||||
|
makeAndGetAppId('anonymousAppId', callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
function makeAndGetAppId(key, callback) {
|
||||||
chrome.storage.local.get(key, function (obj) {
|
chrome.storage.local.get(key, function (obj) {
|
||||||
if (obj && obj[key]) {
|
if (obj && obj[key]) {
|
||||||
callback(obj[key]);
|
callback(obj[key]);
|
||||||
|
Loading…
Reference in New Issue
Block a user