Skip to content
This repository has been archived by the owner on Jun 26, 2018. It is now read-only.

Commit

Permalink
Add content engagement
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Jun 27, 2017
1 parent a7ec66b commit 29c9b22
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/segment/report-pipelines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function getBaseMatch(type, identifier) {
// @todo Will need to add dates when a range is eventually sent.
// createdAt: { $gte: startDate, $lt: endDate },
Expand All @@ -20,9 +19,15 @@ function getBaseMatch(type, identifier) {
action: 'view',
};
case 'content-company':
// @todo This should query base first for content ids, then run.
return {
'entity.relatedTo.type': 'content',
'entity.relatedTo.clientId': identifier,
$or: [
{ clientId: identifier },
{
'entity.relatedTo.type': 'content',
'entity.relatedTo.clientId': identifier,
},
],
action: 'view',
};
default:
Expand All @@ -32,6 +37,27 @@ function getBaseMatch(type, identifier) {

module.exports = (segmentType, segmentId, reportKey) => {
const pipelines = {
'content-engagement': [
{ $match: getBaseMatch(segmentType, segmentId) },
{ $group: {
_id: '$clientId',
title: { $first: '$entity.keyValues.name' },
type: { $first: '$entity.keyValues.contentType' },
identified: { $sum: { $cond: { if: { $eq: ['$session.customerId', null] }, then: 0, else: 1 } } },
total: { $sum: 1 },
} },
{ $sort: { total: -1 } },
{ $limit: 250 },
{ $project: {
id: '$_id',
_id: 0,
type: 1,
title: 1,
identified: 1,
total: 1,
pctIdentified: { $divide: ['$identified', '$total'] },
} },
],
'user-demographic': [
{ $match: getBaseMatch(segmentType, segmentId) },
{ $match: { 'session.customerId': { $ne: null } } },
Expand Down

0 comments on commit 29c9b22

Please sign in to comment.