2021-09-22 07:13:18 -04:00
|
|
|
import '../../../marketing'
|
|
|
|
import '../../../features/plans/group-plan-modal'
|
|
|
|
import * as eventTracking from '../../../infrastructure/event-tracking'
|
|
|
|
import getMeta from '../../../utils/meta'
|
|
|
|
|
2023-03-10 10:57:41 -05:00
|
|
|
let currentView = getMeta('ol-currentView')
|
2021-09-22 07:13:18 -04:00
|
|
|
let currentCurrencyCode = getMeta('ol-recommendedCurrency')
|
2023-03-10 10:57:41 -05:00
|
|
|
const plansPageLayoutV3Variant =
|
|
|
|
getMeta('ol-splitTestVariants')?.['plans-page-layout-v3'] ?? 'default'
|
|
|
|
|
|
|
|
if (window.location.href.includes('validate-pre-rendering=true')) {
|
|
|
|
validatePreRendering()
|
|
|
|
}
|
2021-09-22 07:13:18 -04:00
|
|
|
|
2022-03-01 09:28:01 -05:00
|
|
|
function selectView(view) {
|
|
|
|
document.querySelectorAll('[data-ol-view-tab]').forEach(el => {
|
|
|
|
if (el.getAttribute('data-ol-view-tab') === view) {
|
|
|
|
el.classList.add('active')
|
|
|
|
} else {
|
|
|
|
el.classList.remove('active')
|
|
|
|
}
|
|
|
|
})
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2022-03-01 09:28:01 -05:00
|
|
|
document.querySelectorAll('[data-ol-view]').forEach(el => {
|
|
|
|
el.hidden = el.getAttribute('data-ol-view') !== view
|
|
|
|
})
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2022-05-12 06:24:46 -04:00
|
|
|
updateAnnualSavingBanner(view)
|
2022-03-01 09:28:01 -05:00
|
|
|
currentView = view
|
|
|
|
updateLinkTargets()
|
|
|
|
}
|
|
|
|
|
2021-09-22 07:13:18 -04:00
|
|
|
function setUpViewSwitching(liEl) {
|
|
|
|
const view = liEl.getAttribute('data-ol-view-tab')
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2022-12-16 09:44:27 -05:00
|
|
|
liEl.querySelector('button').addEventListener('click', function (e) {
|
2021-09-22 07:13:18 -04:00
|
|
|
e.preventDefault()
|
2022-03-01 09:28:01 -05:00
|
|
|
eventTracking.send('subscription-funnel', 'plans-page', `${view}-prices`)
|
2022-05-19 05:13:25 -04:00
|
|
|
eventTracking.sendMB('plans-page-toggle', {
|
|
|
|
button: view,
|
2023-01-27 10:04:33 -05:00
|
|
|
'plans-page-layout-v3': plansPageLayoutV3Variant,
|
2022-05-19 05:13:25 -04:00
|
|
|
})
|
2022-03-01 09:28:01 -05:00
|
|
|
selectView(view)
|
2021-09-22 07:13:18 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUpCurrencySwitching(linkEl) {
|
|
|
|
const currencyCode = linkEl.getAttribute('data-ol-currencyCode-switch')
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2021-09-22 07:13:18 -04:00
|
|
|
linkEl.addEventListener('click', function (e) {
|
|
|
|
e.preventDefault()
|
|
|
|
document.querySelectorAll('[data-ol-currencyCode]').forEach(el => {
|
|
|
|
el.hidden = el.getAttribute('data-ol-currencyCode') !== currencyCode
|
|
|
|
})
|
|
|
|
currentCurrencyCode = currencyCode
|
2022-02-01 05:54:13 -05:00
|
|
|
eventTracking.sendMB('plans-page-currency', { currency: currencyCode })
|
2021-09-22 07:13:18 -04:00
|
|
|
updateLinkTargets()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUpSubscriptionTracking(linkEl) {
|
2023-01-27 10:04:33 -05:00
|
|
|
const plansPageLayoutV3Variant =
|
|
|
|
getMeta('ol-splitTestVariants')?.['plans-page-layout-v3'] ?? 'default'
|
|
|
|
|
2021-09-22 07:13:18 -04:00
|
|
|
const plan =
|
|
|
|
linkEl.getAttribute('data-ol-tracking-plan') ||
|
|
|
|
linkEl.getAttribute('data-ol-start-new-subscription')
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2022-02-01 05:54:13 -05:00
|
|
|
const location = linkEl.getAttribute('data-ol-location')
|
|
|
|
const period = linkEl.getAttribute('data-ol-item-view') || currentView
|
2021-09-22 07:13:18 -04:00
|
|
|
|
2022-06-28 09:36:25 -04:00
|
|
|
const DEFAULT_EVENT_TRACKING_KEY = 'plans-page-click'
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2022-06-28 09:36:25 -04:00
|
|
|
const eventTrackingKey =
|
|
|
|
linkEl.getAttribute('data-ol-event-tracking-key') ||
|
|
|
|
DEFAULT_EVENT_TRACKING_KEY
|
2023-01-27 10:04:33 -05:00
|
|
|
|
2022-06-28 09:36:25 -04:00
|
|
|
const eventTrackingSegmentation = {
|
|
|
|
button: plan,
|
|
|
|
location,
|
|
|
|
period,
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eventTrackingKey === DEFAULT_EVENT_TRACKING_KEY) {
|
2023-01-27 10:04:33 -05:00
|
|
|
eventTrackingSegmentation['plans-page-layout-v3'] = plansPageLayoutV3Variant
|
2022-06-28 09:36:25 -04:00
|
|
|
}
|
|
|
|
|
2021-09-22 07:13:18 -04:00
|
|
|
linkEl.addEventListener('click', function () {
|
|
|
|
const customLabel = linkEl.getAttribute('data-ol-tracking-label')
|
|
|
|
const computedLabel = currentView === 'annual' ? `${plan}_annual` : plan
|
|
|
|
const label = customLabel || computedLabel
|
|
|
|
|
2022-02-01 05:54:13 -05:00
|
|
|
eventTracking.sendMB('plans-page-start-trial') // deprecated by plans-page-click
|
|
|
|
eventTracking.send('subscription-funnel', 'sign_up_now_button', label) // deprecated by plans-page-click
|
2022-06-28 09:36:25 -04:00
|
|
|
eventTracking.sendMB(eventTrackingKey, eventTrackingSegmentation)
|
2021-09-22 07:13:18 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-28 09:36:13 -04:00
|
|
|
const searchParams = new URLSearchParams(window.location.search)
|
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
export function updateLinkTargets() {
|
2021-09-22 07:13:18 -04:00
|
|
|
document.querySelectorAll('[data-ol-start-new-subscription]').forEach(el => {
|
|
|
|
if (el.hasAttribute('data-ol-has-custom-href')) return
|
|
|
|
|
|
|
|
const plan = el.getAttribute('data-ol-start-new-subscription')
|
|
|
|
const view = el.getAttribute('data-ol-item-view') || currentView
|
2021-09-24 05:22:28 -04:00
|
|
|
const suffix = view === 'annual' ? `-annual` : `_free_trial_7_days`
|
2021-09-22 07:13:18 -04:00
|
|
|
const planCode = `${plan}${suffix}`
|
|
|
|
|
|
|
|
const location = el.getAttribute('data-ol-location')
|
2022-06-28 09:36:13 -04:00
|
|
|
const itmCampaign = searchParams.get('itm_campaign') || 'plans'
|
|
|
|
const itmContent =
|
|
|
|
itmCampaign === 'plans' ? location : searchParams.get('itm_content')
|
|
|
|
|
|
|
|
const queryString = new URLSearchParams({
|
|
|
|
planCode,
|
|
|
|
currency: currentCurrencyCode,
|
|
|
|
itm_campaign: itmCampaign,
|
|
|
|
})
|
|
|
|
|
|
|
|
if (itmContent) {
|
|
|
|
queryString.set('itm_content', itmContent)
|
|
|
|
}
|
|
|
|
|
2022-10-25 08:02:18 -04:00
|
|
|
if (searchParams.get('itm_referrer')) {
|
|
|
|
queryString.set('itm_referrer', searchParams.get('itm_referrer'))
|
|
|
|
}
|
|
|
|
|
2022-06-28 09:36:13 -04:00
|
|
|
el.href = `/user/subscription/new?${queryString.toString()}`
|
2021-09-22 07:13:18 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-12 06:24:46 -04:00
|
|
|
function updateAnnualSavingBanner(view) {
|
|
|
|
const tooltipEl = document.querySelector('[data-ol-annual-saving-tooltip]')
|
|
|
|
|
|
|
|
if (view === 'annual') {
|
|
|
|
tooltipEl.classList.add('annual-selected')
|
|
|
|
} else {
|
|
|
|
tooltipEl.classList.remove('annual-selected')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 09:28:01 -05:00
|
|
|
function selectViewFromHash() {
|
|
|
|
try {
|
|
|
|
const params = new URLSearchParams(window.location.hash.substring(1))
|
|
|
|
const view = params.get('view')
|
|
|
|
if (view) {
|
|
|
|
// make sure the selected view is valid
|
|
|
|
if (document.querySelector(`[data-ol-view-tab="${view}"]`)) {
|
|
|
|
selectView(view)
|
|
|
|
// clear the hash so it doesn't persist when switching plans
|
|
|
|
window.location.hash = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-10 10:57:41 -05:00
|
|
|
function validatePreRendering() {
|
|
|
|
document.querySelectorAll('[data-ol-view-tab]').forEach(el => {
|
|
|
|
console.assert(
|
|
|
|
(el.getAttribute('data-ol-view-tab') === currentView) ===
|
|
|
|
el.classList.contains('active'),
|
|
|
|
el
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
document.querySelectorAll('[data-ol-view]').forEach(el => {
|
|
|
|
console.assert(
|
|
|
|
(el.hidden === el.getAttribute('data-ol-view')) !== currentView,
|
|
|
|
el
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
const plansPageLayoutV3Variant = getMeta('ol-splitTestVariants')?.[
|
|
|
|
'plans-page-layout-v3'
|
|
|
|
]
|
|
|
|
if (plansPageLayoutV3Variant !== 'new-plans-page') {
|
|
|
|
const tooltipEl = document.querySelector('[data-ol-annual-saving-tooltip]')
|
|
|
|
console.assert(
|
|
|
|
(currentView === 'annual') ===
|
|
|
|
tooltipEl.classList.contains('annual-selected'),
|
|
|
|
tooltipEl
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('validated pre-rendering')
|
|
|
|
}
|
|
|
|
|
2021-09-22 07:13:18 -04:00
|
|
|
document.querySelectorAll('[data-ol-view-tab]').forEach(setUpViewSwitching)
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-currencyCode-switch]')
|
|
|
|
.forEach(setUpCurrencySwitching)
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-start-new-subscription]')
|
|
|
|
.forEach(setUpSubscriptionTracking)
|
|
|
|
updateLinkTargets()
|
2022-03-01 09:28:01 -05:00
|
|
|
|
|
|
|
selectViewFromHash()
|
|
|
|
window.addEventListener('hashchange', selectViewFromHash)
|