Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

[CRO] NikitK/CRO-380/tracking issues for partners signup #6363

Merged
3 changes: 1 addition & 2 deletions crowdin/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4256,8 +4256,7 @@
"-1049534775": "Please enter a valid postcode with Latin characters.",
"-420140433": "Company registration number is required",
"-1857429287": "Last Name",
"-706927392": "Important Guidelines",
"-2086585870": "Partners Guide",
"-1702877392": "Important guidelines",
"-776458472": "General terms of use",
"-2083825503": "Affiliates & introducing brokers (IBs)",
"-28284335": "Additional terms for our affiliates and introducing brokers",
Expand Down
4 changes: 3 additions & 1 deletion src/pages/signup-affiliates/components/_signup-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components'
import affiliate_validation from '../validations/_affilaite_validation'
import AffiliateInput from '../utils/_affiliate-input'
import { SignUpFormProps } from '../_types'
import { trackEvent } from '../utils/_utils'
import { localize, Localize } from 'components/localization'
import { Container } from 'components/containers'
import { Button } from 'components/form'
Expand Down Expand Up @@ -88,6 +89,7 @@ export const SignUpWrapper = styled(Container)`
padding: 0;
}
`
const email = localize('_t_Email_t_')
let language = getLanguage()
language = language !== 'en' ? '/' + language : ''

Expand All @@ -97,7 +99,6 @@ const AffiliateSignupForm = ({
setShowWizard,
}: SignUpFormProps) => {
const [email_error_msg, setEmailErrorMsg] = useState('')
const email = localize('_t_Email_t_')

const handleStateChange = useCallback(
({ e, field }: { e?: React.ChangeEvent<HTMLInputElement>; field: string }) => {
Expand Down Expand Up @@ -172,6 +173,7 @@ const AffiliateSignupForm = ({
secondary
onClick={() => {
window.scrollTo(0, 0)
trackEvent({ action: 'open_wizard', email: affiliate_account.email })
setShowWizard(true)
}}
disabled={!(affiliate_account.email && !email_error_msg)}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/signup-affiliates/components/_signup-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'
import affiliate_validation from '../validations/_affilaite_validation'
import AffiliateInput from '../utils/_affiliate-input'
import { SignUpStatusProps } from '../_types'
import trackEvent from '../utils/_tracking'
import { trackEvent } from '../utils/_utils'
import Image from 'features/components/atoms/image'
import { localize, Localize } from 'components/localization'
import { useIsRtl } from 'components/hooks/use-isrtl'
Expand Down Expand Up @@ -140,7 +140,6 @@ const AffiliateSignupStatus = ({
}, [])

const handleTryAgain = useCallback(() => {
trackEvent({ action: 'try_submit' })
setSignupStatus('loading')
onSubmit()
}, [signup_status])
Expand Down
6 changes: 0 additions & 6 deletions src/pages/signup-affiliates/components/_wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
AccountType,
} from '../_lazy-loading'
import { AffiliateAccountTypes, WizardProps } from '../_types'
import trackEvent from '../utils/_tracking'
import WizardComponent from './wizard-component'
import { useResidenceList } from 'features/hooks/use-residence-list'

Expand All @@ -26,11 +25,6 @@ const Wizard = ({

const is_individual = affiliate_account?.account_type == 1

useEffect(() => {
show_wizard && trackEvent({ action: 'open_wizard' })
return () => trackEvent({ action: 'close_wizard' })
}, [show_wizard])

useEffect(() => {
if (is_individual) {
setAffiliateAccount((prev) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'
import Button from 'components/form/button'
import { Localize } from 'components/localization'
import { WizardComponentTypes } from 'pages/signup-affiliates/_types'
import trackEvent from 'pages/signup-affiliates/utils/_tracking'
import { trackEvent } from 'pages/signup-affiliates/utils/_utils'
import device from 'themes/device'

const StyledFooter = styled.div`
Expand Down Expand Up @@ -64,15 +64,15 @@ const WizardFooter = ({
step_num: step,
step_codename: getCodeName(step),
})
step > 1 && setStep(step - 1)
step > 1 && setStep((prev) => prev - 1)
}
if (button_type === ButtonType.Next) {
trackEvent({
action: 'step_passed',
step_num: step,
step_codename: getCodeName(step),
})
step < max_step && setStep(step + 1)
step < max_step && setStep((prev) => prev + 1)
}
},
[max_step, setStep, step],
Expand Down
36 changes: 22 additions & 14 deletions src/pages/signup-affiliates/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import trackEvent from './utils/_tracking'
import { Submit } from './utils/_utils'
import { Submit, trackEvent } from './utils/_utils'
import { AffiliateAccountTypes, SignUpStatusTypes } from './_types'
import { AffiliateSignupForm, AffiliateSignupStatus, Wizard } from './_lazy-loading'
import { isBrowser } from 'common/utility'
Expand All @@ -25,6 +24,10 @@ const ParentWrapper = styled.div`
background-image: url(${Map});
background-repeat: no-repeat;
background-position: bottom;

@media ${device.tabletL} {
background-image: unset;
}
`
const StyledContainer = styled(Container)`
display: flex;
Expand Down Expand Up @@ -86,7 +89,13 @@ const AffiliateSignup = () => {

useEffect(() => {
trackEvent({ action: 'open' })
return () => trackEvent({ action: 'close' })
const handleBeforeUnload = (event) => {
event.preventDefault()
trackEvent({ action: 'close' })
trackEvent({ action: 'close_wizard' })
}
window.addEventListener('beforeunload', handleBeforeUnload)
return () => window.removeEventListener('beforeunload', handleBeforeUnload)
}, [])

useEffect(() => {
Expand All @@ -104,8 +113,15 @@ const AffiliateSignup = () => {

useEffect(() => {
const partner_signup_error_message = affiliate_api_error?.error.message

if (partner_signup_error_message == 'Username not available') {
if (affiliate_api_data) {
trackEvent({
action: 'success_popup_opened',
user_choice:
JSON.stringify(affiliate_api_error?.echo_req) ||
'success, but without echo_req',
})
setSignupStatus('success')
} else if (partner_signup_error_message == 'Username not available') {
trackEvent({ action: 'partners_signup_error', partner_signup_error_message })
setSignupStatus(partner_signup_error_message)
} else if (
Expand All @@ -117,15 +133,7 @@ const AffiliateSignup = () => {
setSignupStatus('Your website is not a valid entry')
} else if (partner_signup_error_message)
trackEvent({ action: 'other_error', partner_signup_error_message })

if (affiliate_api_data) {
trackEvent({
action: 'success_popup_opened',
user_choice: JSON.stringify(affiliate_api_error?.echo_req),
})
setSignupStatus('success')
}
}, [affiliate_api_data, affiliate_api_error, affiliateSend])
}, [affiliate_api_data, affiliate_api_error])

useEffect(() => {
setAffiliateAccount({
Expand Down
19 changes: 0 additions & 19 deletions src/pages/signup-affiliates/utils/_tracking.ts

This file was deleted.

21 changes: 20 additions & 1 deletion src/pages/signup-affiliates/utils/_utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Analytics } from '@deriv/analytics'
import { Analytics, TEvents } from '@deriv/analytics'
import { SubmitTypes } from '../_types'

export const customSlugify = (text: string): string => {
Expand Down Expand Up @@ -69,3 +69,22 @@ export const Submit = ({
}),
})
}

export const trackEvent = ({
action,
email,
partner_signup_error_message,
NikitK-deriv marked this conversation as resolved.
Show resolved Hide resolved
user_choice,
step_num,
step_codename,
}: TEvents['ce_partner_account_signup_form']) => {
Analytics?.trackEvent('ce_partner_account_signup_form', {
action,
form_name: 'ce_partner_account_signup_form',
...(email && { email }),
...(user_choice && { user_choice }),
...(step_num && { step_num }),
...(step_codename && { step_codename }),
...(partner_signup_error_message && { partner_signup_error_message }),
})
}
Loading