mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added generator referrer attribution for paid subscriptions (#19419)
ref PROD-244
This commit is contained in:
parent
c16960e5bc
commit
54e3abfbc2
1 changed files with 31 additions and 8 deletions
|
@ -4,7 +4,7 @@ const {luck} = require('../utils/random');
|
||||||
|
|
||||||
class MembersSubscriptionCreatedEventsImporter extends TableImporter {
|
class MembersSubscriptionCreatedEventsImporter extends TableImporter {
|
||||||
static table = 'members_subscription_created_events';
|
static table = 'members_subscription_created_events';
|
||||||
static dependencies = ['members_stripe_customers_subscriptions', 'posts'];
|
static dependencies = ['members_stripe_customers_subscriptions', 'posts', 'mentions'];
|
||||||
|
|
||||||
constructor(knex, transaction) {
|
constructor(knex, transaction) {
|
||||||
super(MembersSubscriptionCreatedEventsImporter.table, 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');
|
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.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.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);
|
await this.importForEach(membersStripeCustomersSubscriptions, quantity ? quantity / membersStripeCustomersSubscriptions.length : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
generate() {
|
generate() {
|
||||||
let attribution = {};
|
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));
|
const post = this.posts.find(p => p.visibility === 'public' && new Date(p.published_at) < new Date(this.model.created_at));
|
||||||
if (post) {
|
if (post) {
|
||||||
attribution = {
|
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);
|
const memberCustomer = this.membersStripeCustomers.find(c => c.customer_id === this.model.customer_id);
|
||||||
|
|
||||||
return Object.assign({}, {
|
return {
|
||||||
id: faker.database.mongodbObjectId(),
|
id: faker.database.mongodbObjectId(),
|
||||||
created_at: this.model.created_at,
|
created_at: this.model.created_at,
|
||||||
member_id: memberCustomer.member_id,
|
member_id: memberCustomer.member_id,
|
||||||
subscription_id: this.model.id,
|
subscription_id: this.model.id,
|
||||||
// TODO: Implement referrers
|
...attribution,
|
||||||
referrer_source: null,
|
...referrer
|
||||||
referrer_medium: null,
|
};
|
||||||
referrer_url: null
|
|
||||||
}, attribution);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue