mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-25 09:14:25 +00:00
Revert/undo-788f5083-ef8657bb (#8353)
This reverts the addition of GTM for 1.38, as it was still present in the built files. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-8353-Revert-undo-788f5083-ef8657bb-2f66d73d365081818d43fcaab220a4ef) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -206,49 +206,6 @@ describe('useSubscription', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('pushes purchase event after a pending subscription completes', async () => {
|
||||
window.dataLayer = []
|
||||
localStorage.setItem(
|
||||
'pending_subscription_purchase',
|
||||
JSON.stringify({
|
||||
tierKey: 'creator',
|
||||
billingCycle: 'monthly',
|
||||
timestamp: Date.now()
|
||||
})
|
||||
)
|
||||
|
||||
vi.mocked(global.fetch).mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
is_active: true,
|
||||
subscription_id: 'sub_123',
|
||||
subscription_tier: 'CREATOR',
|
||||
subscription_duration: 'MONTHLY'
|
||||
})
|
||||
} as Response)
|
||||
|
||||
mockIsLoggedIn.value = true
|
||||
const { fetchStatus } = useSubscription()
|
||||
|
||||
await fetchStatus()
|
||||
|
||||
expect(window.dataLayer).toHaveLength(1)
|
||||
expect(window.dataLayer?.[0]).toMatchObject({
|
||||
event: 'purchase',
|
||||
transaction_id: 'sub_123',
|
||||
currency: 'USD',
|
||||
items: [
|
||||
{
|
||||
item_id: 'monthly_creator',
|
||||
item_variant: 'monthly',
|
||||
item_category: 'subscription',
|
||||
quantity: 1
|
||||
}
|
||||
]
|
||||
})
|
||||
expect(localStorage.getItem('pending_subscription_purchase')).toBeNull()
|
||||
})
|
||||
|
||||
it('should handle fetch errors gracefully', async () => {
|
||||
vi.mocked(global.fetch).mockResolvedValue({
|
||||
ok: false,
|
||||
|
||||
@@ -8,20 +8,12 @@ import { getComfyApiBaseUrl, getComfyPlatformBaseUrl } from '@/config/comfyApi'
|
||||
import { t } from '@/i18n'
|
||||
import { isCloud } from '@/platform/distribution/types'
|
||||
import { useTelemetry } from '@/platform/telemetry'
|
||||
import { pushDataLayerEvent } from '@/platform/telemetry/gtm'
|
||||
import {
|
||||
FirebaseAuthStoreError,
|
||||
useFirebaseAuthStore
|
||||
} from '@/stores/firebaseAuthStore'
|
||||
import { useDialogService } from '@/services/dialogService'
|
||||
import {
|
||||
getTierPrice,
|
||||
TIER_TO_KEY
|
||||
} from '@/platform/cloud/subscription/constants/tierPricing'
|
||||
import {
|
||||
clearPendingSubscriptionPurchase,
|
||||
getPendingSubscriptionPurchase
|
||||
} from '@/platform/cloud/subscription/utils/subscriptionPurchaseTracker'
|
||||
import { TIER_TO_KEY } from '@/platform/cloud/subscription/constants/tierPricing'
|
||||
import type { operations } from '@/types/comfyRegistryTypes'
|
||||
import { useSubscriptionCancellationWatcher } from './useSubscriptionCancellationWatcher'
|
||||
|
||||
@@ -101,45 +93,7 @@ function useSubscriptionInternal() {
|
||||
: baseName
|
||||
})
|
||||
|
||||
function buildApiUrl(path: string): string {
|
||||
return `${getComfyApiBaseUrl()}${path}`
|
||||
}
|
||||
|
||||
function trackSubscriptionPurchase(
|
||||
status: CloudSubscriptionStatusResponse | null
|
||||
): void {
|
||||
if (!status?.is_active || !status.subscription_id) return
|
||||
|
||||
const pendingPurchase = getPendingSubscriptionPurchase()
|
||||
if (!pendingPurchase) return
|
||||
|
||||
const { tierKey, billingCycle } = pendingPurchase
|
||||
const isYearly = billingCycle === 'yearly'
|
||||
const baseName = t(`subscription.tiers.${tierKey}.name`)
|
||||
const planName = isYearly
|
||||
? t('subscription.tierNameYearly', { name: baseName })
|
||||
: baseName
|
||||
const unitPrice = getTierPrice(tierKey, isYearly)
|
||||
const value = isYearly && tierKey !== 'founder' ? unitPrice * 12 : unitPrice
|
||||
pushDataLayerEvent({
|
||||
event: 'purchase',
|
||||
transaction_id: status.subscription_id,
|
||||
value,
|
||||
currency: 'USD',
|
||||
items: [
|
||||
{
|
||||
item_id: `${billingCycle}_${tierKey}`,
|
||||
item_name: planName,
|
||||
item_category: 'subscription',
|
||||
item_variant: billingCycle,
|
||||
price: value,
|
||||
quantity: 1
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
clearPendingSubscriptionPurchase()
|
||||
}
|
||||
const buildApiUrl = (path: string) => `${getComfyApiBaseUrl()}${path}`
|
||||
|
||||
const fetchStatus = wrapWithErrorHandlingAsync(
|
||||
fetchSubscriptionStatus,
|
||||
@@ -240,12 +194,6 @@ function useSubscriptionInternal() {
|
||||
|
||||
const statusData = await response.json()
|
||||
subscriptionStatus.value = statusData
|
||||
|
||||
try {
|
||||
await trackSubscriptionPurchase(statusData)
|
||||
} catch (error) {
|
||||
console.error('Failed to track subscription purchase', error)
|
||||
}
|
||||
return statusData
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
useFirebaseAuthStore
|
||||
} from '@/stores/firebaseAuthStore'
|
||||
import type { TierKey } from '@/platform/cloud/subscription/constants/tierPricing'
|
||||
import { startSubscriptionPurchaseTracking } from '@/platform/cloud/subscription/utils/subscriptionPurchaseTracker'
|
||||
import type { BillingCycle } from './subscriptionTierRank'
|
||||
|
||||
type CheckoutTier = TierKey | `${TierKey}-yearly`
|
||||
@@ -79,7 +78,6 @@ export async function performSubscriptionCheckout(
|
||||
const data = await response.json()
|
||||
|
||||
if (data.checkout_url) {
|
||||
startSubscriptionPurchaseTracking(tierKey, currentBillingCycle)
|
||||
if (openInNewTab) {
|
||||
window.open(data.checkout_url, '_blank')
|
||||
} else {
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
import type { TierKey } from '@/platform/cloud/subscription/constants/tierPricing'
|
||||
import type { BillingCycle } from './subscriptionTierRank'
|
||||
|
||||
type PendingSubscriptionPurchase = {
|
||||
tierKey: TierKey
|
||||
billingCycle: BillingCycle
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
const STORAGE_KEY = 'pending_subscription_purchase'
|
||||
const MAX_AGE_MS = 24 * 60 * 60 * 1000 // 24 hours
|
||||
const VALID_TIERS: TierKey[] = ['standard', 'creator', 'pro', 'founder']
|
||||
const VALID_CYCLES: BillingCycle[] = ['monthly', 'yearly']
|
||||
|
||||
const safeRemove = (): void => {
|
||||
try {
|
||||
localStorage.removeItem(STORAGE_KEY)
|
||||
} catch {
|
||||
// Ignore storage errors (e.g. private browsing mode)
|
||||
}
|
||||
}
|
||||
|
||||
export function startSubscriptionPurchaseTracking(
|
||||
tierKey: TierKey,
|
||||
billingCycle: BillingCycle
|
||||
): void {
|
||||
if (typeof window === 'undefined') return
|
||||
try {
|
||||
const payload: PendingSubscriptionPurchase = {
|
||||
tierKey,
|
||||
billingCycle,
|
||||
timestamp: Date.now()
|
||||
}
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(payload))
|
||||
} catch {
|
||||
// Ignore storage errors (e.g. private browsing mode)
|
||||
}
|
||||
}
|
||||
|
||||
export function getPendingSubscriptionPurchase(): PendingSubscriptionPurchase | null {
|
||||
if (typeof window === 'undefined') return null
|
||||
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (!raw) return null
|
||||
|
||||
const parsed = JSON.parse(raw) as PendingSubscriptionPurchase
|
||||
if (!parsed || typeof parsed !== 'object') {
|
||||
safeRemove()
|
||||
return null
|
||||
}
|
||||
|
||||
const { tierKey, billingCycle, timestamp } = parsed
|
||||
if (
|
||||
!VALID_TIERS.includes(tierKey) ||
|
||||
!VALID_CYCLES.includes(billingCycle) ||
|
||||
typeof timestamp !== 'number'
|
||||
) {
|
||||
safeRemove()
|
||||
return null
|
||||
}
|
||||
|
||||
if (Date.now() - timestamp > MAX_AGE_MS) {
|
||||
safeRemove()
|
||||
return null
|
||||
}
|
||||
|
||||
return parsed
|
||||
} catch {
|
||||
safeRemove()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function clearPendingSubscriptionPurchase(): void {
|
||||
if (typeof window === 'undefined') return
|
||||
safeRemove()
|
||||
}
|
||||
Reference in New Issue
Block a user