Add device type detect and stats calculation for open/click rate by device type and country
This commit is contained in:
parent
b6497b0e86
commit
1ba3bce6eb
10 changed files with 176 additions and 15 deletions
|
@ -193,7 +193,43 @@ module.exports.filterClickedSubscribers = (campaign, linkId, request, columns, c
|
|||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.statsClickedSubscribersByColumn = (campaign, linkId, request, column, limit, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let values = [campaign.list, linkId];
|
||||
let query = 'SELECT SQL_CALC_FOUND_ROWS ' + column + ' AS data, COUNT(*) AS cnt FROM `subscription__' + campaign.list + '` JOIN `campaign_tracker__' + campaign.id + '` ON `campaign_tracker__' + campaign.id + '`.`list`=? AND `campaign_tracker__' + campaign.id + '`.`subscriber`=`subscription__' + campaign.list + '`.`id` AND `campaign_tracker__' + campaign.id + '`.`link`=? GROUP BY ' + column + ' ORDER BY COUNT(' + column + ') DESC,' + column;
|
||||
|
||||
connection.query(query, values, (err, rows) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
let data = {};
|
||||
let dataPercent = [];
|
||||
let total = 0;
|
||||
|
||||
rows.forEach(function (row, index) {
|
||||
if (index < limit) {
|
||||
data[row.data] = row.cnt;
|
||||
} else {
|
||||
data.other = (data.other ? data.other : 0) + row.cnt;
|
||||
}
|
||||
total += row.cnt;
|
||||
});
|
||||
Object.keys(data).forEach(function (key) {
|
||||
let name = key + ': ' + data[key];
|
||||
let value = parseInt(data[key] * 100 / total);
|
||||
dataPercent.push([name, value]);
|
||||
});
|
||||
return callback(null, dataPercent, total);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.filterStatusSubscribers = (campaign, status, request, columns, callback) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue