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

Commit

Permalink
Revert "Fix gtm partytown integration (#6038)" (#6049)
Browse files Browse the repository at this point in the history
This reverts commit 442a6e8.
  • Loading branch information
habib-deriv authored Nov 27, 2023
1 parent 442a6e8 commit 4476a31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
3 changes: 3 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ module.exports = {
`https://assets.customer.io/assets/track.js`,
`https://static.deriv.com/scripts/cookie.js`,
`https://widget.trustpilot.com/bootstrap/v5/tp.widget.bootstrap.min.js`,
`https://cdn.livechatinc.com/tracking.js`,
`https://www.google-analytics.com/analytics.js`,
`https://www.googletagmanager.com/gtm.js?id=${process.env.GATSBY_GOOGLE_TAG_MANAGER_TRACKING_ID}`,
],
plugins: [
// [TODO] Enable this when we have a proper setup to enable caching, Otherwise it will cause one of them stop working.
Expand Down
33 changes: 12 additions & 21 deletions gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,29 @@ export const onRenderBody = ({ setHeadComponents }) => {
const gtmTrackingId = process.env.GATSBY_GOOGLE_TAG_MANAGER_TRACKING_ID || ''

setHeadComponents([
// Partytown setup
<Partytown key="partytown" forward={['dataLayer.push']} />,
<script
key="partytown-vanilla-config"
type="text/partytown"
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
}
}`,
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}');`,
}}
Expand Down

0 comments on commit 4476a31

Please sign in to comment.