Fixed FirstPromoter integration to ignore old referrals

closes https://github.com/TryGhost/Team/issues/2888

Due to lack of member's created at date, we previously called the FirstPromoter tracking function for all logged-in members irrespective of when they signed up. This caused issues in few cases where members who were already signed up were getting falsely attributed as referrals if they had clicked on a referral link previously.

This change uses the member's created at date which is now available on frontend for logged-in members, and ignored the FirstPromoter tracking script if member had signed up more than 24 hours ago.
This commit is contained in:
Rishabh 2023-04-04 23:46:05 +05:30
parent e95c531e8b
commit 56eb7a822f
3 changed files with 17 additions and 2 deletions

View File

@ -20,6 +20,7 @@ module.exports.formattedMemberResponse = function formattedMemberResponse(member
subscribed: !!member.subscribed,
subscriptions: member.subscriptions || [],
paid: member.status !== 'free',
created_at: member.created_at,
enable_comment_notifications: member.enable_comment_notifications
};
if (member.newsletters) {

View File

@ -11,7 +11,7 @@ import {getActivePage, isAccountPage, isOfferPage} from './pages';
import ActionHandler from './actions';
import './App.css';
import NotificationParser from './utils/notifications';
import {allowCompMemberUpgrade, createPopupNotification, getCurrencySymbol, getFirstpromoterId, getPriceIdFromPageQuery, getProductCadenceFromPrice, getProductFromId, getQueryPrice, getSiteDomain, isActiveOffer, isComplimentaryMember, isInviteOnlySite, isPaidMember, isSentryEventAllowed, removePortalLinkFromUrl} from './utils/helpers';
import {allowCompMemberUpgrade, createPopupNotification, getCurrencySymbol, getFirstpromoterId, getPriceIdFromPageQuery, getProductCadenceFromPrice, getProductFromId, getQueryPrice, getSiteDomain, isActiveOffer, isComplimentaryMember, isInviteOnlySite, isPaidMember, isRecentMember, isSentryEventAllowed, removePortalLinkFromUrl} from './utils/helpers';
import {handleDataAttributes} from './data-attributes';
import i18nLib from '@tryghost/i18n';
@ -558,7 +558,7 @@ export default class App extends React.Component {
if (!_t || 'complete' === _t || 'loaded' === _t) {
try {
window.$FPROM.init(firstPromoterId, siteDomain);
if (member) {
if (isRecentMember({member})) {
const email = member.email;
const uid = member.uuid;
if (window.$FPROM) {

View File

@ -891,3 +891,17 @@ export function getUrlHistory() {
console.warn(`[Portal] Failed to load member URL history:`, error);
}
}
// Check if member is a recent member, i.e. created in last 24 hours
export function isRecentMember({member}) {
if (!member?.created_at) {
return false;
}
const now = new Date();
const created = new Date(member.created_at);
const diff = now.getTime() - created.getTime();
const diffHours = Math.round(diff / (1000 * 60 * 60));
return diffHours < 24;
}