Merge pull request #457 from lbryio/429-analytics-referrer

added referrer to serve-event analytics
This commit is contained in:
Bill Bittner 2018-05-29 10:13:58 -07:00 committed by GitHub
commit 916e8dc4e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,8 +9,9 @@ function createServeEventParams (headers, ip, originalUrl) {
eventLabel : originalUrl,
ipOverride : ip,
userAgentOverride: headers['user-agent'],
documentReferrer : headers['referer'],
};
};
}
function createPublishTimingEventParams (category, variable, label, startTime, endTime) {
const duration = endTime - startTime;
@ -20,7 +21,7 @@ function createPublishTimingEventParams (category, variable, label, startTime, e
userTimingTime : duration,
userTimingLabel : label,
};
};
}
function sendGoogleAnalyticsEvent (ip, params) {
const visitorId = ip.replace(/\./g, '-');
@ -29,8 +30,9 @@ function sendGoogleAnalyticsEvent (ip, params) {
if (err) {
logger.error('Google Analytics Event Error >>', err);
}
logger.debug(`Event successfully sent to google analytics`);
});
};
}
function sendGoogleAnalyticsTiming (visitorId, params) {
const visitor = ua(googleId, visitorId, { strictCidFormat: false, https: true });
@ -40,18 +42,25 @@ function sendGoogleAnalyticsTiming (visitorId, params) {
}
logger.debug(`Timing event successfully sent to google analytics`);
});
};
}
function sendGAServeEvent (headers, ip, originalUrl) {
logger.debug('headers:', headers);
const params = createServeEventParams(headers, ip, originalUrl);
sendGoogleAnalyticsEvent(ip, params);
}
function sendGATimingEvent (category, variable, label, startTime, endTime) {
const params = createPublishTimingEventParams(category, variable, label, startTime, endTime);
sendGoogleAnalyticsTiming(title, params);
}
function chooseGaLbrynetPublishLabel ({ channel_name: channelName, channel_id: channelId }) {
return (channelName || channelId ? 'PUBLISH_IN_CHANNEL_CLAIM' : 'PUBLISH_ANONYMOUS_CLAIM');
}
module.exports = {
sendGAServeEvent (headers, ip, originalUrl) {
const params = createServeEventParams(headers, ip, originalUrl);
sendGoogleAnalyticsEvent(ip, params);
},
sendGATimingEvent (category, variable, label, startTime, endTime) {
const params = createPublishTimingEventParams(category, variable, label, startTime, endTime);
sendGoogleAnalyticsTiming(title, params);
},
chooseGaLbrynetPublishLabel ({ channel_name: channelName, channel_id: channelId }) {
return (channelName || channelId ? 'PUBLISH_IN_CHANNEL_CLAIM' : 'PUBLISH_ANONYMOUS_CLAIM');
},
sendGAServeEvent,
sendGATimingEvent,
chooseGaLbrynetPublishLabel,
};