From bb0d90093728afc92a0dc6f8741c6eaa85f639ff Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 21 Sep 2022 15:04:23 +0530 Subject: [PATCH] Handled storing referrer information in DB refs https://github.com/TryGhost/Team/issues/1931 - stores `referrer_source`, `referrer_medium` and `referrer_url` in event tables for new members and paid subscriptions --- ghost/members-api/lib/controllers/router.js | 6 +++--- ghost/members-events-service/lib/event-storage.js | 14 ++++++++++---- ghost/stripe/lib/WebhookController.js | 10 ++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ghost/members-api/lib/controllers/router.js b/ghost/members-api/lib/controllers/router.js index 4d3d66450d..130743f099 100644 --- a/ghost/members-api/lib/controllers/router.js +++ b/ghost/members-api/lib/controllers/router.js @@ -228,15 +228,15 @@ module.exports = class RouterController { } if (attribution.refSource) { - metadata.attribution_ref_source = attribution.refSource; + metadata.referrer_source = attribution.refSource; } if (attribution.refMedium) { - metadata.attribution_ref_medium = attribution.refMedium; + metadata.referrer_medium = attribution.refMedium; } if (attribution.refUrl) { - metadata.attribution_ref_url = attribution.refUrl; + metadata.referrer_url = attribution.refUrl; } } diff --git a/ghost/members-events-service/lib/event-storage.js b/ghost/members-events-service/lib/event-storage.js index dc821c1a27..3794bcab11 100644 --- a/ghost/members-events-service/lib/event-storage.js +++ b/ghost/members-events-service/lib/event-storage.js @@ -5,8 +5,8 @@ const {MemberCreatedEvent, SubscriptionCreatedEvent} = require('@tryghost/member */ class EventStorage { /** - * - * @param {Object} deps + * + * @param {Object} deps * @param {Object} deps.labsService * @param {Object} deps.models * @param {Object} deps.models.MemberCreatedEvent @@ -37,7 +37,10 @@ class EventStorage { attribution_id: attribution?.id ?? null, attribution_url: attribution?.url ?? null, attribution_type: attribution?.type ?? null, - source: event.data.source + source: event.data.source, + referrer_source: attribution?.refSource ?? null, + referrer_medium: attribution?.refMedium ?? null, + referrer_url: attribution?.refUrl ?? null }); }); @@ -56,7 +59,10 @@ class EventStorage { created_at: event.timestamp, attribution_id: attribution?.id ?? null, attribution_url: attribution?.url ?? null, - attribution_type: attribution?.type ?? null + attribution_type: attribution?.type ?? null, + referrer_source: attribution?.refSource ?? null, + referrer_medium: attribution?.refMedium ?? null, + referrer_url: attribution?.refUrl ?? null }); }); } diff --git a/ghost/stripe/lib/WebhookController.js b/ghost/stripe/lib/WebhookController.js index db0760a04a..0b81b23046 100644 --- a/ghost/stripe/lib/WebhookController.js +++ b/ghost/stripe/lib/WebhookController.js @@ -226,7 +226,10 @@ module.exports = class WebhookController { const attribution = { id: session.metadata.attribution_id ?? null, url: session.metadata.attribution_url ?? null, - type: session.metadata.attribution_type ?? null + type: session.metadata.attribution_type ?? null, + refSource: session.metadata.referrer_source ?? null, + refMedium: session.metadata.referrer_medium ?? null, + refUrl: session.metadata.referrer_url ?? null }; const payerName = _.get(customer, 'subscriptions.data[0].default_payment_method.billing_details.name'); @@ -254,7 +257,10 @@ module.exports = class WebhookController { const attribution = { id: session.metadata?.attribution_id ?? null, url: session.metadata?.attribution_url ?? null, - type: session.metadata?.attribution_type ?? null + type: session.metadata?.attribution_type ?? null, + refSource: session.metadata.referrer_source ?? null, + refMedium: session.metadata.referrer_medium ?? null, + refUrl: session.metadata.referrer_url ?? null }; if (payerName && !member.get('name')) {