diff --git a/src/app/analytics/ga.service.test.ts b/src/app/analytics/ga.service.test.ts index be2b09f00..c374db693 100644 --- a/src/app/analytics/ga.service.test.ts +++ b/src/app/analytics/ga.service.test.ts @@ -211,7 +211,6 @@ describe('Testing GA Service', () => { vi.mocked(localStorageService.get).mockImplementation((key) => { const store: Record = { - subscriptionId: 'sub_12345', paymentIntentId: '', priceId: 'price_yearly_2tb', currency: 'EUR', @@ -236,7 +235,7 @@ describe('Testing GA Service', () => { expect(event).toMatchObject({ event: 'purchase', ecommerce: { - transaction_id: 'sub_12345', + transaction_id: 'user_uuid_123', currency: 'EUR', value: 95.9, items: [ @@ -260,7 +259,6 @@ describe('Testing GA Service', () => { vi.mocked(localStorageService.getUser).mockReturnValue({ uuid: 'user_uuid' } as any); vi.mocked(localStorageService.get).mockImplementation((key) => { if (key === 'paymentIntentId') return 'pi_999'; - if (key === 'subscriptionId') return 'sub_888'; if (key === 'amountPaid') return '100'; if (key === 'itemOriginalPrice') return '119.88'; if (key === 'checkout_item_data') @@ -279,34 +277,10 @@ describe('Testing GA Service', () => { expect(event.ecommerce.transaction_id).toBe('pi_999'); }); - it('should use subscription ID when payment intent is not available', () => { - vi.mocked(localStorageService.getUser).mockReturnValue({ uuid: 'user_uuid' } as any); - vi.mocked(localStorageService.get).mockImplementation((key) => { - if (key === 'paymentIntentId') return null; - if (key === 'subscriptionId') return 'sub_888'; - if (key === 'amountPaid') return '100'; - if (key === 'itemOriginalPrice') return '119.88'; - if (key === 'checkout_item_data') - return JSON.stringify({ - item_name: '2TB Year Plan', - item_category: 'Individual', - item_variant: 'year', - discount: 0, - }); - return ''; - }); - - gaService.trackPurchase(); - - const event = globalThis.window.dataLayer[0] as any; - expect(event.ecommerce.transaction_id).toBe('sub_888'); - }); - - it('should fallback to user UUID when neither payment intent nor subscription ID are available', () => { + it('should fallback to user UUID when payment intent is not available', () => { vi.mocked(localStorageService.getUser).mockReturnValue({ uuid: 'user_fallback_uuid' } as any); vi.mocked(localStorageService.get).mockImplementation((key) => { if (key === 'paymentIntentId') return null; - if (key === 'subscriptionId') return null; if (key === 'amountPaid') return '100'; if (key === 'itemOriginalPrice') return '119.88'; if (key === 'checkout_item_data') diff --git a/src/app/analytics/ga.service.ts b/src/app/analytics/ga.service.ts index 83f89fd87..73723eefb 100644 --- a/src/app/analytics/ga.service.ts +++ b/src/app/analytics/ga.service.ts @@ -154,7 +154,6 @@ function trackPurchase(): void { return; } - const subscriptionId = localStorageService.get('subscriptionId'); const paymentIntentId = localStorageService.get('paymentIntentId'); const priceId = localStorageService.get('priceId'); const currency = localStorageService.get('currency'); @@ -173,7 +172,7 @@ function trackPurchase(): void { console.error('[GA Service] Error parsing checkout_item_data:', parseError); } - const transactionId = paymentIntentId || subscriptionId || uuid; + const transactionId = paymentIntentId || uuid; const currencyCode = currency ?? 'EUR'; const itemName = checkoutItemData?.item_name || 'Unknown Plan'; diff --git a/src/app/analytics/impact.service.test.ts b/src/app/analytics/impact.service.test.ts index 495fb3c97..fd164a934 100644 --- a/src/app/analytics/impact.service.test.ts +++ b/src/app/analytics/impact.service.test.ts @@ -42,7 +42,6 @@ vi.mock('services/error.service', () => ({ }, })); -const subId = 'sub_123'; const paymentIntentId = 'py_123'; const mockedUserUuid = '00000000-0000-0000-0000-0000000000'; const mockImpactApiUrl = 'mock-impact-api-url'; @@ -93,7 +92,6 @@ beforeEach(() => { vi.spyOn(localStorageService, 'get').mockImplementation((key) => { if (key === 'paymentIntentId') return paymentIntentId; - if (key === 'subscriptionId') return subId; if (key === 'productName') return planName; if (key === 'priceId') return product.price.id; if (key === 'currency') return product.price.currency; @@ -110,7 +108,6 @@ describe('Testing Impact Service', () => { const setToLocalStorageSpy = vi.spyOn(localStorageService, 'set'); savePaymentDataInLocalStorage({ - subscriptionId: subId, paymentIntentId, selectedPlan: product as PriceWithTax, users: 1, @@ -121,32 +118,12 @@ describe('Testing Impact Service', () => { expect(setToLocalStorageSpy).toHaveBeenCalledWith('amountPaid', expectedAmount); }); - it('When the plan is not lifetime, then it saves the subscription ID to localStorage', () => { - const setToLocalStorageSpy = vi.spyOn(localStorageService, 'set'); - - savePaymentDataInLocalStorage({ - subscriptionId: subId, - paymentIntentId: undefined, - selectedPlan: product as PriceWithTax, - users: 1, - couponCodeData: promoCode, - isFirstPurchase: true, - }); - - expect(setToLocalStorageSpy).toHaveBeenCalledWith('subscriptionId', subId); - }); - it('When the plan is lifetime, then it saves the payment intent ID to localStorage', () => { const setToLocalStorageSpy = vi.spyOn(localStorageService, 'set'); - const lifetimeProduct = { - ...product, - price: { ...product.price, interval: 'lifetime' }, - }; savePaymentDataInLocalStorage({ - subscriptionId: undefined, paymentIntentId, - selectedPlan: lifetimeProduct as PriceWithTax, + selectedPlan: product as PriceWithTax, users: 1, couponCodeData: promoCode, isFirstPurchase: true, @@ -159,7 +136,6 @@ describe('Testing Impact Service', () => { const setToLocalStorageSpy = vi.spyOn(localStorageService, 'set'); savePaymentDataInLocalStorage({ - subscriptionId: subId, paymentIntentId, selectedPlan: product as PriceWithTax, users: 1, @@ -176,7 +152,6 @@ describe('Testing Impact Service', () => { const setToLocalStorageSpy = vi.spyOn(localStorageService, 'set'); savePaymentDataInLocalStorage({ - subscriptionId: subId, paymentIntentId, selectedPlan: product as PriceWithTax, users: 1, @@ -191,7 +166,6 @@ describe('Testing Impact Service', () => { const setToLocalStorageSpy = vi.spyOn(localStorageService, 'set'); savePaymentDataInLocalStorage({ - subscriptionId: subId, paymentIntentId, selectedPlan: product as PriceWithTax, users: 1, @@ -287,7 +261,6 @@ describe('Testing Impact Service', () => { timestamp: expect.any(String), properties: expect.objectContaining({ impact_value: parseFloat(expectedAmount), - subscription_id: subId, payment_intent: paymentIntentId, order_promo_code: promoCode.codeName, }), @@ -301,7 +274,6 @@ describe('Testing Impact Service', () => { it('When the amount paid is 0, then it uses 0.01 as the minimum impact value', async () => { vi.spyOn(localStorageService, 'get').mockImplementation((key) => { if (key === 'amountPaid') return '0'; - if (key === 'subscriptionId') return subId; if (key === 'couponCode') return promoCode.codeName; if (key === 'isFirstPurchase') return 'true'; return null; @@ -382,7 +354,6 @@ describe('Testing Impact Service', () => { vi.spyOn(localStorageService, 'get').mockImplementation((key) => { if (key === 'couponCode') return 'CNINTERNXT'; // In whitelist if (key === 'amountPaid') return expectedAmount; - if (key === 'subscriptionId') return subId; if (key === 'isFirstPurchase') return 'true'; return null; }); diff --git a/src/app/analytics/impact.service.ts b/src/app/analytics/impact.service.ts index a1a20e605..6549b3741 100644 --- a/src/app/analytics/impact.service.ts +++ b/src/app/analytics/impact.service.ts @@ -29,7 +29,6 @@ import { sendAddShoppersConversion } from './addShoppers.services'; * */ export interface SavePaymentDataParams { - subscriptionId: string | undefined; paymentIntentId: string | undefined; selectedPlan: PriceWithTax | undefined; users: number; @@ -38,18 +37,13 @@ export interface SavePaymentDataParams { } export function savePaymentDataInLocalStorage({ - subscriptionId, paymentIntentId, selectedPlan, users, couponCodeData, isFirstPurchase, }: SavePaymentDataParams) { - if (subscriptionId && selectedPlan?.price.interval !== 'lifetime') { - localStorageService.set('subscriptionId', subscriptionId); - } - - if (paymentIntentId && selectedPlan?.price.interval === 'lifetime') { + if (paymentIntentId) { localStorageService.set('paymentIntentId', paymentIntentId); } @@ -76,12 +70,13 @@ export async function trackSignUp(uuid: string): Promise { const IMPACT_API = envService.getVariable('impactApiUrl'); const anonymousID = getCookie('impactAnonymousId'); const source = getCookie('impactSource'); + const irclickid = getCookie('impactClickId'); if (globalThis.window.gtag) { window.gtag('event', 'User Signup'); } - if (source && source !== 'direct') { + if ((source && source !== 'direct') || irclickid) { await axios.post(IMPACT_API, { anonymousId: anonymousID, timestamp: dayjs().format('YYYY-MM-DDTHH:mm:ss.sssZ'), @@ -90,6 +85,7 @@ export async function trackSignUp(uuid: string): Promise { type: 'track', event: 'User Signup', ...(gclid && { gclid }), + ...(irclickid && { properties: { irclickid } }), }); } } catch (error) { @@ -107,7 +103,6 @@ export async function trackPaymentConversion(): Promise { } const { uuid, email: userEmail } = userSettings; - const subscription = localStorageService.get('subscriptionId'); const paymentIntent = localStorageService.get('paymentIntentId'); const currency = localStorageService.get('currency'); const amountPaidStr = localStorageService.get('amountPaid'); @@ -130,20 +125,21 @@ export async function trackPaymentConversion(): Promise { const IMPACT_API = envService.getVariable('impactApiUrl'); const anonymousID = getCookie('impactAnonymousId') || uuidV4(); const source = getCookie('impactSource'); + const irclickid = getCookie('impactClickId'); const IMPACT_COUPON_WHITELIST = ['CNINTERNXT', 'CNINTERNXTL', 'CLOUDOFF']; const isImpactCoupon = couponCode && IMPACT_COUPON_WHITELIST.includes(couponCode.toUpperCase()); - if (isFirstPurchase && ((source && source !== 'direct') || isImpactCoupon)) { + if (isFirstPurchase && ((source && source !== 'direct') || isImpactCoupon || irclickid)) { try { await axios.post(IMPACT_API, { anonymousId: anonymousID, timestamp: dayjs().format('YYYY-MM-DDTHH:mm:ss.sssZ'), properties: { impact_value: amount === 0 ? 0.01 : amount, - subscription_id: subscription, payment_intent: paymentIntent, ...(couponCode && { order_promo_code: couponCode }), + ...(irclickid && { irclickid }), }, userId: uuid, type: 'track', diff --git a/src/views/Checkout/hooks/useUserPayment.ts b/src/views/Checkout/hooks/useUserPayment.ts index f32560076..128b34879 100644 --- a/src/views/Checkout/hooks/useUserPayment.ts +++ b/src/views/Checkout/hooks/useUserPayment.ts @@ -163,7 +163,6 @@ export const useUserPayment = () => { }); savePaymentDataInLocalStorage({ - subscriptionId: subscription.subscriptionId, paymentIntentId: subscription.paymentIntentId, selectedPlan: currentSelectedPlan, users: 1, @@ -221,7 +220,6 @@ export const useUserPayment = () => { }); savePaymentDataInLocalStorage({ - subscriptionId: undefined, paymentIntentId, selectedPlan: currentSelectedPlan, users: 1, diff --git a/src/views/Checkout/views/CheckoutSuccessView.tsx b/src/views/Checkout/views/CheckoutSuccessView.tsx index 3fe98c529..f035f12c2 100644 --- a/src/views/Checkout/views/CheckoutSuccessView.tsx +++ b/src/views/Checkout/views/CheckoutSuccessView.tsx @@ -10,7 +10,6 @@ import metaService from 'app/analytics/meta.service'; import { userStoragePolling } from 'utils/userStoragePolling.utils'; export function removePaymentsStorage() { - localStorageService.removeItem('subscriptionId'); localStorageService.removeItem('paymentIntentId'); localStorageService.removeItem('amountPaid'); localStorageService.removeItem('productName');