Merge pull request #231 from Bitcoin-com/wallet/task/505
505 - BitAnalytics 0.2.1 with GA
This commit is contained in:
commit
75843c68ff
10 changed files with 245 additions and 66 deletions
|
|
@ -163,7 +163,7 @@ module.exports = function(grunt) {
|
|||
},
|
||||
bitanalytics: {
|
||||
src: [
|
||||
'bitanalytics/bitanalytics-0.1.0.js'
|
||||
'bitanalytics/bitanalytics.js'
|
||||
],
|
||||
dest: 'www/lib/bitanalytics.js'
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6276,7 +6276,7 @@ var ClickAction = /** @class */ (function (_super) {
|
|||
}(action_1.default));
|
||||
exports.default = ClickAction;
|
||||
|
||||
},{"../action":4,"../log-event":15,"../log-event-handlers":14}],6:[function(require,module,exports){
|
||||
},{"../action":4,"../log-event":16,"../log-event-handlers":15}],6:[function(require,module,exports){
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
|
|
@ -6315,7 +6315,7 @@ var BitAnalytics = /** @class */ (function () {
|
|||
exports.default = BitAnalytics;
|
||||
BitAnalytics.main();
|
||||
|
||||
},{"./action-factory":2,"./action-handlers":3,"./channels/adjust-channel":9,"./channels/mixpanel-channel":12,"./log-event":15,"./log-event-handlers":14}],7:[function(require,module,exports){
|
||||
},{"./action-factory":2,"./action-handlers":3,"./channels/adjust-channel":9,"./channels/mixpanel-channel":12,"./log-event":16,"./log-event-handlers":15}],7:[function(require,module,exports){
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
|
|
@ -6560,11 +6560,10 @@ var FirebaseChannel = /** @class */ (function (_super) {
|
|||
var keys = Object.keys(params);
|
||||
var keysLength = keys.length;
|
||||
var sanitized = {};
|
||||
for (var i = 0; i < keysLength; i++) {
|
||||
var key = keys[i];
|
||||
keys.map(function (key) {
|
||||
var cleanKey = key.replace('-', '_').replace(/[\W]+/g, '');
|
||||
sanitized[cleanKey] = params[key];
|
||||
}
|
||||
});
|
||||
return sanitized;
|
||||
};
|
||||
return FirebaseChannel;
|
||||
|
|
@ -6588,13 +6587,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var channel_1 = __importDefault(require("../channel"));
|
||||
var ga_1 = __importDefault(require("../external-libs/ga"));
|
||||
var GoogleAnalyticsChannel = /** @class */ (function (_super) {
|
||||
__extends(GoogleAnalyticsChannel, _super);
|
||||
function GoogleAnalyticsChannel(name, config) {
|
||||
var _this = _super.call(this, name) || this;
|
||||
_this.dataLayer = null;
|
||||
_this.gaInstance = null;
|
||||
_this.trackingId = '';
|
||||
_this.eventLabels = ['id'];
|
||||
if (!config.trackingId) {
|
||||
throw new Error('[BitAnalytics] Google Analytics config is missing tracking ID.');
|
||||
|
|
@ -6602,8 +6600,12 @@ var GoogleAnalyticsChannel = /** @class */ (function (_super) {
|
|||
if (config.eventLabels) {
|
||||
_this.eventLabels = config.eventLabels;
|
||||
}
|
||||
_this.trackingId = config.trackingId;
|
||||
_this.setUpGa();
|
||||
_this.gaInstance = new ga_1.default({
|
||||
trackID: config.trackingId,
|
||||
appVersion: config.appVersion,
|
||||
appName: config.appName || 'App'
|
||||
});
|
||||
_this.isReady = true;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
|
|
@ -6612,49 +6614,26 @@ var GoogleAnalyticsChannel = /** @class */ (function (_super) {
|
|||
*
|
||||
*/
|
||||
GoogleAnalyticsChannel.prototype.postEvent = function (name, params) {
|
||||
// Default Google Analytics Events
|
||||
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
|
||||
// Useful to convert to these, or start with these?
|
||||
if (this.isReady) {
|
||||
params.event_category = name;
|
||||
var category = name;
|
||||
var action = name;
|
||||
var label = name;
|
||||
var value = params['value'] || '';
|
||||
for (var _i = 0, _a = this.eventLabels; _i < _a.length; _i++) {
|
||||
var eventLabel = _a[_i];
|
||||
if (params[eventLabel]) {
|
||||
params.event_label = params[eventLabel];
|
||||
label = params[eventLabel];
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.gtag('event', name, params);
|
||||
this.gaInstance.event(category, action, label, value);
|
||||
}
|
||||
};
|
||||
/**
|
||||
*
|
||||
* Private methods
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Mimics function in the tracking snippet
|
||||
*/
|
||||
GoogleAnalyticsChannel.prototype.gtag = function () {
|
||||
var args = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
args[_i] = arguments[_i];
|
||||
}
|
||||
console.log(arguments);
|
||||
window.dataLayer.push(arguments);
|
||||
};
|
||||
GoogleAnalyticsChannel.prototype.setUpGa = function () {
|
||||
// From what GA recommends to insert into page
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
this.gtag('js', new Date());
|
||||
this.gtag('config', this.trackingId);
|
||||
this.isReady = true;
|
||||
};
|
||||
return GoogleAnalyticsChannel;
|
||||
}(channel_1.default));
|
||||
exports.default = GoogleAnalyticsChannel;
|
||||
|
||||
},{"../channel":8}],12:[function(require,module,exports){
|
||||
},{"../channel":8,"../external-libs/ga":14}],12:[function(require,module,exports){
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
|
|
@ -6746,6 +6725,207 @@ exports.default = MixpanelChannel;
|
|||
|
||||
},{}],14:[function(require,module,exports){
|
||||
"use strict";
|
||||
/*
|
||||
* name: nwjs-analytics -Node-Webkit Google Analytics integration
|
||||
* version: 1.0.2
|
||||
* github: https://github.com/Daaru00/nwjs-analytics
|
||||
*/
|
||||
function GA(opt) {
|
||||
this.apiVersion = opt.apiVersion || '1';
|
||||
this.trackID = opt.trackID || 'UA-XXXXXXXX-X';
|
||||
this.clientID = opt.clientID || null;
|
||||
this.userID = opt.userID || null;
|
||||
this.appName = opt.appName || 'App';
|
||||
this.appVersion = opt.appVersion || '1.0.0';
|
||||
this.debug = opt.debug || false;
|
||||
this.performanceTracking = opt.performanceTracking || true;
|
||||
this.errorTracking = opt.errorTracking || true;
|
||||
this.userLanguage = opt.userLanguage || "en";
|
||||
this.currency = opt.currency || "EUR";
|
||||
this.lastScreenName = opt.lastScreenName || '';
|
||||
}
|
||||
GA.prototype.sendRequest = function (data, callback) {
|
||||
var ga = this;
|
||||
if (!this.clientID || this.clientID == null)
|
||||
this.clientID = this.generateClientID();
|
||||
if (!this.userID || this.userID == null)
|
||||
this.userID = this.generateClientID();
|
||||
var postData = "v=" + this.apiVersion
|
||||
+ "&an=" + this.appName
|
||||
+ "&av=" + this.appVersion
|
||||
+ "&tid=" + this.trackID
|
||||
+ "&cid=" + this.clientID
|
||||
+ "&sr=" + this.getScreenResolution()
|
||||
+ "&vp=" + this.getViewportSize();
|
||||
Object.keys(data).forEach(function (key) {
|
||||
var val = data[key];
|
||||
if (typeof val != "undefined")
|
||||
postData += "&" + key + "=" + val;
|
||||
});
|
||||
var http = new XMLHttpRequest();
|
||||
var url = "https://www.google-analytics.com";
|
||||
if (!this.debug)
|
||||
url += "/collect";
|
||||
else
|
||||
url += "/debug/collect";
|
||||
http.open("GET", url + "?" + postData, true);
|
||||
http.onreadystatechange = function () {
|
||||
if (ga.debug)
|
||||
console.log(http.response);
|
||||
if (http.readyState == 4 && http.status == 200) {
|
||||
if (callback)
|
||||
callback(true);
|
||||
}
|
||||
else {
|
||||
if (callback)
|
||||
callback(false);
|
||||
}
|
||||
};
|
||||
http.send();
|
||||
};
|
||||
GA.prototype.generateClientID = function () {
|
||||
var id = "";
|
||||
var possibilities = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
for (var i = 0; i < 5; i++)
|
||||
id += possibilities.charAt(Math.floor(Math.random() * possibilities.length));
|
||||
return id;
|
||||
};
|
||||
GA.prototype.getScreenResolution = function () {
|
||||
return screen.width + "x" + screen.height;
|
||||
};
|
||||
GA.prototype.getColorDept = function () {
|
||||
return screen.colorDepth + "-bits";
|
||||
};
|
||||
GA.prototype.getUserAgent = function () {
|
||||
return navigator.userAgent;
|
||||
};
|
||||
GA.prototype.getViewportSize = function () {
|
||||
return window.screen.availWidth + "x" + window.screen.availHeight;
|
||||
};
|
||||
/*
|
||||
* Measurement Protocol
|
||||
* [https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide]
|
||||
*/
|
||||
GA.prototype.screenView = function (screename) {
|
||||
var data = {
|
||||
't': 'screenview',
|
||||
'cd': screename
|
||||
};
|
||||
this.sendRequest(data);
|
||||
this.lastScreenName = screename;
|
||||
};
|
||||
GA.prototype.event = function (category, action, label, value) {
|
||||
var data = {
|
||||
't': 'event',
|
||||
'ec': category,
|
||||
'ea': action,
|
||||
};
|
||||
if (label) {
|
||||
data['el'] = label;
|
||||
}
|
||||
if (value) {
|
||||
data['ev'] = value;
|
||||
}
|
||||
if (this.lastScreenName) {
|
||||
data['cd'] = this.lastScreenName;
|
||||
}
|
||||
this.sendRequest(data);
|
||||
};
|
||||
GA.prototype.exception = function (msg, fatal) {
|
||||
var data = {
|
||||
't': 'exception',
|
||||
'exd': msg,
|
||||
'exf': fatal || 0
|
||||
};
|
||||
this.sendRequest(data);
|
||||
};
|
||||
GA.prototype.timing = function (category, variable, time, label) {
|
||||
var data = {
|
||||
't': 'timing',
|
||||
'utc': category,
|
||||
'utv': variable,
|
||||
'utt': time,
|
||||
'utl': label,
|
||||
};
|
||||
this.sendRequest(data);
|
||||
},
|
||||
GA.prototype.ecommerce = {
|
||||
transactionID: false,
|
||||
generateTransactionID: function () {
|
||||
var id = "";
|
||||
var possibilities = "0123456789";
|
||||
for (var i = 0; i < 5; i++)
|
||||
id += possibilities.charAt(Math.floor(Math.random() * possibilities.length));
|
||||
return id;
|
||||
},
|
||||
transaction: function (total, items) {
|
||||
var t_id = "";
|
||||
if (!this.ecommerce.transactionID)
|
||||
t_id = this.ecommerce.generateTransactionID();
|
||||
else
|
||||
t_id = this.ecommerce.transactionID;
|
||||
var data = {
|
||||
't': 'transaction',
|
||||
'ti': t_id,
|
||||
'tr': total,
|
||||
'cu': this.currency,
|
||||
};
|
||||
this.sendRequest(data);
|
||||
items.forEach(function (item) {
|
||||
var data = {
|
||||
't': 'item',
|
||||
'ti': t_id,
|
||||
'in': item.name,
|
||||
'ip': item.price,
|
||||
'iq': item.qty,
|
||||
'ic': item.id,
|
||||
'cu': this.currency
|
||||
};
|
||||
this.sendRequest(data);
|
||||
});
|
||||
}
|
||||
},
|
||||
GA.prototype.custom = function (data) {
|
||||
this.sendRequest(data);
|
||||
};
|
||||
module.exports = GA;
|
||||
/*
|
||||
* Performance Tracking
|
||||
*/
|
||||
/*window.addEventListener("load", function() {
|
||||
|
||||
if(ga.performanceTracking) {
|
||||
setTimeout(function() {
|
||||
var timing = window.performance.timing;
|
||||
var userTime = timing.loadEventEnd - timing.navigationStart;
|
||||
ga.timing("performance", "pageload", userTime);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
}, false);*/
|
||||
/*
|
||||
* Error Reporting
|
||||
*/
|
||||
/*window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||
var message = [
|
||||
'Message: ' + msg,
|
||||
'Line: ' + lineNo,
|
||||
'Column: ' + columnNo,
|
||||
'Error object: ' + JSON.stringify(error)
|
||||
].join(' - ');
|
||||
|
||||
if(ga.errorTracking)
|
||||
{
|
||||
setTimeout(function() {
|
||||
ga.exception(message.toString());
|
||||
}, 0);
|
||||
}
|
||||
|
||||
return false;
|
||||
};*/
|
||||
|
||||
},{}],15:[function(require,module,exports){
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
|
|
@ -6865,7 +7045,7 @@ var LogEventHandlers = /** @class */ (function () {
|
|||
}());
|
||||
exports.default = LogEventHandlers;
|
||||
|
||||
},{"./channel-factory":7}],15:[function(require,module,exports){
|
||||
},{"./channel-factory":7}],16:[function(require,module,exports){
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var LogEvent = /** @class */ (function () {
|
||||
|
|
@ -36,9 +36,9 @@ angular.module('copayApp.controllers').controller('addressbookAddController', fu
|
|||
addressbook.address = translated.legacy;
|
||||
}
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
var log = new window.BitAnalytics.LogEvent("contact_created", [{
|
||||
"coin": $scope.addressbookEntry.coin
|
||||
|
|
|
|||
|
|
@ -655,9 +655,9 @@ angular.module('copayApp.controllers').controller('confirmController', function(
|
|||
soundService.play('misc/payment_sent.mp3');
|
||||
}
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
var log = new window.BitAnalytics.LogEvent("transfer_success", [{
|
||||
"coin": $scope.wallet.coin,
|
||||
|
|
|
|||
|
|
@ -76,9 +76,9 @@ angular.module('copayApp.controllers').controller('preferencesNotificationsContr
|
|||
|
||||
emailService.updateEmail(opts);
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
var log = new window.BitAnalytics.LogEvent("settings_email_notification_toggle", [{
|
||||
"toggle": $scope.emailNotifications.value
|
||||
|
|
|
|||
|
|
@ -145,9 +145,9 @@ angular.module('copayApp.controllers').controller('tabReceiveController', functi
|
|||
}
|
||||
$scope.paymentReceivedCoin = $scope.wallet.coin;
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
var log = new window.BitAnalytics.LogEvent("transfer_success", [{
|
||||
"coin": $scope.wallet.coin,
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun
|
|||
$scope.isAndroid = platformInfo.isAndroid;
|
||||
$scope.isIOS = platformInfo.isIOS;
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
var log = new window.BitAnalytics.LogEvent("wallet_details_open", [], [channel]);
|
||||
window.BitAnalytics.LogEventHandlers.postEvent(log);
|
||||
|
|
|
|||
|
|
@ -1184,9 +1184,9 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
|
|||
}
|
||||
});
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
|
||||
// Send a log to test
|
||||
|
|
|
|||
|
|
@ -427,9 +427,9 @@ angular.module('copayApp.services')
|
|||
}, function(err, secret) {
|
||||
if (err) return bwcError.cb(err, gettextCatalog.getString('Error creating wallet'), cb);
|
||||
|
||||
var channel = "firebase";
|
||||
if (platformInfo.isNW) {
|
||||
channel = "ga";
|
||||
var channel = "ga";
|
||||
if (platformInfo.isCordova) {
|
||||
channel = "firebase";
|
||||
}
|
||||
var log = new window.BitAnalytics.LogEvent("wallet_created", [{
|
||||
"coin": opts.coin
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@
|
|||
<link rel="stylesheet" type="text/css" href="css/chartist.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/bitcoin.com.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/icomoon.css">
|
||||
<title>Bitcoin.com Wallet - Bitcoin.com Wallet</title>
|
||||
<link rel="shortcut icon" href="img/app/favicon.ico">
|
||||
<script src="https://www.googletagmanager.com/gtag/js?id=UA-59964190-23"></script>
|
||||
<title>Bitcoin.com Wallet</title>
|
||||
<link rel="shortcut icon" href="img/app/favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
@ -31,7 +30,7 @@
|
|||
|
||||
<script src="lib/ionic.bundle.min.js"></script>
|
||||
<script src="lib/angular-components.js"></script>
|
||||
<script src="lib/bitcoin-cash-js.js"></script>
|
||||
<script src="lib/bitcoin-cash-js.js"></script>
|
||||
<script src="lib/bitanalytics.js"></script>
|
||||
|
||||
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue