From 3ab6254360fb50985201f8b1c2c201db88ae897b Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Wed, 2 Oct 2024 10:33:32 +0800 Subject: [PATCH 1/8] feat: added environment variables for analytics --- .github/actions/build/action.yml | 12 ++++++++++++ .github/workflows/generate_preview_link.yml | 7 +++++++ .github/workflows/release_production.yml | 5 +++++ .github/workflows/release_staging.yml | 8 ++++++++ .github/workflows/test.yml | 4 ++++ 5 files changed, 36 insertions(+) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index b3091ebac4d..7d5fb14204c 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -5,11 +5,23 @@ inputs: description: "Target Environment" required: true default: staging + RUDDERSTACK_KEY: + description: "Rudderstack key for initialising analytics" + required: false + GROWTHBOOK_DECRYPTION_KEY: + description: "Growthbook decryption key for initialising analytics" + required: false + GROWTHBOOK_CLIENT_KEY: + description: "Growthbook client key for initialising analytics" + required: false runs: using: composite steps: - name: Building dist for ${{ inputs.target }} env: TARGET_ENV: ${{ inputs.target }} + RUDDERSTACK_KEY: ${{ inputs.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ inputs.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ inputs.GROWTHBOOK_CLIENT_KEY }} run: node_modules/grunt/bin/grunt releaseci --$TARGET_ENV shell: bash diff --git a/.github/workflows/generate_preview_link.yml b/.github/workflows/generate_preview_link.yml index 2ec2e2880de..e53bc79800f 100644 --- a/.github/workflows/generate_preview_link.yml +++ b/.github/workflows/generate_preview_link.yml @@ -14,6 +14,7 @@ concurrency: jobs: build_and_deploy_preview_link: runs-on: Ubuntu-latest + environment: Staging permissions: checks: write pull-requests: write @@ -48,11 +49,17 @@ jobs: uses: "./.github/actions/build" with: target: staging + RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Build Translations uses: "./.github/actions/build" with: target: translations + RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: "Run Tests" run: npm run test diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index e77ca9ecfa8..ff4b1ee5509 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -7,6 +7,7 @@ jobs: build_and_test: name: Build and Test runs-on: ubuntu-latest + environment: Production env: RELEASE_TYPE: Production steps: @@ -22,6 +23,9 @@ jobs: uses: "./.github/actions/build" with: target: production + RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Versioning uses: "./.github/actions/versioning" with: @@ -35,6 +39,7 @@ jobs: path: dist publish_cloudflare_production: name: Publish to Cloudflare Production + environment: Production runs-on: ubuntu-latest env: RELEASE_TYPE: Production diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index e69515eeb4b..4ad732bfc98 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -6,6 +6,7 @@ on: jobs: build_and_test: name: Build and Test + environment: Staging runs-on: ubuntu-latest steps: - name: Checkout @@ -20,10 +21,16 @@ jobs: uses: "./.github/actions/build" with: target: staging + RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Build Translations uses: "./.github/actions/build" with: target: translations + RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Versioning uses: "./.github/actions/versioning" with: @@ -36,6 +43,7 @@ jobs: path: dist publish_cloudflare_staging: name: Publish to Cloudflare Pages Staging + environment: Staging runs-on: ubuntu-latest needs: [build_and_test] steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c2d8028d6c7..5a778abb2ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,6 +7,7 @@ jobs: build_and_test: name: Build and Test runs-on: ubuntu-latest + environment: Production steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 @@ -20,5 +21,8 @@ jobs: uses: "./.github/actions/build" with: target: production + RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} + GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} + GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: "Run Tests" run: npm run test From c37b4a70191da3d87eb7802a3481b942cd39d80d Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Wed, 2 Oct 2024 11:36:49 +0800 Subject: [PATCH 2/8] chore: redeploy test link --- .github/workflows/release_production.yml | 1 - src/javascript/app/base/header.js | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index ff4b1ee5509..b69991a605f 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -39,7 +39,6 @@ jobs: path: dist publish_cloudflare_production: name: Publish to Cloudflare Production - environment: Production runs-on: ubuntu-latest env: RELEASE_TYPE: Production diff --git a/src/javascript/app/base/header.js b/src/javascript/app/base/header.js index 812fb94554c..23277b43c34 100644 --- a/src/javascript/app/base/header.js +++ b/src/javascript/app/base/header.js @@ -499,6 +499,7 @@ const Header = (() => { showMobileSubmenu(false); }); + // OnClickOutisde Event Handle document.addEventListener('click', (event) => { // Platform Switcher From 38cb9666e18af2cd1d14c6089b182701cef27fb2 Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Wed, 2 Oct 2024 11:48:46 +0800 Subject: [PATCH 3/8] chore: updated environemnt --- .github/workflows/release_production.yml | 2 +- .github/workflows/release_staging.yml | 1 - .github/workflows/test.yml | 2 +- src/javascript/app/base/header.js | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index b69991a605f..773b8709fb0 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -6,8 +6,8 @@ on: jobs: build_and_test: name: Build and Test - runs-on: ubuntu-latest environment: Production + runs-on: ubuntu-latest env: RELEASE_TYPE: Production steps: diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 4ad732bfc98..6d08162fe5b 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -43,7 +43,6 @@ jobs: path: dist publish_cloudflare_staging: name: Publish to Cloudflare Pages Staging - environment: Staging runs-on: ubuntu-latest needs: [build_and_test] steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a778abb2ef..70175c259df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,8 @@ on: jobs: build_and_test: name: Build and Test + environment: Development runs-on: ubuntu-latest - environment: Production steps: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 diff --git a/src/javascript/app/base/header.js b/src/javascript/app/base/header.js index 23277b43c34..812fb94554c 100644 --- a/src/javascript/app/base/header.js +++ b/src/javascript/app/base/header.js @@ -499,7 +499,6 @@ const Header = (() => { showMobileSubmenu(false); }); - // OnClickOutisde Event Handle document.addEventListener('click', (event) => { // Platform Switcher From 2a4cb2872b35265dae77f2f13a3feab77a6f8422 Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Wed, 2 Oct 2024 12:00:54 +0800 Subject: [PATCH 4/8] chore: removed growthbook decryption key as it is not required --- .github/actions/build/action.yml | 4 -- .github/workflows/generate_preview_link.yml | 4 +- .github/workflows/release_production.yml | 1 - .github/workflows/release_staging.yml | 2 - .github/workflows/test.yml | 1 - src/javascript/_common/analytics.js | 42 +++++++++++++++++++++ 6 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/javascript/_common/analytics.js diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 7d5fb14204c..524d2edd7df 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -8,9 +8,6 @@ inputs: RUDDERSTACK_KEY: description: "Rudderstack key for initialising analytics" required: false - GROWTHBOOK_DECRYPTION_KEY: - description: "Growthbook decryption key for initialising analytics" - required: false GROWTHBOOK_CLIENT_KEY: description: "Growthbook client key for initialising analytics" required: false @@ -21,7 +18,6 @@ runs: env: TARGET_ENV: ${{ inputs.target }} RUDDERSTACK_KEY: ${{ inputs.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ inputs.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ inputs.GROWTHBOOK_CLIENT_KEY }} run: node_modules/grunt/bin/grunt releaseci --$TARGET_ENV shell: bash diff --git a/.github/workflows/generate_preview_link.yml b/.github/workflows/generate_preview_link.yml index e53bc79800f..6fc1f4b675c 100644 --- a/.github/workflows/generate_preview_link.yml +++ b/.github/workflows/generate_preview_link.yml @@ -14,7 +14,7 @@ concurrency: jobs: build_and_deploy_preview_link: runs-on: Ubuntu-latest - environment: Staging + environment: Development permissions: checks: write pull-requests: write @@ -50,7 +50,6 @@ jobs: with: target: staging RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Build Translations @@ -58,7 +57,6 @@ jobs: with: target: translations RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: "Run Tests" diff --git a/.github/workflows/release_production.yml b/.github/workflows/release_production.yml index 773b8709fb0..6cee8bd61a2 100644 --- a/.github/workflows/release_production.yml +++ b/.github/workflows/release_production.yml @@ -24,7 +24,6 @@ jobs: with: target: production RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Versioning uses: "./.github/actions/versioning" diff --git a/.github/workflows/release_staging.yml b/.github/workflows/release_staging.yml index 6d08162fe5b..bc040e25c1e 100644 --- a/.github/workflows/release_staging.yml +++ b/.github/workflows/release_staging.yml @@ -22,14 +22,12 @@ jobs: with: target: staging RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Build Translations uses: "./.github/actions/build" with: target: translations RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: Versioning uses: "./.github/actions/versioning" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70175c259df..03de766eb62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,6 @@ jobs: with: target: production RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }} GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: "Run Tests" run: npm run test diff --git a/src/javascript/_common/analytics.js b/src/javascript/_common/analytics.js new file mode 100644 index 00000000000..c25115401de --- /dev/null +++ b/src/javascript/_common/analytics.js @@ -0,0 +1,42 @@ +const DerivAnalytics = require('@deriv-com/analytics'); + +const Analytics = (() => { + const init = () => { + if (process.env.RUDDERSTACK_KEY && process.env.GROWTHBOOK_CLIENT_KEY) { + DerivAnalytics.Analytics.initialise({ + growthbookKey : process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests + rudderstackKey : process.env.RUDDERSTACK_KEY, + }); + } + }; + + const isGrowthbookLoaded = () => Boolean(DerivAnalytics.Analytics?.getInstances()?.ab); + + const getGrowthbookFeatureValue = ({ defaultValue, featureFlag }) => { + const resolvedDefaultValue = defaultValue !== undefined ? defaultValue : false; + const isGBLoaded = isGrowthbookLoaded(); + + if (!isGBLoaded) return [null, false]; + + return [DerivAnalytics.Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue), true]; + }; + + const setGrowthbookOnChange = onChange => { + const isGBLoaded = isGrowthbookLoaded(); + if (!isGBLoaded) return null; + + const onChangeRenderer = DerivAnalytics.Analytics?.getInstances().ab.GrowthBook?.setRenderer(() => { + onChange(); + }); + return onChangeRenderer; + }; + + return { + init, + isGrowthbookLoaded, + getGrowthbookFeatureValue, + setGrowthbookOnChange, + }; +})(); + +module.exports = Analytics; From 41c168a3cafd3ab9e9a2d6922fd3ba244625c2e0 Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Wed, 2 Oct 2024 12:04:02 +0800 Subject: [PATCH 5/8] chore: resolved eslint --- src/javascript/_common/analytics.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/javascript/_common/analytics.js b/src/javascript/_common/analytics.js index c25115401de..9cc8055729e 100644 --- a/src/javascript/_common/analytics.js +++ b/src/javascript/_common/analytics.js @@ -4,8 +4,8 @@ const Analytics = (() => { const init = () => { if (process.env.RUDDERSTACK_KEY && process.env.GROWTHBOOK_CLIENT_KEY) { DerivAnalytics.Analytics.initialise({ - growthbookKey : process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests - rudderstackKey : process.env.RUDDERSTACK_KEY, + growthbookKey : process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests + rudderstackKey: process.env.RUDDERSTACK_KEY, }); } }; From c156607945328c8273455407501d81543eb1d61a Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Wed, 2 Oct 2024 12:06:24 +0800 Subject: [PATCH 6/8] chore: removed unrelated files to the current branch --- src/javascript/_common/analytics.js | 42 ----------------------------- 1 file changed, 42 deletions(-) delete mode 100644 src/javascript/_common/analytics.js diff --git a/src/javascript/_common/analytics.js b/src/javascript/_common/analytics.js deleted file mode 100644 index 9cc8055729e..00000000000 --- a/src/javascript/_common/analytics.js +++ /dev/null @@ -1,42 +0,0 @@ -const DerivAnalytics = require('@deriv-com/analytics'); - -const Analytics = (() => { - const init = () => { - if (process.env.RUDDERSTACK_KEY && process.env.GROWTHBOOK_CLIENT_KEY) { - DerivAnalytics.Analytics.initialise({ - growthbookKey : process.env.GROWTHBOOK_CLIENT_KEY, // optional key to enable A/B tests - rudderstackKey: process.env.RUDDERSTACK_KEY, - }); - } - }; - - const isGrowthbookLoaded = () => Boolean(DerivAnalytics.Analytics?.getInstances()?.ab); - - const getGrowthbookFeatureValue = ({ defaultValue, featureFlag }) => { - const resolvedDefaultValue = defaultValue !== undefined ? defaultValue : false; - const isGBLoaded = isGrowthbookLoaded(); - - if (!isGBLoaded) return [null, false]; - - return [DerivAnalytics.Analytics?.getFeatureValue(featureFlag, resolvedDefaultValue), true]; - }; - - const setGrowthbookOnChange = onChange => { - const isGBLoaded = isGrowthbookLoaded(); - if (!isGBLoaded) return null; - - const onChangeRenderer = DerivAnalytics.Analytics?.getInstances().ab.GrowthBook?.setRenderer(() => { - onChange(); - }); - return onChangeRenderer; - }; - - return { - init, - isGrowthbookLoaded, - getGrowthbookFeatureValue, - setGrowthbookOnChange, - }; -})(); - -module.exports = Analytics; From 2e9a3720c63786caf17b6f7006b9d96c210e2fef Mon Sep 17 00:00:00 2001 From: adrienne-deriv <103016120+adrienne-deriv@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:01:32 +0800 Subject: [PATCH 7/8] chore: removed environment for test workflow --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03de766eb62..5a6f4fb2ffc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,6 @@ on: jobs: build_and_test: name: Build and Test - environment: Development runs-on: ubuntu-latest steps: - name: Checkout From 03e04919826744d0277d4b3045bbcd94afe84373 Mon Sep 17 00:00:00 2001 From: adrienne-deriv <103016120+adrienne-deriv@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:01:57 +0800 Subject: [PATCH 8/8] chore: removed environment for test workflow --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a6f4fb2ffc..c2d8028d6c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,5 @@ jobs: uses: "./.github/actions/build" with: target: production - RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }} - GROWTHBOOK_CLIENT_KEY: ${{ vars.GROWTHBOOK_CLIENT_KEY }} - name: "Run Tests" run: npm run test