Skip to content

Commit 0596ffb

Browse files
authored
Adding DUX CDN version (#14015)
### WHY are these changes introduced? polaris-react.shopify.com is not compliant with regards to cookie policy. We need to ensure that we do not drop cookies pre-consent in geos where that is required. <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Adding Dux and configured to gate cookies on the side. Mobile <img width="422" height="927" alt="image" src="https://github.com/user-attachments/assets/84574c29-bef3-4d3c-a48b-26f8842d256a" /> Desktop <img width="1294" height="547" alt="image" src="https://github.com/user-attachments/assets/8fd3b055-dfe8-47ec-82f2-8e21779385ae" /> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#install-dependencies-and-build-workspaces) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) Running the app locally, you'll see the cookie banner show up. You should also not see any cookies being set prior to accepting any cookies: <img width="699" height="412" alt="image" src="https://github.com/user-attachments/assets/ff8437f5-1e51-455f-8968-66656003620e" /> If you accept cookies, you should see `shopify_y` and `shopify_s` cookies being set. <img width="763" height="130" alt="image" src="https://github.com/user-attachments/assets/ea8f0bf0-c2e1-4393-aa8e-4dc44c687ef3" /> No cookies added if you reject cookies. ### 🎩 checklist - [ ] Tested a [snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases) - [x] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [x] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [x] Updated the component's `README.md` with documentation changes - [x] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent a1dbca8 commit 0596ffb

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

.changeset/better-rooms-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'polaris.shopify.com': patch
3+
---
4+
5+
Add Dux and privacy controls. Move GTM to Dux.

polaris.shopify.com/pages/_app.tsx

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,46 @@ function MyApp({Component, pageProps}: AppProps) {
7171

7272
return (
7373
<>
74-
{isProd ? (
75-
<>
76-
<Script
77-
async
78-
src={`https://www.googletagmanager.com/gtag/js?id=${PUBLIC_GA_ID}`}
79-
/>
80-
<Script
81-
id="gtag-init"
82-
strategy="afterInteractive"
83-
dangerouslySetInnerHTML={{
84-
__html: `
85-
window.dataLayer = window.dataLayer || [];
86-
function gtag(){dataLayer.push(arguments);}
87-
gtag('js', new Date());
88-
gtag('config', '${PUBLIC_GA_ID}', {
89-
page_path: window.location.pathname,
74+
<Script
75+
id="dux-init"
76+
strategy="afterInteractive"
77+
dangerouslySetInnerHTML={{
78+
__html: `
79+
const loadScript = (src) => {
80+
const promise = new Promise((resolve, reject) => {
81+
const script = document.createElement('script');
82+
script.src = src;
83+
script.type = 'module';
84+
script.onload = () => {
85+
resolve(true);
86+
};
87+
script.onerror = () => {
88+
reject(false);
89+
};
90+
document.body.appendChild(script);
91+
});
92+
return promise;
93+
}
94+
// example loading from CDN
95+
loadScript('https://cdn.shopify.com/shopifycloud/dux/dux-portal-4.4.0.min.js').then(() => {
96+
Dux.init({
97+
eventHandlerEndpoint: 'https://www.shopify.com/__dux',
98+
mode: 'production',
99+
service: 'polaris-react',
100+
enableActiveConsent: true,
101+
enableConsentBuffer: true,
102+
enableLogger: {
103+
cookieBlocker: true,
104+
},
105+
countryCode: 'GB',
106+
enableGtm: true,
107+
enableGtmLoader: true,
108+
gtmAccountId: '${PUBLIC_GA_ID}',
109+
})
90110
});
91111
`,
92-
}}
93-
/>
94-
</>
95-
) : null}
112+
}}
113+
/>
96114

97115
<script dangerouslySetInnerHTML={{__html: noflash}}></script>
98116

0 commit comments

Comments
 (0)