Skip to content

Commit 15eaaf0

Browse files
committed
Fix Total Clicks
1 parent 60a46e9 commit 15eaaf0

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ app.get('/userInsights', loggedInUserChecker, async (req, res) => {
266266
if (metric.name === FIELD__VIEWS) {
267267
// The "views" metric returns as a value for user insights
268268
getInsightsValue(metrics, index);
269+
} else if (metric.name === FIELD__CLICKS) {
270+
getInsightsValueForClicks(metrics, index);
269271
}
270272
else {
271273
// All other metrics return as a total value
@@ -940,6 +942,17 @@ function getInsightsTotalValue(metrics, index) {
940942
}
941943
}
942944

945+
/**
946+
* @param {{ value?: number, link_total_values: { value: number }[] }[]} metrics
947+
* @param {number} index
948+
*/
949+
function getInsightsValueForClicks(metrics, index) {
950+
if (metrics[index]) {
951+
metrics[index].value = metrics[index].link_total_values.reduce((sum, { value }) => sum + value, 0);
952+
}
953+
}
954+
955+
943956
/**
944957
* @param {object} target
945958
* @param {string} attachmentType

0 commit comments

Comments
 (0)