2022-08-25 17:42:19 +03:00
|
|
|
|
import Helper from '@ember/component/helper';
|
2022-09-23 20:15:08 +03:00
|
|
|
|
import moment from 'moment-timezone';
|
2022-01-25 14:50:10 +03:00
|
|
|
|
import {getNonDecimal, getSymbol} from 'ghost-admin/utils/currency';
|
2022-10-27 18:23:45 +03:00
|
|
|
|
import {ghPluralize} from 'ghost-admin/helpers/gh-pluralize';
|
2022-08-25 17:42:19 +03:00
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
export default class ParseMemberEventHelper extends Helper {
|
|
|
|
|
@service feature;
|
2022-09-23 18:41:46 +03:00
|
|
|
|
@service utils;
|
2022-10-27 12:44:19 +03:00
|
|
|
|
@service membersUtils;
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
compute([event, hasMultipleNewsletters]) {
|
|
|
|
|
const subject = event.data.member.name || event.data.member.email;
|
|
|
|
|
const icon = this.getIcon(event);
|
|
|
|
|
const action = this.getAction(event, hasMultipleNewsletters);
|
|
|
|
|
const info = this.getInfo(event);
|
2022-09-21 11:25:51 +03:00
|
|
|
|
const description = this.getDescription(event);
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
const join = this.getJoin(event);
|
|
|
|
|
const object = this.getObject(event);
|
|
|
|
|
const url = this.getURL(event);
|
|
|
|
|
const timestamp = moment(event.data.created_at);
|
2022-10-25 15:30:40 +03:00
|
|
|
|
const source = this.getSource(event);
|
2022-01-26 12:52:51 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
return {
|
|
|
|
|
memberId: event.data.member_id ?? event.data.member?.id,
|
|
|
|
|
member: event.data.member,
|
|
|
|
|
emailId: event.data.email_id,
|
|
|
|
|
email: event.data.email,
|
|
|
|
|
icon,
|
|
|
|
|
subject,
|
|
|
|
|
action,
|
|
|
|
|
join,
|
|
|
|
|
object,
|
2022-10-25 15:30:40 +03:00
|
|
|
|
source,
|
2022-08-25 17:42:19 +03:00
|
|
|
|
info,
|
2022-09-21 11:25:51 +03:00
|
|
|
|
description,
|
2022-08-25 17:42:19 +03:00
|
|
|
|
url,
|
|
|
|
|
timestamp
|
|
|
|
|
};
|
2022-01-26 12:52:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
/* internal helper functions */
|
|
|
|
|
getIcon(event) {
|
|
|
|
|
let icon;
|
2022-01-26 12:52:51 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'login_event') {
|
|
|
|
|
icon = 'logged-in';
|
2022-01-26 12:52:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'payment_event') {
|
|
|
|
|
icon = 'subscriptions';
|
|
|
|
|
}
|
2022-02-15 19:07:28 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'newsletter_event') {
|
|
|
|
|
if (event.data.subscribed) {
|
|
|
|
|
icon = 'subscribed-to-email';
|
|
|
|
|
} else {
|
|
|
|
|
icon = 'unsubscribed-from-email';
|
|
|
|
|
}
|
2022-01-26 12:52:51 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'subscription_event') {
|
|
|
|
|
icon = 'subscriptions';
|
2022-01-26 12:52:51 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.data.type === 'canceled') {
|
|
|
|
|
icon = 'canceled-subscription';
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-26 12:52:51 +03:00
|
|
|
|
|
2022-10-27 12:44:19 +03:00
|
|
|
|
if (event.type === 'signup_event' || (event.type === 'subscription_event' && event.data.type === 'created' && event.data.signup)) {
|
|
|
|
|
icon = 'signed-up';
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'email_opened_event') {
|
|
|
|
|
icon = 'opened-email';
|
|
|
|
|
}
|
2022-01-26 12:52:51 +03:00
|
|
|
|
|
2022-10-24 12:11:44 +03:00
|
|
|
|
if (event.type === 'email_delivered_event' || event.type === 'email_sent_event') {
|
2022-08-25 17:42:19 +03:00
|
|
|
|
icon = 'received-email';
|
|
|
|
|
}
|
2022-07-22 12:41:32 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'email_failed_event') {
|
|
|
|
|
icon = 'email-delivery-failed';
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-11-18 13:33:48 +03:00
|
|
|
|
if (event.type === 'email_complaint_event') {
|
|
|
|
|
icon = 'email-delivery-spam';
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'comment_event') {
|
|
|
|
|
icon = 'comment';
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-10-27 18:23:45 +03:00
|
|
|
|
if (event.type === 'click_event' || event.type === 'aggregated_click_event') {
|
2022-09-21 11:25:51 +03:00
|
|
|
|
icon = 'click';
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 16:44:18 +03:00
|
|
|
|
if (event.type === 'feedback_event') {
|
|
|
|
|
if (event.data.score === 1) {
|
|
|
|
|
icon = 'more-like-this';
|
|
|
|
|
} else {
|
|
|
|
|
icon = 'less-like-this';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 13:50:39 +03:00
|
|
|
|
return 'event-' + icon;
|
2022-01-25 14:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
getAction(event, hasMultipleNewsletters) {
|
2022-10-27 12:44:19 +03:00
|
|
|
|
if (event.type === 'signup_event' || (event.type === 'subscription_event' && event.data.type === 'created' && event.data.signup)) {
|
2022-08-25 17:42:19 +03:00
|
|
|
|
return 'signed up';
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'login_event') {
|
|
|
|
|
return 'logged in';
|
2022-08-24 17:11:25 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'payment_event') {
|
|
|
|
|
return 'made payment';
|
2022-01-25 14:50:10 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'newsletter_event') {
|
|
|
|
|
let newsletter = 'newsletter';
|
|
|
|
|
if (hasMultipleNewsletters && event.data.newsletter && event.data.newsletter.name) {
|
|
|
|
|
newsletter = event.data.newsletter.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.data.subscribed) {
|
|
|
|
|
return 'subscribed to ' + newsletter;
|
|
|
|
|
} else {
|
|
|
|
|
return 'unsubscribed from ' + newsletter;
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
}
|
2022-08-25 17:42:19 +03:00
|
|
|
|
|
|
|
|
|
if (event.type === 'subscription_event') {
|
|
|
|
|
if (event.data.type === 'created') {
|
|
|
|
|
return 'started paid subscription';
|
|
|
|
|
}
|
|
|
|
|
if (event.data.type === 'updated') {
|
|
|
|
|
return 'changed paid subscription';
|
|
|
|
|
}
|
|
|
|
|
if (event.data.type === 'canceled') {
|
|
|
|
|
return 'canceled paid subscription';
|
|
|
|
|
}
|
|
|
|
|
if (event.data.type === 'reactivated') {
|
|
|
|
|
return 'reactivated paid subscription';
|
|
|
|
|
}
|
|
|
|
|
if (event.data.type === 'expired') {
|
|
|
|
|
return 'ended paid subscription';
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 12:58:58 +03:00
|
|
|
|
return 'changed paid subscription';
|
2022-04-13 12:28:13 +03:00
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'email_opened_event') {
|
|
|
|
|
return 'opened email';
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-10-24 12:11:44 +03:00
|
|
|
|
if (event.type === 'email_delivered_event' || event.type === 'email_sent_event') {
|
2022-08-25 17:42:19 +03:00
|
|
|
|
return 'received email';
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'email_failed_event') {
|
2022-11-18 13:33:48 +03:00
|
|
|
|
return this.feature.get('suppressionList') ? 'bounced email' : 'failed to receive email';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.type === 'email_complaint_event') {
|
|
|
|
|
return 'flagged as spam email';
|
2022-08-25 17:42:19 +03:00
|
|
|
|
}
|
2022-07-22 12:41:32 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'comment_event') {
|
|
|
|
|
if (event.data.parent) {
|
|
|
|
|
return 'replied to comment';
|
|
|
|
|
}
|
|
|
|
|
return 'commented';
|
2022-07-22 12:41:32 +03:00
|
|
|
|
}
|
2022-09-21 11:25:51 +03:00
|
|
|
|
|
|
|
|
|
if (event.type === 'click_event') {
|
2022-09-27 14:29:08 +03:00
|
|
|
|
return 'clicked link in email';
|
2022-09-21 11:25:51 +03:00
|
|
|
|
}
|
2022-10-17 16:44:18 +03:00
|
|
|
|
|
2022-10-27 18:23:45 +03:00
|
|
|
|
if (event.type === 'aggregated_click_event') {
|
|
|
|
|
if (event.data.count.clicks <= 1) {
|
|
|
|
|
return 'clicked link in email';
|
|
|
|
|
}
|
|
|
|
|
return `clicked ${ghPluralize(event.data.count.clicks, 'link')} in email`;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 16:44:18 +03:00
|
|
|
|
if (event.type === 'feedback_event') {
|
|
|
|
|
if (event.data.score === 1) {
|
|
|
|
|
return 'more like this';
|
|
|
|
|
}
|
|
|
|
|
return 'less like this';
|
|
|
|
|
}
|
2022-07-22 12:41:32 +03:00
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* When we need to append the action and object in one sentence, you can add extra words here.
|
|
|
|
|
* E.g.,
|
|
|
|
|
* action: 'Signed up'.
|
|
|
|
|
* object: 'My blog post'
|
|
|
|
|
* When both words need to get appended, we'll add 'on'
|
|
|
|
|
* -> do this by returning 'on' in getJoin()
|
|
|
|
|
* This string is not added when action and object are in a separete table column, or when the getObject/getURL is empty
|
|
|
|
|
*/
|
2022-11-11 18:17:55 +03:00
|
|
|
|
getJoin() {
|
|
|
|
|
return '–';
|
2022-08-25 17:42:19 +03:00
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Clickable object, shown between action and info, or in a separate column in some views
|
|
|
|
|
*/
|
|
|
|
|
getObject(event) {
|
|
|
|
|
if (event.type === 'signup_event' || event.type === 'subscription_event') {
|
|
|
|
|
if (event.data.attribution?.title) {
|
|
|
|
|
return event.data.attribution.title;
|
|
|
|
|
}
|
2022-08-24 17:11:25 +03:00
|
|
|
|
}
|
2022-07-22 12:41:32 +03:00
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'comment_event') {
|
|
|
|
|
if (event.data.post) {
|
|
|
|
|
return event.data.post.title;
|
|
|
|
|
}
|
2022-07-22 12:41:32 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 16:44:18 +03:00
|
|
|
|
if (event.type === 'click_event' || event.type === 'feedback_event') {
|
2022-09-21 11:25:51 +03:00
|
|
|
|
if (event.data.post) {
|
|
|
|
|
return event.data.post.title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
return '';
|
|
|
|
|
}
|
2022-01-25 14:50:10 +03:00
|
|
|
|
|
2022-10-25 15:30:40 +03:00
|
|
|
|
/**
|
|
|
|
|
* Clickable object, shown between action and info, or in a separate column in some views
|
|
|
|
|
*/
|
|
|
|
|
getSource(event) {
|
|
|
|
|
if (event.data?.attribution?.referrer_source) {
|
|
|
|
|
return {
|
|
|
|
|
name: event.data.attribution.referrer_source,
|
|
|
|
|
url: event.data.attribution.referrer_url ?? null
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
getInfo(event) {
|
|
|
|
|
if (event.type === 'subscription_event') {
|
|
|
|
|
let mrrDelta = getNonDecimal(event.data.mrr_delta, event.data.currency);
|
|
|
|
|
if (mrrDelta === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-27 12:44:19 +03:00
|
|
|
|
const symbol = getSymbol(event.data.currency);
|
|
|
|
|
|
|
|
|
|
if (event.data.type === 'created') {
|
|
|
|
|
const sign = mrrDelta > 0 ? '' : '-';
|
2022-11-11 18:17:55 +03:00
|
|
|
|
const tierName = this.membersUtils.hasMultipleTiers ? (event.data.tierName ?? 'Paid') : 'Paid';
|
|
|
|
|
return `${tierName} ${sign}${symbol}${Math.abs(mrrDelta)}/month`;
|
2022-10-27 12:44:19 +03:00
|
|
|
|
}
|
|
|
|
|
const sign = mrrDelta > 0 ? '+' : '-';
|
2022-11-11 18:17:55 +03:00
|
|
|
|
return `MRR ${sign}${symbol}${Math.abs(mrrDelta)}`;
|
2022-01-25 14:50:10 +03:00
|
|
|
|
}
|
2022-10-27 12:44:19 +03:00
|
|
|
|
|
|
|
|
|
if (event.type === 'signup_event' && this.membersUtils.paidMembersEnabled) {
|
2022-10-27 19:01:37 +03:00
|
|
|
|
return 'Free';
|
2022-10-27 12:44:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
return;
|
2022-01-25 14:50:10 +03:00
|
|
|
|
}
|
2022-08-02 18:02:42 +03:00
|
|
|
|
|
2022-09-21 11:25:51 +03:00
|
|
|
|
getDescription(event) {
|
|
|
|
|
if (event.type === 'click_event') {
|
|
|
|
|
// Clean URL
|
|
|
|
|
try {
|
2022-09-23 18:41:46 +03:00
|
|
|
|
return this.utils.cleanTrackedUrl(event.data.link.to, true);
|
2022-09-21 11:25:51 +03:00
|
|
|
|
} catch (e) {
|
|
|
|
|
// Invalid URL
|
|
|
|
|
}
|
2022-09-21 15:58:22 +03:00
|
|
|
|
return event.data.link.to;
|
2022-09-21 11:25:51 +03:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
/**
|
|
|
|
|
* Make the object clickable
|
|
|
|
|
*/
|
|
|
|
|
getURL(event) {
|
2022-10-17 16:44:18 +03:00
|
|
|
|
if (event.type === 'comment_event' || event.type === 'click_event' || event.type === 'feedback_event') {
|
2022-09-21 11:25:51 +03:00
|
|
|
|
if (event.data.post) {
|
|
|
|
|
return event.data.post.url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 17:42:19 +03:00
|
|
|
|
if (event.type === 'signup_event' || event.type === 'subscription_event') {
|
|
|
|
|
if (event.data.attribution && event.data.attribution.url) {
|
|
|
|
|
return event.data.attribution.url;
|
|
|
|
|
}
|
2022-08-24 17:11:25 +03:00
|
|
|
|
}
|
2022-08-25 17:42:19 +03:00
|
|
|
|
return;
|
2022-08-24 17:11:25 +03:00
|
|
|
|
}
|
2022-08-02 18:02:42 +03:00
|
|
|
|
}
|