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
This commit is contained in:
Rishabh 2022-09-21 15:04:23 +05:30 committed by Rishabh Garg
parent 3b9998cdd6
commit bb0d900937
3 changed files with 21 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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
});
});
}

View File

@ -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')) {