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

refactor: a/b testing feature doesnt track user events #5679

Merged
merged 60 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0a19ef2
refactor: a/b testing feature doesnt track user events
NikitK-deriv Sep 25, 2023
4cc8bcf
fix: remove prod key from staging and beta to prevent data mix
NikitK-deriv Sep 25, 2023
28573ab
fix: resolve build issue
NikitK-deriv Sep 25, 2023
ed3dc63
refactor: ecrypted connection, add attributes
NikitK-deriv Sep 28, 2023
daa884f
fix: tracking foundation
NikitK-deriv Oct 2, 2023
1193b63
fix: vercel issue
NikitK-deriv Oct 2, 2023
454e207
feat: add ecnryption key in yml files
NikitK-deriv Oct 2, 2023
8702487
fix: vercel issue
NikitK-deriv Oct 3, 2023
877b85e
fix: vercel issue
NikitK-deriv Oct 3, 2023
3948984
fix: vercel issue
NikitK-deriv Oct 3, 2023
ed66f0d
fix: vercel issue
NikitK-deriv Oct 3, 2023
0116626
fix: vercel issue
NikitK-deriv Oct 3, 2023
6ffbc2a
chore: trigger vercel
NikitK-deriv Oct 3, 2023
3524a1b
chore: cleanup
NikitK-deriv Oct 3, 2023
0cb14b8
fix: mode
NikitK-deriv Oct 3, 2023
055d3d7
chore: rudder init before growthbook usage
NikitK-deriv Oct 3, 2023
f16b5a6
fix: vercel issue
NikitK-deriv Oct 3, 2023
a301b81
refactor: move growthbook from ssr to hook
NikitK-deriv Oct 3, 2023
c18c923
fix: vercel issue
NikitK-deriv Oct 3, 2023
9dde5c1
fix: vercel issue
NikitK-deriv Oct 3, 2023
9e32fbf
fix: vercel issue
NikitK-deriv Oct 3, 2023
977a40f
chore: cleanup
NikitK-deriv Oct 3, 2023
f3f4c21
feat: add dynamic devMode
NikitK-deriv Oct 4, 2023
da88508
chore: comment function with feature log
NikitK-deriv Oct 4, 2023
b516d07
chore: merge with latest master
NikitK-deriv Oct 5, 2023
eebadf6
feat: add growthbbok in package for example
NikitK-deriv Oct 9, 2023
4121968
refactor: new approach of analytic usage
NikitK-deriv Oct 10, 2023
77d8b8f
refactor: make possible to register severl events
NikitK-deriv Oct 10, 2023
e49f2cb
refactor: add form_name and make growthbbok callback test
NikitK-deriv Oct 10, 2023
b58181c
chore: experimtent_view issue
NikitK-deriv Oct 10, 2023
b7e046c
chore: vercel issue
NikitK-deriv Oct 10, 2023
59f94c6
refactor: update instance
NikitK-deriv Oct 10, 2023
959d28d
refactor: functions
NikitK-deriv Oct 10, 2023
65a56d0
chore: resolve vercel issue
NikitK-deriv Oct 10, 2023
ec26106
chore: cleanup
NikitK-deriv Oct 10, 2023
beb39a7
refactor: final
NikitK-deriv Oct 10, 2023
cd28e39
chore: cleanup keys
NikitK-deriv Oct 10, 2023
d1de6bb
chore: test
NikitK-deriv Oct 10, 2023
e0d6775
refactor: remove register approach
NikitK-deriv Oct 11, 2023
22ecaa3
chore: merge with latest master
NikitK-deriv Oct 11, 2023
23bea7b
chore: remove consoles
NikitK-deriv Oct 11, 2023
494f431
refactor: has_ident set approach, setUrl in instance, defValue for fn
NikitK-deriv Oct 12, 2023
762cbf8
fix: setUrl issue
NikitK-deriv Oct 12, 2023
7304e74
fix: setUrl issue
NikitK-deriv Oct 12, 2023
31763d0
refactor: add analytics as external package
NikitK-deriv Oct 16, 2023
470e439
feat: update version of package
NikitK-deriv Oct 19, 2023
75fa49f
chore: resolve merge conflicts
NikitK-deriv Oct 19, 2023
df55c94
fix: generate test link issue with parcel
NikitK-deriv Oct 19, 2023
bce973d
chore: update yml files
NikitK-deriv Oct 19, 2023
b630a15
refactor: change mode boolean
NikitK-deriv Oct 19, 2023
fa4354c
chore: check how condition works
NikitK-deriv Oct 20, 2023
66aef57
chore: gatsby browser
NikitK-deriv Oct 20, 2023
338ce1c
chore: replace yml mistake and update dependencies
NikitK-deriv Oct 23, 2023
c0d8c04
chore: merge with latest master
NikitK-deriv Oct 23, 2023
630f907
feat: update package version and resolve cookie issue
NikitK-deriv Oct 23, 2023
7184a1a
chore: debug
NikitK-deriv Oct 24, 2023
e512b09
chore: debug
NikitK-deriv Oct 24, 2023
fafff76
fix: resolved and cleanup
NikitK-deriv Oct 24, 2023
4fa4f0d
fix: user_id undefined
NikitK-deriv Oct 24, 2023
e21936b
refactor: add identifyEvent separately
NikitK-deriv Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ env:
GATSBY_DATADOG_CLIENT_TOKEN: ${{ secrets.GATSBY_DATADOG_CLIENT_TOKEN }}
GATSBY_MAP_API_KEY: ${{ secrets.GATSBY_MAP_API_KEY }}
GATSBY_GROWTHBOOK_CLIENT_KEY: ${{ secrets.GATSBY_GROWTHBOOK_CLIENT_KEY }}
GATSBY_GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GATSBY_GROWTHBOOK_DECRYPTION_KEY }}
GATSBY_RUDDERSTACK_STAGING_KEY: ${{ secrets.GATSBY_RUDDERSTACK_STAGING_KEY }}
GATSBY_RUDDERSTACK_PRODUCTION_KEY: ${{ secrets.GATSBY_RUDDERSTACK_PRODUCTION_KEY }}
GATSBY_RUDDERSTACK_URL: ${{ secrets.GATSBY_RUDDERSTACK_URL }}

jobs:
release-beta:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ env:
GATSBY_DATADOG_CLIENT_TOKEN: ${{ secrets.GATSBY_DATADOG_CLIENT_TOKEN }}
GATSBY_MAP_API_KEY: ${{ secrets.GATSBY_MAP_API_KEY }}
GATSBY_GROWTHBOOK_CLIENT_KEY: ${{ secrets.GATSBY_GROWTHBOOK_CLIENT_KEY }}
GATSBY_GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GATSBY_GROWTHBOOK_DECRYPTION_KEY }}
GATSBY_RUDDERSTACK_STAGING_KEY: ${{ secrets.GATSBY_RUDDERSTACK_STAGING_KEY }}
GATSBY_RUDDERSTACK_PRODUCTION_KEY: ${{ secrets.GATSBY_RUDDERSTACK_PRODUCTION_KEY }}
GATSBY_RUDDERSTACK_URL: ${{ secrets.GATSBY_RUDDERSTACK_URL }}

jobs:
release-production:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ env:
GATSBY_DATADOG_CLIENT_TOKEN: ${{ secrets.GATSBY_DATADOG_CLIENT_TOKEN }}
GATSBY_MAP_API_KEY: ${{ secrets.GATSBY_MAP_API_KEY }}
GATSBY_GROWTHBOOK_CLIENT_KEY: ${{ secrets.GATSBY_GROWTHBOOK_CLIENT_KEY }}
GATSBY_GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GATSBY_GROWTHBOOK_DECRYPTION_KEY }}
GATSBY_RUDDERSTACK_STAGING_KEY: ${{ secrets.GATSBY_RUDDERSTACK_STAGING_KEY }}
GATSBY_RUDDERSTACK_PRODUCTION_KEY: ${{ secrets.GATSBY_RUDDERSTACK_PRODUCTION_KEY }}
GATSBY_RUDDERSTACK_URL: ${{ secrets.GATSBY_RUDDERSTACK_URL }}
GATSBY_STRAPI_TOKEN: ${{ secrets.GATSBY_STRAPI_TOKEN }}

jobs:
Expand Down
24 changes: 24 additions & 0 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react'
import { createRoot } from 'react-dom/client'
import Cookies from 'js-cookie'
import { isMobile } from 'react-device-detect'
import { Analytics } from '@deriv/analytics'
import { WrapPagesWithLocaleContext } from './src/components/localization'
import { isProduction } from './src/common/websocket/config'
import { LocalStore } from './src/common/storage'
Expand Down Expand Up @@ -77,6 +80,25 @@ export const onInitialClientRender = () => {
}

export const onClientEntry = () => {
// @deriv/analytics
Analytics?.initialise({
growthbookKey: process.env.GATSBY_GROWTHBOOK_CLIENT_KEY,
growthbookDecryptionKey: process.env.GATSBY_GROWTHBOOK_DECRYPTION_KEY,
enableDevMode: window?.location.hostname.includes('localhost'),
rudderstackKey: ['.pages.dev', 'git-fork', 'localhost'].some((condition) =>
window.location.hostname.includes(condition),
)
? process.env.GATSBY_RUDDERSTACK_STAGING_KEY
: process.env.GATSBY_RUDDERSTACK_PRODUCTION_KEY,
})
Analytics?.setAttributes({
country: Cookies.get('clients_country') || Cookies.getJSON('website_status'),
user_language: Cookies.get('user_language') || getLanguage(),
device_language: navigator?.language || ' ',
device_type: isMobile ? 'mobile' : 'desktop',
})
const { tracking } = Analytics.getInstances()
tracking.identifyEvent(Analytics?.getId(), { language: getLanguage() })
//datadog
const dd_options = {
clientToken: process.env.GATSBY_DATADOG_CLIENT_TOKEN,
Expand Down Expand Up @@ -118,6 +140,8 @@ export const onClientEntry = () => {

export const onRouteUpdate = () => {
checkDomain()
// can't be resolved by package function due the gatsby architecture
window?._growthbook?.GrowthBook?.setURL(window.location.href)

const dataLayer = window.dataLayer
const domain = getDomain()
Expand Down
2,110 changes: 1,048 additions & 1,062 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"author": "Deriv",
"dependencies": {
"@artsy/fresnel": "^6.1.0",
"@deriv/analytics": "^1.2.1",
"@deriv/analytics": "^1.3.4",
"@deriv/deriv-api": "^1.0.11",
"@growthbook/growthbook-react": "^0.18.0",
"@hookform/resolvers": "^3.0.1",
"@livechat/customer-sdk": "^3.1.0",
"@loadable/component": "^5.15.2",
Expand Down
2 changes: 0 additions & 2 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const MAP_API_KEY = process.env.GATSBY_MAP_API_KEY
const GATSBY_GROWTHBOOK_CLIENT_KEY = process.env.GATSBY_GROWTHBOOK_CLIENT_KEY
const isBrowser = () => typeof window !== 'undefined'

export const deriv_com_url = 'deriv.com'
Expand Down Expand Up @@ -132,7 +131,6 @@ export const ctrader_app_store_url =

export const ctrader_web_browser_url = 'ct.deriv.com'
export const ctrader_windows_url = 'https://getctrader.com/deriv/ctrader-deriv-setup.exe'
export const growthbook_client_key = GATSBY_GROWTHBOOK_CLIENT_KEY
export const gtm_test_domain = 'deriv-com.binary.sx'
export const map_api_key = MAP_API_KEY
export const mga_link_url =
Expand Down
10 changes: 0 additions & 10 deletions src/features/hooks/analytic/use-analytic-data/index.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/features/hooks/analytic/use-analytic-events/index.ts

This file was deleted.

47 changes: 0 additions & 47 deletions src/features/hooks/analytic/use-growthbook/index.ts

This file was deleted.

14 changes: 10 additions & 4 deletions src/features/hooks/use-signup-form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as yup from 'yup'
import Cookies from 'js-cookie'
import { Analytics } from '@deriv/analytics'
import { yupResolver } from '@hookform/resolvers/yup'
import { useForm } from 'react-hook-form'
import { navigate } from 'gatsby'
import { useAnalyticsEvents } from 'features/hooks/analytic/use-analytic-events'
import { getCookiesFields, getCookiesObject, getDataObjFromCookies } from 'common/cookies'
import { validation_regex } from 'common/validation'
import apiManager from 'common/websocket'
Expand Down Expand Up @@ -42,14 +42,17 @@ const schema = yup.object({
type FormData = yup.InferType<typeof schema>

const useSignupForm = () => {
const { onAnalyticEvent } = useAnalyticsEvents('ce_virtual_signup_form')
const analyticsData: Parameters<typeof Analytics.trackEvent>[1] = {
form_source: isBrowser() && window.location.hostname,
form_name: 'default_diel_deriv',
}
const signUpForm = useForm<FormData>({
mode: 'onChange',
resolver: yupResolver(schema),
})

const onSignup = ({ email }: FormData) => {
onAnalyticEvent('started')
Analytics?.trackEvent('ce_virtual_signup_form', { action: 'started', ...analyticsData })

const formatted_email = getVerifyEmailRequest(email)
apiManager
Expand All @@ -67,7 +70,10 @@ const useSignupForm = () => {
navigate(success_link, { replace: true })
})
.catch((reason) => {
onAnalyticEvent('signup_flow_error')
Analytics?.trackEvent('ce_virtual_signup_form', {
action: 'signup_flow_error',
...analyticsData,
})
signUpForm.setError('email', {
message: reason.error.code,
})
Expand Down
12 changes: 6 additions & 6 deletions src/features/pages/home/hero/content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import loadable from '@loadable/component'
import pMinDelay from 'p-min-delay'
import { Analytics } from '@deriv/analytics'
import HeroCtaButton from './hero-cta.button'
import { hero_content_title, hero_typewriter } from './hero-content.module.scss'
import HeroHeaderItems from './hero-header.items'
import Flex from 'features/components/atoms/flex-box'
import Typography from 'features/components/atoms/typography'
import { useGrowthBook } from 'features/hooks/analytic/use-growthbook'
import { get_lang_direction, Localize } from 'components/localization'

const HeroFeaturesCarousel = loadable(() => pMinDelay(import('./hero-features.carousel'), 3000), {
Expand All @@ -20,14 +20,14 @@ const HeroFeaturesCarousel = loadable(() => pMinDelay(import('./hero-features.ca
})

const HomeHeroContent = () => {
const { homepage } = useGrowthBook()
const test_toggle_aa_test = Analytics?.getFeatureState('test-toggle-aa-test')
const common_test = Analytics?.getFeatureValue('test-toggle-aa-test', 'fallback')

const headings = {
control: '_t_Get the widest range of markets, trades and platforms_t_',
'new-title': '_t_Get the widest range of markets, trades and platforms_t_',
Control: '_t_Get the widest range of markets, trades and platforms_t_',
'Variation 1': '_t_Get the widest range of markets, trades and platforms_t_',
}

const heading = headings[homepage] || headings.control
const heading = headings[test_toggle_aa_test || 'Control']

return (
<Flex.Box justify="start" direction="col" align="start" gap="4x" dir={get_lang_direction()}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
import React from 'react'
import { Analytics } from '@deriv/analytics'
import { signup_apple_btn, signup_fb_btn, signup_login_redirect } from '../signup.module.scss'
import Login from 'common/login'
import Button from 'features/components/atoms/button'
import Flex from 'features/components/atoms/flex-box'
import Image from 'features/components/atoms/image'
import Typography from 'features/components/atoms/typography'
import { useAnalyticsEvents } from 'features/hooks/analytic/use-analytic-events'
import AppleLogo from 'images/svg/signup_apple_icon.svg'
import FacebookLogo from 'images/svg/signup_fb_icon.svg'
import GoogleLogo from 'images/svg/google_logo.svg'
import { Localize } from 'components/localization'
import { isBrowser } from 'common/utility'

const FormSocialButtons = () => {
const { onAnalyticEvent } = useAnalyticsEvents('ce_virtual_signup_form')
const analyticsData: Parameters<typeof Analytics.trackEvent>[1] = {
action: 'started',
form_source: isBrowser() && window.location.hostname,
form_name: 'default_diel_deriv',
}

return (
<>
<Button.Secondary
outlined
id="dm-signup-google"
onClick={() => {
onAnalyticEvent('google')
Analytics?.trackEvent('ce_virtual_signup_form', {
signup_provider: 'google',
...analyticsData,
})
Login.initOneAll('google')
}}
>
Expand All @@ -35,7 +43,10 @@ const FormSocialButtons = () => {
className={signup_fb_btn}
id="dm-signup-facebook"
onClick={() => {
onAnalyticEvent('facebook')
Analytics?.trackEvent('ce_virtual_signup_form', {
signup_provider: 'google',
...analyticsData,
})
Login.initOneAll('facebook')
}}
>
Expand All @@ -56,7 +67,10 @@ const FormSocialButtons = () => {
textcolor="white"
id="dm-signup-apple"
onClick={() => {
onAnalyticEvent('apple')
Analytics?.trackEvent('ce_virtual_signup_form', {
signup_provider: 'apple',
...analyticsData,
})
Login.initOneAll('apple')
}}
>
Expand All @@ -83,7 +97,10 @@ const FormSocialButtons = () => {
className={signup_login_redirect}
onClick={(event) => {
event.preventDefault()
onAnalyticEvent('email')
Analytics?.trackEvent('ce_virtual_signup_form', {
signup_provider: 'email',
...analyticsData,
})
Login.redirectToLogin()
}}
/>,
Expand Down
10 changes: 7 additions & 3 deletions src/features/pages/signup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import React, { useEffect } from 'react'
import { Analytics } from '@deriv/analytics'
import Layout from 'features/components/templates/layout'
import { signup_wrapper } from './signup.module.scss'
import SignUpContent from './signup.content'
import SignUpFormContainer from './form-container'
import StaticNav from 'features/components/templates/navigation/static-nav'
import { useAnalyticsEvents } from 'features/hooks/analytic/use-analytic-events'
import Flex from 'features/components/atoms/flex-box'
import { isBrowser } from 'common/utility'

const SignUp = () => {
const { onAnalyticEvent } = useAnalyticsEvents('ce_virtual_signup_form')
const analyticsData: Parameters<typeof Analytics.trackEvent>[1] = {
form_source: isBrowser() && window.location.hostname,
form_name: 'default_diel_deriv',
}

useEffect(() => {
onAnalyticEvent('open')
Analytics?.trackEvent('ce_virtual_signup_form', { action: 'open', ...analyticsData })
}, [])

return (
Expand Down
12 changes: 1 addition & 11 deletions src/pages/landing/ebooks/stocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { graphql, useStaticQuery } from 'gatsby'
import HeaderSection from './components/_header-section'
import Introduction from './components/_introduction'
import Topics from './components/_topics'
import { useGrowthBook } from 'features/hooks/analytic/use-growthbook'
import Layout from 'components/layout/layout'
import { SEO } from 'components/containers'
import { WithIntl } from 'components/localization'
Expand Down Expand Up @@ -31,15 +30,6 @@ const query = graphql`
`

const StocksEbook = () => {
const { ebook_stocks_heading } = useGrowthBook()

const introMains = {
control: '_t_Learn to trade Stock derivatives the smart way_t_',
'new-title': '_t_Learn to trade Stock derivatives the smart way_t_',
}

const introMain = introMains[ebook_stocks_heading] || introMains.control

const data = useStaticQuery(query)
return (
<Layout type="landing-page" is_ppc_redirect>
Expand All @@ -48,7 +38,7 @@ const StocksEbook = () => {
imgWidth={557}
imgHeight={703}
ebook_utm_code="stock-ebook"
introMain={introMain}
introMain={'_t_Learn to trade Stock derivatives the smart way_t_'}
authorDesc="_t_This e-book has been brought to you by a veteran online trader and New York Times bestselling author,_t_"
authorName="_t_Vince Stanzione._t_"
/>
Expand Down
Loading
Loading