Added listeners for remaining events

refs https://github.com/TryGhost/Team/issues/1054

This adds the missing listeners for the rest of the analytics events
we'd like to capture.
This commit is contained in:
Fabien O'Carroll 2021-09-21 18:35:24 +02:00
parent 9fca7ce8f3
commit d12f7cd152

View File

@ -1,5 +1,11 @@
const DomainEvents = require('@tryghost/domain-events');
const {MemberEntryViewEvent} = require('@tryghost/member-events');
const {
MemberEntryViewEvent,
MemberUnsubscribeEvent,
MemberSignupEvent,
MemberPaidConverstionEvent,
MemberPaidCancellationEvent
} = require('@tryghost/member-events');
const AnalyticEvent = require('./AnalyticEvent');
@ -28,6 +34,60 @@ class EventHandler {
await this.repository.save(event);
});
DomainEvents.subscribe(MemberUnsubscribeEvent, async (ev) => {
const event = AnalyticEvent.create({
name: 'unsubscribe',
memberId: ev.data.memberId,
memberStatus: ev.data.memberStatus,
entryId: ev.data.entryId,
sourceUrl: ev.data.sourceUrl,
timestamp: ev.timestamp
});
await this.repository.save(event);
});
DomainEvents.subscribe(MemberSignupEvent, async (ev) => {
const event = AnalyticEvent.create({
name: 'signup',
memberId: ev.data.memberId,
memberStatus: 'free',
entryId: ev.data.entryId,
sourceUrl: ev.data.sourceUrl,
timestamp: ev.timestamp
});
await this.repository.save(event);
});
DomainEvents.subscribe(MemberPaidCancellationEvent, async (ev) => {
const event = AnalyticEvent.create({
name: 'paid_cancellation',
memberId: ev.data.memberId,
memberStatus: ev.data.memberStatus,
entryId: ev.data.entryId,
sourceUrl: ev.data.sourceUrl,
metadata: ev.data.subscriptionId,
timestamp: ev.timestamp
});
await this.repository.save(event);
});
DomainEvents.subscribe(MemberPaidConverstionEvent, async (ev) => {
const event = AnalyticEvent.create({
name: 'paid_conversion',
memberId: ev.data.memberId,
memberStatus: ev.data.memberStatus,
entryId: ev.data.entryId,
sourceUrl: ev.data.sourceUrl,
metadata: ev.data.subscriptionId,
timestamp: ev.timestamp
});
await this.repository.save(event);
});
}
}