2022-05-12 07:38:02 -04:00
|
|
|
import '../../../../marketing'
|
|
|
|
|
2022-05-19 05:13:25 -04:00
|
|
|
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
2022-06-22 08:22:11 -04:00
|
|
|
import { setUpStickyHeaderObserver } from './plans-v2-sticky-header'
|
2022-05-12 07:38:02 -04:00
|
|
|
import {
|
|
|
|
setUpMonthlyAnnualSwitching,
|
2022-06-22 08:22:11 -04:00
|
|
|
switchMonthlyAnnual,
|
|
|
|
toggleMonthlyAnnualSwitching,
|
2022-05-12 07:38:02 -04:00
|
|
|
} from './plans-v2-m-a-switch'
|
|
|
|
import {
|
|
|
|
changeGroupPlanModalEducationalDiscount,
|
|
|
|
changeGroupPlanModalNumberOfLicenses,
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing,
|
2022-05-12 07:38:02 -04:00
|
|
|
} from './plans-v2-group-plan'
|
|
|
|
import { setUpGroupSubscriptionButtonAction } from './plans-v2-subscription-button'
|
2024-05-28 12:48:29 -04:00
|
|
|
import {
|
|
|
|
getViewInfoFromHash,
|
|
|
|
handleForStudentsLinkInFooter,
|
|
|
|
setHashFromViewTab,
|
|
|
|
} from './plans-v2-hash'
|
2023-04-25 08:33:04 -04:00
|
|
|
import getMeta from '../../../../utils/meta'
|
|
|
|
|
|
|
|
const currentCurrencyCode = getMeta('ol-recommendedCurrency')
|
|
|
|
|
2024-06-17 10:19:06 -04:00
|
|
|
function showQuoteForTab(viewTab) {
|
|
|
|
// hide/display quote rows
|
|
|
|
document.querySelectorAll('.plans-page-quote-row').forEach(quoteRow => {
|
|
|
|
const showForPlanTypes = quoteRow.getAttribute('data-ol-show-for-plan-type')
|
|
|
|
if (showForPlanTypes?.includes(viewTab)) {
|
|
|
|
quoteRow.classList.remove('plans-page-quote-row-hidden')
|
|
|
|
} else {
|
|
|
|
quoteRow.classList.add('plans-page-quote-row-hidden')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-25 08:33:04 -04:00
|
|
|
function setUpSubscriptionTracking(linkEl) {
|
|
|
|
linkEl.addEventListener('click', function () {
|
|
|
|
const plan =
|
|
|
|
linkEl.getAttribute('data-ol-tracking-plan') ||
|
|
|
|
linkEl.getAttribute('data-ol-start-new-subscription')
|
|
|
|
|
|
|
|
const location = linkEl.getAttribute('data-ol-location')
|
|
|
|
const period = linkEl.getAttribute('data-ol-item-view')
|
|
|
|
|
|
|
|
const DEFAULT_EVENT_TRACKING_KEY = 'plans-page-click'
|
|
|
|
|
|
|
|
const eventTrackingKey =
|
|
|
|
linkEl.getAttribute('data-ol-event-tracking-key') ||
|
|
|
|
DEFAULT_EVENT_TRACKING_KEY
|
|
|
|
|
|
|
|
const eventTrackingSegmentation = {
|
|
|
|
button: plan,
|
|
|
|
location,
|
|
|
|
'billing-period': period,
|
|
|
|
}
|
|
|
|
|
|
|
|
eventTracking.sendMB('plans-page-start-trial') // deprecated by plans-page-click
|
|
|
|
eventTracking.sendMB(eventTrackingKey, eventTrackingSegmentation)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const searchParams = new URLSearchParams(window.location.search)
|
|
|
|
|
|
|
|
export function updateLinkTargets() {
|
|
|
|
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')
|
2024-02-27 12:25:10 -05:00
|
|
|
|
|
|
|
const suffix = view === 'annual' ? '-annual' : '_free_trial_7_days'
|
2023-08-08 10:41:14 -04:00
|
|
|
|
2023-04-25 08:33:04 -04:00
|
|
|
const planCode = `${plan}${suffix}`
|
|
|
|
|
|
|
|
const location = el.getAttribute('data-ol-location')
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (searchParams.get('itm_referrer')) {
|
|
|
|
queryString.set('itm_referrer', searchParams.get('itm_referrer'))
|
|
|
|
}
|
|
|
|
|
|
|
|
el.href = `/user/subscription/new?${queryString.toString()}`
|
|
|
|
})
|
|
|
|
}
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
// We need this mutable variable because the group tab only have annual.
|
|
|
|
// There's some difference between the monthly and annual UI
|
|
|
|
// and since monthly-annual switch is disabled for the group tab,
|
|
|
|
// we need to introduce a new variable to store the information
|
2023-01-27 10:04:33 -05:00
|
|
|
let currentMonthlyAnnualSwitchValue = 'annual'
|
2022-06-22 08:22:11 -04:00
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
function selectTab(viewTab) {
|
|
|
|
document.querySelectorAll('[data-ol-plans-v2-view-tab]').forEach(el => {
|
2024-01-25 07:57:26 -05:00
|
|
|
const tab = el.querySelector('[data-ol-plans-v2-view-tab] button')
|
|
|
|
if (tab) {
|
|
|
|
const isActive =
|
|
|
|
tab.parentElement.getAttribute('data-ol-plans-v2-view-tab') === viewTab
|
|
|
|
tab.parentElement.classList.toggle('active', isActive)
|
|
|
|
tab.setAttribute('aria-selected', isActive)
|
|
|
|
}
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
document.querySelectorAll('[data-ol-plans-v2-view]').forEach(el => {
|
|
|
|
el.hidden = el.getAttribute('data-ol-plans-v2-view') !== viewTab
|
|
|
|
})
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
document.querySelector('[data-ol-plans-v2-m-a-tooltip]').hidden =
|
|
|
|
viewTab === 'group'
|
|
|
|
document.querySelector('[data-ol-plans-v2-license-picker-container]').hidden =
|
|
|
|
viewTab !== 'group'
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelector('[data-ol-plans-v2-m-a-switch-container]')
|
|
|
|
.setAttribute('data-ol-current-view', viewTab)
|
2022-05-12 07:38:02 -04:00
|
|
|
|
2024-03-28 10:55:45 -04:00
|
|
|
if (viewTab === 'group') {
|
|
|
|
updateMainGroupPlanPricing()
|
|
|
|
}
|
|
|
|
|
|
|
|
updateMonthlyAnnualSwitchValue(viewTab)
|
|
|
|
|
|
|
|
toggleUniversityInfo(viewTab)
|
2024-05-28 12:48:29 -04:00
|
|
|
|
|
|
|
// update the hash to reflect the current view when switching individual, group, or student tabs
|
|
|
|
setHashFromViewTab(viewTab, currentMonthlyAnnualSwitchValue)
|
2024-06-17 10:19:06 -04:00
|
|
|
|
|
|
|
showQuoteForTab(viewTab)
|
2024-03-28 10:55:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateMonthlyAnnualSwitchValue(viewTab) {
|
2022-05-12 07:38:02 -04:00
|
|
|
// group tab is special because group plan only has annual value
|
|
|
|
// so we need to perform some UI changes whenever user click the group tab
|
|
|
|
if (viewTab === 'group') {
|
2022-06-22 08:22:11 -04:00
|
|
|
toggleMonthlyAnnualSwitching(viewTab, 'annual')
|
2022-05-12 07:38:02 -04:00
|
|
|
} else {
|
2022-06-22 08:22:11 -04:00
|
|
|
toggleMonthlyAnnualSwitching(viewTab, currentMonthlyAnnualSwitchValue)
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUpTabSwitching() {
|
|
|
|
document.querySelectorAll('[data-ol-plans-v2-view-tab]').forEach(el => {
|
|
|
|
const viewTab = el.getAttribute('data-ol-plans-v2-view-tab')
|
|
|
|
|
2022-12-16 09:44:27 -05:00
|
|
|
el.querySelector('button').addEventListener('click', function (e) {
|
2022-05-12 07:38:02 -04:00
|
|
|
e.preventDefault()
|
2022-05-19 05:13:25 -04:00
|
|
|
eventTracking.send(
|
|
|
|
'subscription-funnel',
|
|
|
|
'plans-page',
|
|
|
|
`${viewTab}-prices`
|
|
|
|
)
|
2022-05-12 07:38:02 -04:00
|
|
|
selectTab(viewTab)
|
|
|
|
})
|
|
|
|
})
|
2024-01-25 07:57:26 -05:00
|
|
|
|
|
|
|
const tabs = document.querySelectorAll(
|
|
|
|
'[data-ol-plans-v2-view-tab] [role="tab"]'
|
|
|
|
)
|
|
|
|
|
|
|
|
if (tabs) {
|
|
|
|
tabs.forEach(tab => {
|
|
|
|
tab.addEventListener('keydown', event => {
|
|
|
|
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
|
|
|
|
const currentIndex = Array.from(tabs).indexOf(tab)
|
|
|
|
const nextIndex =
|
|
|
|
event.key === 'ArrowLeft' ? currentIndex - 1 : currentIndex + 1
|
|
|
|
const newIndex = (nextIndex + tabs.length) % tabs.length
|
|
|
|
tabs[newIndex].focus()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-05-12 07:38:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUpGroupPlanPricingChange() {
|
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-plans-v2-license-picker-select]')
|
|
|
|
.forEach(el => {
|
|
|
|
el.addEventListener('change', () => {
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing()
|
|
|
|
changeGroupPlanModalNumberOfLicenses()
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
document
|
|
|
|
.querySelectorAll(
|
|
|
|
'[data-ol-plans-v2-license-picker-educational-discount-input]'
|
|
|
|
)
|
|
|
|
.forEach(el =>
|
|
|
|
el.addEventListener('change', () => {
|
2022-05-19 07:57:36 -04:00
|
|
|
updateMainGroupPlanPricing()
|
|
|
|
changeGroupPlanModalEducationalDiscount()
|
2022-05-12 07:38:02 -04:00
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-12 05:58:24 -04:00
|
|
|
function toggleUniversityInfo(viewTab) {
|
|
|
|
const el = document.querySelector('[data-ol-plans-university-info-container]')
|
|
|
|
|
|
|
|
el.hidden = viewTab !== 'student'
|
|
|
|
}
|
|
|
|
|
2024-05-28 12:48:29 -04:00
|
|
|
// This is the old scheme for hashing redirection
|
|
|
|
// This is deprecated and should be removed in the future
|
|
|
|
// This is only used for backward compatibility
|
|
|
|
function selectViewFromHashDeprecated() {
|
2022-06-23 05:22:04 -04:00
|
|
|
try {
|
|
|
|
const params = new URLSearchParams(window.location.hash.substring(1))
|
|
|
|
const view = params.get('view')
|
|
|
|
if (view) {
|
2024-03-28 10:55:45 -04:00
|
|
|
// View params are expected to be of the format e.g. individual or individual-monthly
|
2024-05-28 12:48:29 -04:00
|
|
|
const [tab, period] = view.split('-')
|
2022-06-23 05:22:04 -04:00
|
|
|
// make sure the selected view is valid
|
2024-03-28 10:55:45 -04:00
|
|
|
if (document.querySelector(`[data-ol-plans-v2-view-tab="${tab}"]`)) {
|
|
|
|
selectTab(tab)
|
|
|
|
|
2024-05-28 12:48:29 -04:00
|
|
|
if (['monthly', 'annual'].includes(period)) {
|
|
|
|
currentMonthlyAnnualSwitchValue = period
|
2024-03-28 10:55:45 -04:00
|
|
|
} else {
|
|
|
|
// set annual as the default
|
|
|
|
currentMonthlyAnnualSwitchValue = 'annual'
|
|
|
|
}
|
|
|
|
|
|
|
|
updateMonthlyAnnualSwitchValue(tab)
|
2023-06-06 12:43:43 -04:00
|
|
|
|
2024-05-28 12:48:29 -04:00
|
|
|
// change the hash with the new scheme
|
|
|
|
setHashFromViewTab(tab, currentMonthlyAnnualSwitchValue)
|
2022-06-23 05:22:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-28 12:48:29 -04:00
|
|
|
function selectViewAndPeriodFromHash() {
|
|
|
|
const [viewTab, period] = getViewInfoFromHash()
|
|
|
|
|
|
|
|
// the sequence of these three lines is important
|
|
|
|
// because `currentMonthlyAnnualSwitchValue` is mutable.
|
|
|
|
// `selectTab` and `updateMonthlyAnnualSwitchValue` depend on the value of `currentMonthlyAnnualSwitchValue`
|
|
|
|
// to determine the UI state
|
|
|
|
currentMonthlyAnnualSwitchValue = period
|
|
|
|
selectTab(viewTab)
|
|
|
|
updateMonthlyAnnualSwitchValue(viewTab)
|
|
|
|
|
|
|
|
// handle the case where user access plans page while still on the plans page
|
|
|
|
// current example would the the "For students" link on the footer
|
|
|
|
const SCROLL_TO_TOP_DELAY = 50
|
|
|
|
window.setTimeout(() => {
|
|
|
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
|
|
|
}, SCROLL_TO_TOP_DELAY)
|
|
|
|
}
|
|
|
|
|
|
|
|
// call the function to select the view and period from the hash value
|
|
|
|
// this is called once when the page is loaded
|
|
|
|
if (window.location.hash) {
|
|
|
|
if (window.location.hash.includes('view')) {
|
|
|
|
selectViewFromHashDeprecated()
|
|
|
|
} else {
|
|
|
|
selectViewAndPeriodFromHash()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-22 08:22:11 -04:00
|
|
|
document
|
|
|
|
.querySelector('[data-ol-plans-v2-m-a-switch]')
|
|
|
|
.addEventListener('click', () => {
|
2023-01-27 10:04:33 -05:00
|
|
|
const isMonthlyPricing = document.querySelector(
|
2022-06-22 08:22:11 -04:00
|
|
|
'[data-ol-plans-v2-m-a-switch] input[type="checkbox"]'
|
|
|
|
).checked
|
|
|
|
|
2023-01-27 10:04:33 -05:00
|
|
|
if (isMonthlyPricing) {
|
2022-06-22 08:22:11 -04:00
|
|
|
currentMonthlyAnnualSwitchValue = 'monthly'
|
2023-01-27 10:04:33 -05:00
|
|
|
} else {
|
|
|
|
currentMonthlyAnnualSwitchValue = 'annual'
|
2022-06-22 08:22:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switchMonthlyAnnual(currentMonthlyAnnualSwitchValue)
|
2024-05-28 12:48:29 -04:00
|
|
|
|
|
|
|
// update the hash to reflect the current view when pressing the monthly-annual switch
|
|
|
|
const DEFAULT_VIEW_TAB = 'individual'
|
|
|
|
const viewTab =
|
|
|
|
document
|
|
|
|
.querySelector('[data-ol-plans-v2-m-a-switch-container]')
|
|
|
|
.getAttribute('data-ol-current-view') ?? DEFAULT_VIEW_TAB
|
|
|
|
|
|
|
|
setHashFromViewTab(viewTab, currentMonthlyAnnualSwitchValue)
|
2022-06-22 08:22:11 -04:00
|
|
|
})
|
|
|
|
|
2023-04-25 08:33:04 -04:00
|
|
|
document
|
|
|
|
.querySelectorAll('[data-ol-start-new-subscription]')
|
|
|
|
.forEach(setUpSubscriptionTracking)
|
|
|
|
|
2022-05-12 07:38:02 -04:00
|
|
|
setUpTabSwitching()
|
|
|
|
setUpGroupPlanPricingChange()
|
|
|
|
setUpMonthlyAnnualSwitching()
|
|
|
|
setUpGroupSubscriptionButtonAction()
|
|
|
|
setUpStickyHeaderObserver()
|
|
|
|
updateLinkTargets()
|
2024-05-28 12:48:29 -04:00
|
|
|
handleForStudentsLinkInFooter()
|
2022-06-23 05:22:04 -04:00
|
|
|
|
2024-05-28 12:48:29 -04:00
|
|
|
window.addEventListener('hashchange', () => {
|
|
|
|
if (window.location.hash) {
|
|
|
|
if (window.location.hash.includes('view')) {
|
|
|
|
selectViewFromHashDeprecated()
|
|
|
|
} else {
|
|
|
|
selectViewAndPeriodFromHash()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|