From 708bd4a292ee8fa22833245b451eaa2b69fd42e3 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Tue, 13 Oct 2020 10:35:44 -0500 Subject: [PATCH] chore(analytics): track first-time-purchase info --- website/server/libs/payments/gems.js | 1 + website/server/libs/payments/subscriptions.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/website/server/libs/payments/gems.js b/website/server/libs/payments/gems.js index 96ec179ef5..c6aae19648 100644 --- a/website/server/libs/payments/gems.js +++ b/website/server/libs/payments/gems.js @@ -108,6 +108,7 @@ export async function buyGems (data) { gift: Boolean(data.gift), purchaseValue: amt, headers: data.headers, + firstPurchase: data.user.purchased.txnCount === 1, }); if (data.gift) await buyGemGift(data); diff --git a/website/server/libs/payments/subscriptions.js b/website/server/libs/payments/subscriptions.js index 893ab97966..8e62878e71 100644 --- a/website/server/libs/payments/subscriptions.js +++ b/website/server/libs/payments/subscriptions.js @@ -172,6 +172,8 @@ async function createSubscription (data) { txnEmail(data.user, emailType); } + if (!group && !data.promo) data.user.purchased.txnCount += 1; + if (!data.promo) { analytics.trackPurchase({ uuid: data.user._id, @@ -184,11 +186,10 @@ async function createSubscription (data) { gift: Boolean(data.gift), purchaseValue: block.price, headers: data.headers, + firstPurchase: !group && data.user.purchased.txnCount === 1, }); } - if (!group && !data.promo) data.user.purchased.txnCount += 1; - if (data.gift) { const byUserName = getUserInfo(data.user, ['name']).name;