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

Commit

Permalink
Konstantinos/DERC-2262/Datalayer issue fix + partytown integration (#…
Browse files Browse the repository at this point in the history
…6068)

* fix: performance

* fix: hero images optimized

---------

Co-authored-by: “konstantinosG-deriv” <“[email protected]”>
  • Loading branch information
konstantinosG-deriv and “konstantinosG-deriv” authored Nov 29, 2023
1 parent 9aabd45 commit 1076bcc
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 34 deletions.
5 changes: 5 additions & 0 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
const language_config = require(`./i18n-config.js`)
const language_config_en = require(`./i18n-config-en.js`)
const path = require('path')
const { copyLibFiles } = require('@builder.io/partytown/utils')

const translations_cache = {}

exports.onPreBuild = async () => {
await copyLibFiles(path.join(__dirname, 'static', '~partytown'))
}
// Based upon https://github.com/gatsbyjs/gatsby/tree/master/examples/using-i18n
exports.onCreatePage = ({ page, actions }) => {
const { createRedirect, createPage, deletePage } = actions
Expand Down
73 changes: 43 additions & 30 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
import React from 'react'
import { Partytown } from '@builder.io/partytown/react'
import { WrapPagesWithLocaleContext } from './src/components/localization'
import './src/components/localization/config'
import GlobalProvider from './src/store/global-provider'

export const wrapRootElement = ({ element }) => {
return <GlobalProvider>{element}</GlobalProvider>
return <GlobalProvider>{element}</GlobalProvider>
}

export const wrapPageElement = WrapPagesWithLocaleContext

export const onRenderBody = ({ setHeadComponents }) => {
const gtmTrackingId = process.env.GATSBY_GOOGLE_TAG_MANAGER_TRACKING_ID || ''
const gtmTrackingId = process.env.GATSBY_GOOGLE_TAG_MANAGER_TRACKING_ID || ''

setHeadComponents([
<script
key="partytown-vanilla-config"
dangerouslySetInnerHTML={{
__html: `partytown = {
resolveUrl(url, location) {
// Use a secure connection
if (url?.protocol === 'http:') {
url = new URL(url.href.replace('http', 'https'))
}
// Point to our proxied URL
const proxyUrl = new URL(location.origin + '/__third-party-proxy')
proxyUrl.searchParams.append('url', url)
return proxyUrl
}
}`,
}}
/>,
gtmTrackingId && (
<script
key="gtm-script"
dangerouslySetInnerHTML={{
__html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl+'';f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer', '${gtmTrackingId}');`,
}}
/>
),
])
}
setHeadComponents([
// Partytown setup
<Partytown key="partytown" />,
<script
key="partytown-vanilla-config"
dangerouslySetInnerHTML={{
__html: `partytown = {
resolveUrl(url, location) {
// Use a secure connection
if (url?.protocol === 'http:') {
url = new URL(url.href.replace('http', 'https'))
}
// Point to our proxied URL
const proxyUrl = new URL(location.origin + '/__third-party-proxy')
proxyUrl.searchParams.append('url', url)
return proxyUrl
}
}`,
}}
/>,

// GTM setup
gtmTrackingId && (
<script
key="gtm-script"
type="text/partytown"
async
src={`https://www.googletagmanager.com/gtm.js?id=${gtmTrackingId}`}
></script>
),
gtmTrackingId && (
<script
key="gtm-script"
dangerouslySetInnerHTML={{
__html: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl+'';f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer', '${gtmTrackingId}');`,
}}
/>
),
])
}
18 changes: 15 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"author": "Deriv",
"dependencies": {
"@artsy/fresnel": "^6.1.0",
"@builder.io/partytown": "^0.8.1",
"@deriv/analytics": "^1.3.4",
"@deriv/deriv-api": "^1.0.11",
"@hookform/resolvers": "^3.0.1",
Expand Down Expand Up @@ -147,6 +148,7 @@
"scripts": {
"analyze-bundle": "GENERATE_JSON_STATS=true gatsby build && npx webpack-bundle-analyzer -m static -r ./webpack-bundle-report/report.html ./public/stats.json",
"build": "GATSBY_CPU_COUNT=2 gatsby build --log-pages",
"partytown": "partytown copylib public/~partytown",
"develop": "GATSBY_CPU_COUNT=2 gatsby develop -o",
"format": "prettier --write '**/*.js' '*.js'",
"stylelint": "stylelint 'src/**/*.js' --formatter verbose",
Expand Down
1 change: 1 addition & 0 deletions src/components/hooks/use-livechat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const useLivechat = (): [boolean, TLC_API] => {

const loadLiveChatScript = (callback) => {
const livechat_script = document.createElement('script')
livechat_script.type = 'text/partytown'
livechat_script.innerHTML = `
window.__lc = window.__lc || {};
window.__lc.license = ${licence_key};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const LanguageSwitcher = () => {
onOpenChange={setOpen}
>
<DropdownMenu.Trigger asChild>
<div className={styles.trigger}>
<div role="button" className={styles.trigger}>
<Typography.Paragraph size="medium" font_family={'UBUNTU'} weight="bold">
{currentLang.short_name}
</Typography.Paragraph>
Expand Down
Binary file modified src/images/common/awards/best-forex-spreads.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/awards/broker-of-the-year.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/awards/gptw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/awards/investors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/awards/most-trusted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/home/eu_hero_person_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/home/hero_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/home/hero_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/home/hero_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/images/common/home/hero_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

1 comment on commit 1076bcc

@vercel
Copy link

@vercel vercel bot commented on 1076bcc Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-com – ./

deriv-com.binary.sx
deriv-com-git-master.binary.sx

Please sign in to comment.