mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Added generator referrer attribution for paid subscriptions (#19419)
ref PROD-244
This commit is contained in:
parent
c16960e5bc
commit
54e3abfbc2
@ -4,7 +4,7 @@ const {luck} = require('../utils/random');
|
||||
|
||||
class MembersSubscriptionCreatedEventsImporter extends TableImporter {
|
||||
static table = 'members_subscription_created_events';
|
||||
static dependencies = ['members_stripe_customers_subscriptions', 'posts'];
|
||||
static dependencies = ['members_stripe_customers_subscriptions', 'posts', 'mentions'];
|
||||
|
||||
constructor(knex, transaction) {
|
||||
super(MembersSubscriptionCreatedEventsImporter.table, knex, transaction);
|
||||
@ -14,13 +14,16 @@ class MembersSubscriptionCreatedEventsImporter extends TableImporter {
|
||||
const membersStripeCustomersSubscriptions = await this.transaction.select('id', 'created_at', 'customer_id').from('members_stripe_customers_subscriptions');
|
||||
this.membersStripeCustomers = await this.transaction.select('id', 'member_id', 'customer_id').from('members_stripe_customers');
|
||||
this.posts = await this.transaction.select('id', 'published_at', 'visibility', 'type', 'slug').from('posts').orderBy('published_at', 'desc');
|
||||
this.incomingRecommendations = await this.transaction.select('id', 'source', 'created_at').from('mentions');
|
||||
|
||||
await this.importForEach(membersStripeCustomersSubscriptions, quantity ? quantity / membersStripeCustomersSubscriptions.length : 1);
|
||||
}
|
||||
|
||||
generate() {
|
||||
let attribution = {};
|
||||
if (luck(10)) {
|
||||
let referrer = {};
|
||||
|
||||
if (luck(30)) {
|
||||
const post = this.posts.find(p => p.visibility === 'public' && new Date(p.published_at) < new Date(this.model.created_at));
|
||||
if (post) {
|
||||
attribution = {
|
||||
@ -30,18 +33,38 @@ class MembersSubscriptionCreatedEventsImporter extends TableImporter {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (luck(40)) {
|
||||
if (luck(20)) {
|
||||
// Ghost network
|
||||
referrer = {
|
||||
referrer_source: luck(20) ? 'Ghost.org' : 'Ghost Explore',
|
||||
referrer_url: 'ghost.org',
|
||||
referrer_medium: 'Ghost Network'
|
||||
};
|
||||
} else {
|
||||
// Incoming recommendation
|
||||
const incomingRecommendation = faker.helpers.arrayElement(this.incomingRecommendations);
|
||||
|
||||
const hostname = new URL(incomingRecommendation.source).hostname;
|
||||
referrer = {
|
||||
referrer_source: hostname,
|
||||
referrer_url: hostname,
|
||||
referrer_medium: faker.helpers.arrayElement([null, 'Email'])
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const memberCustomer = this.membersStripeCustomers.find(c => c.customer_id === this.model.customer_id);
|
||||
|
||||
return Object.assign({}, {
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
created_at: this.model.created_at,
|
||||
member_id: memberCustomer.member_id,
|
||||
subscription_id: this.model.id,
|
||||
// TODO: Implement referrers
|
||||
referrer_source: null,
|
||||
referrer_medium: null,
|
||||
referrer_url: null
|
||||
}, attribution);
|
||||
...attribution,
|
||||
...referrer
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user