overleaf/services/web/frontend/js/pages/user/subscription/plans-v2/plans-v2-tracking.ts
M Fahru 41e2d1bba7 Merge pull request #20005 from overleaf/mf-view-events-plans-page
[web] Implement plans page and interstitial payment page view events for plans redesign test

GitOrigin-RevId: 023338acffe149db93b37d94cf06e8102ffcff8f
2024-08-21 08:05:43 +00:00

46 lines
1.4 KiB
TypeScript

import { sendMB } from '@/infrastructure/event-tracking'
import { getSplitTestVariant } from '@/utils/splitTestUtils'
import getMeta from '@/utils/meta'
export function sendPlansViewEvent() {
document.addEventListener(
'DOMContentLoaded',
function () {
const currency = getMeta('ol-recommendedCurrency')
const countryCode = getMeta('ol-countryCode')
const geoPricingLATAMTestVariant = getSplitTestVariant(
'geo-pricing-latam-v2'
)
const websiteRedesignPlansTestVariant = getMeta(
'ol-websiteRedesignPlansVariant'
)
const device = window.matchMedia('(max-width: 767px)').matches
? 'mobile'
: 'desktop'
const plansPageViewSegmentation = {
currency,
countryCode,
device,
'geo-pricing-latam-v2': geoPricingLATAMTestVariant,
'website-redesign-plans': websiteRedesignPlansTestVariant,
}
const isPlansPage = window.location.href.includes(
'user/subscription/plans'
)
const isInterstitialPaymentPage = window.location.href.includes(
'user/subscription/choose-your-plan'
)
if (isPlansPage) {
sendMB('plans-page-view', plansPageViewSegmentation)
} else if (isInterstitialPaymentPage) {
sendMB('paywall-plans-page-view', plansPageViewSegmentation)
}
},
{ once: true }
)
}