2021-06-23 05:37:08 -04:00
|
|
|
import { useCallback, useEffect } from 'react'
|
2021-04-30 16:20:16 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { Button } from 'react-bootstrap'
|
|
|
|
import PropTypes from 'prop-types'
|
2022-06-28 09:36:13 -04:00
|
|
|
import { useSplitTestContext } from '../context/split-test-context'
|
2021-04-30 16:20:16 -04:00
|
|
|
import * as eventTracking from '../../infrastructure/event-tracking'
|
|
|
|
|
|
|
|
export default function StartFreeTrialButton({
|
|
|
|
buttonStyle = 'info',
|
|
|
|
children,
|
|
|
|
classes = {},
|
|
|
|
setStartedFreeTrial,
|
|
|
|
source,
|
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2022-06-28 09:36:13 -04:00
|
|
|
const { splitTestVariants } = useSplitTestContext({
|
|
|
|
splitTestVariants: PropTypes.object,
|
|
|
|
})
|
|
|
|
const interstitialPaymentFromPaywallVariant =
|
|
|
|
splitTestVariants['interstitial-payment-from-paywall']
|
|
|
|
|
2021-06-10 04:04:21 -04:00
|
|
|
useEffect(() => {
|
2021-09-16 04:47:37 -04:00
|
|
|
eventTracking.sendMB('paywall-prompt', { 'paywall-type': source })
|
2021-06-10 04:04:21 -04:00
|
|
|
}, [source])
|
|
|
|
|
2021-04-30 16:20:16 -04:00
|
|
|
const handleClick = useCallback(
|
|
|
|
event => {
|
|
|
|
event.preventDefault()
|
|
|
|
|
|
|
|
eventTracking.send('subscription-funnel', 'upgraded-free-trial', source)
|
2021-09-16 04:47:37 -04:00
|
|
|
eventTracking.sendMB('paywall-click', { 'paywall-type': source })
|
2021-04-30 16:20:16 -04:00
|
|
|
|
|
|
|
if (setStartedFreeTrial) {
|
|
|
|
setStartedFreeTrial(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = new URLSearchParams({
|
2021-06-10 04:04:21 -04:00
|
|
|
planCode: 'collaborator_free_trial_7_days',
|
2021-04-30 16:20:16 -04:00
|
|
|
ssp: 'true',
|
|
|
|
itm_campaign: source,
|
|
|
|
})
|
|
|
|
|
2022-06-28 09:36:13 -04:00
|
|
|
if (interstitialPaymentFromPaywallVariant === 'active') {
|
|
|
|
window.open(
|
|
|
|
`/user/subscription/choose-your-plan?itm_campaign=${source}`
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
window.open(`/user/subscription/new?${params}`)
|
|
|
|
}
|
2021-04-30 16:20:16 -04:00
|
|
|
},
|
2022-06-28 09:36:13 -04:00
|
|
|
[setStartedFreeTrial, source, interstitialPaymentFromPaywallVariant]
|
2021-04-30 16:20:16 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
bsStyle={buttonStyle}
|
|
|
|
onClick={handleClick}
|
|
|
|
className={classes.button}
|
|
|
|
>
|
|
|
|
{children || t('start_free_trial')}
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
StartFreeTrialButton.propTypes = {
|
|
|
|
buttonStyle: PropTypes.string,
|
|
|
|
children: PropTypes.any,
|
|
|
|
classes: PropTypes.shape({
|
|
|
|
button: PropTypes.string.isRequired,
|
|
|
|
}),
|
|
|
|
setStartedFreeTrial: PropTypes.func,
|
|
|
|
source: PropTypes.string.isRequired,
|
|
|
|
}
|