This commit is contained in:
Andris Reinman 2016-09-08 14:39:41 +03:00
parent 6c34091634
commit 95379f731f
17 changed files with 187 additions and 99 deletions

View file

@ -13,7 +13,7 @@ let log = require('npmlog');
let mailer = require('../mailer');
let caches = require('../caches');
let allowedKeys = ['description', 'from', 'address', 'subject', 'template', 'source_url', 'list', 'segment', 'html', 'text'];
let allowedKeys = ['description', 'from', 'address', 'subject', 'template', 'source_url', 'list', 'segment', 'html', 'text', 'tracking_disabled'];
module.exports.list = (start, limit, callback) => {
db.getConnection((err, connection) => {
@ -417,6 +417,8 @@ module.exports.create = (campaign, opts, callback) => {
campaign = tools.convertKeys(campaign);
let name = (campaign.name || '').toString().trim();
campaign.trackingDisabled = campaign.trackingDisabled ? 1 : 0;
opts = opts || {};
if (/^\d+:\d+$/.test(campaign.list)) {
@ -631,6 +633,8 @@ module.exports.update = (id, updates, callback) => {
let campaign = tools.convertKeys(updates);
let name = (campaign.name || '').toString().trim();
campaign.trackingDisabled = campaign.trackingDisabled ? 1 : 0;
if (!name) {
return callback(new Error('Campaign Name must be set'));
}

View file

@ -39,9 +39,11 @@ module.exports.countClick = (remoteIp, campaignCid, listCid, subscriptionCid, li
if (err) {
return callback(err);
}
if(!data){
if (!data || data.campaign.trackingDisabled) {
return callback(null, false);
}
db.getConnection((err, connection) => {
if (err) {
return callback(err);
@ -154,6 +156,10 @@ module.exports.countOpen = (remoteIp, campaignCid, listCid, subscriptionCid, cal
return callback(err);
}
if (!data || data.campaign.trackingDisabled) {
return callback(null, false);
}
db.getConnection((err, connection) => {
if (err) {
return callback(err);
@ -260,6 +266,10 @@ module.exports.add = (url, campaignId, callback) => {
};
module.exports.updateLinks = (campaign, list, subscription, serviceUrl, message, callback) => {
if (campaign.trackingDisabled) {
// tracking is disabled, do not modify the message
return setImmediate(() => callback(null, message));
}
let re = /(<a[^>]* href\s*=[\s"']*)(http[^"'>\s]+)/gi;
let urls = new Set();
(message || '').replace(re, (match, prefix, url) => {
@ -272,7 +282,7 @@ module.exports.updateLinks = (campaign, list, subscription, serviceUrl, message,
// insert tracking image
let inserted = false;
let imgUrl = urllib.resolve(serviceUrl, util.format('/links/%s/%s/%s', campaign.cid, list.cid, encodeURIComponent(subscription.cid)));
let img = '<img src="' + imgUrl + '" width="1" height="1" alt="Tracking Image">';
let img = '<img src="' + imgUrl + '" width="1" height="1" alt="mt">';
message = message.replace(/<\/body\b/i, match => {
inserted = true;
return img + match;

View file

@ -172,7 +172,7 @@ module.exports.filter = (listId, request, columns, segmentId, callback) => {
};
module.exports.addConfirmation = (list, email, data, callback) => {
module.exports.addConfirmation = (list, email, optInIp, data, callback) => {
let cid = shortid.generate();
tools.validateEmail(email, false, err => {
@ -185,8 +185,8 @@ module.exports.addConfirmation = (list, email, data, callback) => {
return callback(err);
}
let query = 'INSERT INTO confirmations (cid, list, email, data) VALUES (?,?,?,?)';
connection.query(query, [cid, list.id, email, JSON.stringify(data || {})], (err, result) => {
let query = 'INSERT INTO confirmations (cid, list, email, opt_in_ip, data) VALUES (?,?,?,?,?)';
connection.query(query, [cid, list.id, email, optInIp, JSON.stringify(data || {})], (err, result) => {
connection.release();
if (err) {
return callback(err);