start-free-trial-button.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useCallback, useEffect } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { Button } from 'react-bootstrap'
  4. import PropTypes from 'prop-types'
  5. import { useSplitTestContext } from '../context/split-test-context'
  6. import * as eventTracking from '../../infrastructure/event-tracking'
  7. export default function StartFreeTrialButton({
  8. buttonStyle = 'info',
  9. children,
  10. classes = {},
  11. setStartedFreeTrial,
  12. source,
  13. }) {
  14. const { t } = useTranslation()
  15. const { splitTestVariants } = useSplitTestContext({
  16. splitTestVariants: PropTypes.object,
  17. })
  18. const interstitialPaymentFromPaywallVariant =
  19. splitTestVariants['interstitial-payment-from-paywall']
  20. useEffect(() => {
  21. eventTracking.sendMB('paywall-prompt', { 'paywall-type': source })
  22. }, [source])
  23. const handleClick = useCallback(
  24. event => {
  25. event.preventDefault()
  26. eventTracking.send('subscription-funnel', 'upgraded-free-trial', source)
  27. eventTracking.sendMB('paywall-click', { 'paywall-type': source })
  28. if (setStartedFreeTrial) {
  29. setStartedFreeTrial(true)
  30. }
  31. const params = new URLSearchParams({
  32. planCode: 'collaborator_free_trial_7_days',
  33. ssp: 'true',
  34. itm_campaign: source,
  35. })
  36. if (interstitialPaymentFromPaywallVariant === 'active') {
  37. window.open(
  38. `/user/subscription/choose-your-plan?itm_campaign=${source}`
  39. )
  40. } else {
  41. window.open(`/user/subscription/new?${params}`)
  42. }
  43. },
  44. [setStartedFreeTrial, source, interstitialPaymentFromPaywallVariant]
  45. )
  46. return (
  47. <Button
  48. bsStyle={buttonStyle}
  49. onClick={handleClick}
  50. className={classes.button}
  51. >
  52. {children || t('start_free_trial')}
  53. </Button>
  54. )
  55. }
  56. StartFreeTrialButton.propTypes = {
  57. buttonStyle: PropTypes.string,
  58. children: PropTypes.any,
  59. classes: PropTypes.shape({
  60. button: PropTypes.string.isRequired,
  61. }),
  62. setStartedFreeTrial: PropTypes.func,
  63. source: PropTypes.string.isRequired,
  64. }