diff --git a/packages/common/src/models/Analytics.ts b/packages/common/src/models/Analytics.ts index 513d82fb553..93e0a1c52b7 100644 --- a/packages/common/src/models/Analytics.ts +++ b/packages/common/src/models/Analytics.ts @@ -1600,24 +1600,29 @@ type BuyUSDCRecoveryFailure = { error: string } -type PurchaseContentStarted = { - eventName: Name.PURCHASE_CONTENT_STARTED - extraAmount?: number - extraAmountPreset?: string +type ContentPurchaseMetadata = { + price: number contentId: number + contentName: string contentType: string + payExtraAmount: number + payExtraPreset?: string + artistHandle: string + isVerifiedArtist: boolean } -type PurchaseContentSuccess = { + +type PurchaseContentStarted = ContentPurchaseMetadata & { + eventName: Name.PURCHASE_CONTENT_STARTED +} +type PurchaseContentSuccess = ContentPurchaseMetadata & { eventName: Name.PURCHASE_CONTENT_SUCCESS - contentId: number - contentType: string } -type PurchaseContentFailure = { + +type PurchaseContentFailure = ContentPurchaseMetadata & { eventName: Name.PURCHASE_CONTENT_FAILURE - contentId: number - contentType: string error: string } + type PurchaseContentTwitterShare = { eventName: Name.PURCHASE_CONTENT_TWITTER_SHARE text: string diff --git a/packages/common/src/store/purchase-content/sagas.ts b/packages/common/src/store/purchase-content/sagas.ts index af94b060d68..0d4db145354 100644 --- a/packages/common/src/store/purchase-content/sagas.ts +++ b/packages/common/src/store/purchase-content/sagas.ts @@ -47,10 +47,7 @@ type GetPurchaseConfigArgs = { contentType: ContentType } -function* getUSDCPremiumConditions({ - contentId, - contentType -}: GetPurchaseConfigArgs) { +function* getContentInfo({ contentId, contentType }: GetPurchaseConfigArgs) { if (contentType !== ContentType.TRACK) { throw new Error('Only tracks are supported') } @@ -62,7 +59,19 @@ function* getUSDCPremiumConditions({ ) { throw new Error('Content is missing premium conditions') } - return trackInfo.premium_conditions.usdc_purchase + const artistInfo = yield* select(getUser, { id: trackInfo.owner_id }) + if (!artistInfo) { + throw new Error('Failed to retrieve content owner') + } + + const { + premium_conditions: { + usdc_purchase: { price } + }, + title + } = trackInfo + + return { price, title, artistInfo } } function* getPurchaseConfig({ contentId, contentType }: GetPurchaseConfigArgs) { @@ -140,24 +149,32 @@ function* doStartPurchaseContentFlow({ const reportToSentry = yield* getContext('reportToSentry') const { track, make } = yield* getContext('analytics') + const { price, title, artistInfo } = yield* call(getContentInfo, { + contentId, + contentType + }) + + const analyticsInfo = { + price: price / 100, + contentId, + contentType, + contentName: title, + artistHandle: artistInfo.handle, + isVerifiedArtist: artistInfo.is_verified, + payExtraAmount: extraAmount ? extraAmount / 100 : 0, + payExtraPreset: extraAmountPreset + } + // Record start yield* call( track, make({ eventName: Name.PURCHASE_CONTENT_STARTED, - extraAmount, - extraAmountPreset, - contentId, - contentType + ...analyticsInfo }) ) try { - const { price } = yield* call(getUSDCPremiumConditions, { - contentId, - contentType - }) - // get user bank const userBank = yield* call(getUSDCUserBank) @@ -245,7 +262,10 @@ function* doStartPurchaseContentFlow({ yield* call( track, - make({ eventName: Name.PURCHASE_CONTENT_SUCCESS, contentId, contentType }) + make({ + eventName: Name.PURCHASE_CONTENT_SUCCESS, + ...analyticsInfo + }) ) } catch (e: unknown) { // If we get a known error, pipe it through directly. Otherwise make sure we @@ -264,9 +284,8 @@ function* doStartPurchaseContentFlow({ track, make({ eventName: Name.PURCHASE_CONTENT_FAILURE, - contentId, - contentType, - error: error.message + error: error.message, + ...analyticsInfo }) ) }