From c6e98e67c074471aae4d554fe25591a8ac8f4bf6 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Wed, 23 Feb 2022 19:04:36 +0100 Subject: [PATCH] Added the new MemberPageViewEvent event refs https://github.com/TryGhost/Team/issues/1306 - This event will be triggered by logged-in members visiting any page of the publication (page, post, tag, author...) --- ghost/member-events/index.js | 1 + .../member-events/lib/MemberPageViewEvent.js | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 ghost/member-events/lib/MemberPageViewEvent.js diff --git a/ghost/member-events/index.js b/ghost/member-events/index.js index 48592c7b86..c43a7533a7 100644 --- a/ghost/member-events/index.js +++ b/ghost/member-events/index.js @@ -5,5 +5,6 @@ module.exports = { MemberSignupEvent: require('./lib/MemberSignupEvent'), MemberPaidConverstionEvent: require('./lib/MemberPaidConversionEvent'), MemberPaidCancellationEvent: require('./lib/MemberPaidCancellationEvent'), + MemberPageViewEvent: require('./lib/MemberPageViewEvent'), SubscriptionCreatedEvent: require('./lib/SubscriptionCreatedEvent') }; diff --git a/ghost/member-events/lib/MemberPageViewEvent.js b/ghost/member-events/lib/MemberPageViewEvent.js new file mode 100644 index 0000000000..d033996baa --- /dev/null +++ b/ghost/member-events/lib/MemberPageViewEvent.js @@ -0,0 +1,28 @@ +/** + * @typedef {object} MemberPageViewEventData + * @prop {string} memberId + * @prop {string} memberLastSeenAt + * @prop {string} url + */ + +/** + * Server-side event firing on page views (page, post, tags...) + */ +module.exports = class MemberPageViewEvent { + /** + * @param {MemberPageViewEventData} data + * @param {Date} timestamp + */ + constructor(data, timestamp) { + this.data = data; + this.timestamp = timestamp; + } + + /** + * @param {MemberPageViewEventData} data + * @param {Date} [timestamp] + */ + static create(data, timestamp) { + return new MemberPageViewEvent(data, timestamp || new Date); + } +};