From d12f7cd15283a1c59413a0996b5d88c1b5ac6891 Mon Sep 17 00:00:00 2001 From: Fabien O'Carroll Date: Tue, 21 Sep 2021 18:35:24 +0200 Subject: [PATCH] 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. --- .../lib/EventHandler.js | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/ghost/member-analytics-service/lib/EventHandler.js b/ghost/member-analytics-service/lib/EventHandler.js index 8cf3aee7a4..0324353a1d 100644 --- a/ghost/member-analytics-service/lib/EventHandler.js +++ b/ghost/member-analytics-service/lib/EventHandler.js @@ -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); + }); } }