Skip to content

Commit

Permalink
Fix amount tracking and google analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
xdzurman committed Aug 3, 2020
1 parent 16fd62f commit 490f1dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 5 additions & 2 deletions server/helpers/parseTxBody.js
Expand Up @@ -7,12 +7,15 @@ const parseTxBodyOutAmount = (txBody) => {
* is always the amount intended to be sent out
* format - [txAux][outputs][0-th output][amount]
*/
return cbor.decode(txBody)[0][1][0][1]
return cbor.decode(txBody)[0].get(1)[0][1]
}

const parseTxBodyTotalAmount = (txBody) => {
// reduce along decodedTxBody[0][1][i-th output][1] to sum all outputs
return cbor.decode(txBody)[0][1].reduce((acc, curr) => acc + curr[1], 0)
return cbor
.decode(txBody)[0]
.get(1)
.reduce((acc, curr) => acc + curr[1], 0)
}

module.exports = {
Expand Down
14 changes: 13 additions & 1 deletion server/middlewares/statsGoogleAnalytics.js
@@ -1,6 +1,7 @@
const device = require('device')
const mung = require('express-mung')
const normalizeUrl = require('normalize-url')
const {parseTxBodyOutAmount, parseTxBodyTotalAmount} = require('../helpers/parseTxBody')
const ua = require('universal-analytics')
const {backendConfig} = require('../helpers/loadConfig')

Expand Down Expand Up @@ -84,11 +85,22 @@ const trackTxSubmissions = mung.jsonAsync(async (body, req, res) => {
}

if (txSubmissionSuccess === 'successful') {
const {txBody} = req.body

const txSentAmount = parseTxBodyOutAmount(txBody)
await trackEvent({
...baseEventData,
action: `${txSubmissionType}:sentOut`,
label: 'successful payment',
value: undefined,
value: Math.floor(txSentAmount / 1000000),
})

const txTotalAmount = parseTxBodyTotalAmount(txBody)
await trackEvent({
...baseEventData,
action: `${txSubmissionType}:sentTotal`,
label: 'total amount',
value: Math.floor(txTotalAmount / 1000000),
})
} else {
await trackEvent({
Expand Down
2 changes: 1 addition & 1 deletion server/middlewares/statsRedis.js
Expand Up @@ -56,7 +56,7 @@ const trackTxSubmissions = mung.json((body, req, res) => {

incrCountersBy(`${txSubmissionType}:${txSubmissionSuccess}`, 1)

if (backendConfig.ADALITE_CARDANO_VERSION === 'byron' && txSubmissionSuccess === 'successful') {
if (txSubmissionSuccess === 'successful') {
const {txBody} = req.body
let txOutAmount = 0
let txTotalAmount = 0
Expand Down

0 comments on commit 490f1dd

Please sign in to comment.