Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localization support for privacy banner + useCustomerPrivacy updates #2457

Merged
merged 18 commits into from
Sep 4, 2024

Conversation

juanpprieto
Copy link
Contributor

@juanpprieto juanpprieto commented Aug 20, 2024

analytics.mp4

Included on this PR:

1. Adds consent banner localization support to the AnalyticsProvider and useCustomerPrivacy

To enable it simply pass country and language to the consent config returned from the loader

2. Reworks the previously fragile customerPrivacy and privacyBanner onReady logic removing a not ideal 3s setTimeout and relying on Object.defineProperty on the window instead to detect when these SDKs are actually available.

Banner will show when ready instead of after 3 secs.

3. Deprecates a getCustomerPrivacy utility

Now that we have privacyBanner and customerPrivacy returned from both useAnalytics and useCustomerPrivacy we don't need getCustomerPrivacy

4. Adds privacyBanner and customerPrivacy to the useAnalytics and useCustomerPrivacy returns, so users can now use any of these SDK methods programmatically

const {customerPrivacy, privacyBanner} = useAnalytics() // or useCustomerPrivacy(..)

if (privacyBanner) {
  // load the consent banner programmatically
  privacyBanner.loadBanner() 
  // or  
  privacyBanner.loadBanner({ country: "CA", locale: "FR" })
 
  // load preferences banner programmatically
  privacyBanner.showPreferences();
  // or
  privacyBanner.showPreferences({ country: "CA", locale: "FR" })
}

if (customerPrivacy) {
 const analyticsProcessingAllowed = customerPrivacy.analyticsProcessingAllowed()
 // ....
}

Used in the demo videos header buttons.

5. Fixed an issue where tracking was temporarily allowed for a few milliseconds while the consent check was being performed by the customerPrivacy SDK

Tophat instructions:

  • Return difference country and language combinations from the root loader consent.
  • test the different methods of privacyBanner (showBanner, showPreferences) and customerPrivacy (analyticsProcessingAllowed, setTrackingConsent) returned by useAnalytics and/or useCustomerPrivacy

TODO

  • Update existing tests and add new tests for useCustomerPrivacy
  • Update docs
  • Test snapshot in a 3P consent environment

Copy link
Contributor

shopify bot commented Aug 22, 2024

Oxygen deployed a preview of your juanpprieto/international-privacy-banner branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment September 4, 2024 6:52 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment September 4, 2024 6:52 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment September 4, 2024 6:52 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment September 4, 2024 6:52 PM
sitemap ✅ Successful (Logs) Preview deployment Inspect deployment September 4, 2024 6:52 PM
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment September 4, 2024 6:52 PM

Learn more about Hydrogen's GitHub integration.

@juanpprieto juanpprieto marked this pull request as ready for review August 28, 2024 23:40

This comment has been minimized.

@juanpprieto juanpprieto changed the title WIP: Add localization support for privacy banner Add localization support for privacy banner + useCustomerPrivacy updates Aug 29, 2024
@juanpprieto
Copy link
Contributor Author

/snapit

Copy link
Contributor

github-actions bot commented Sep 3, 2024

🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20240903172745",
"@shopify/hydrogen": "0.0.0-snapshot-20240903172745",
"@shopify/mini-oxygen": "0.0.0-snapshot-20240903172745",
"@shopify/remix-oxygen": "0.0.0-snapshot-20240903172745"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

templates/skeleton/app/root.tsx Show resolved Hide resolved
@juanpprieto
Copy link
Contributor Author

/snapit

Copy link
Contributor

github-actions bot commented Sep 3, 2024

🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

"@shopify/cli-hydrogen": "0.0.0-snapshot-20240903233028",
"@shopify/hydrogen": "0.0.0-snapshot-20240903233028",
"@shopify/mini-oxygen": "0.0.0-snapshot-20240903233028",
"@shopify/remix-oxygen": "0.0.0-snapshot-20240903233028"

Create a new project with all the released packages running npm create @shopify/hydrogen@<snapshot_version>
To try a new CLI plugin version, add @shopify/cli-hydrogen as a dependency to your project using the snapshot version.

@juanpprieto juanpprieto merged commit eefa820 into main Sep 4, 2024
13 checks passed
@juanpprieto juanpprieto deleted the juanpprieto/international-privacy-banner branch September 4, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants