feat(scripts): use c15t to load scripts based on shopper consent preferences#2659
Conversation
🦋 Changeset detectedLatest commit: 675089c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
f52d125 to
8542b96
Compare
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| `[scripts-transformer] Unknown BigCommerce Script Consent Category ` + | ||
| `"${bigCommerceCategory}", defaulting to UNKNOWN`, | ||
| ); |
There was a problem hiding this comment.
This will probably log in production. We probably want to remove this.
There was a problem hiding this comment.
Remove or just run when not in prod?
There was a problem hiding this comment.
I'd just remove here, otherwise we'd need to add some sort of invariant logger here.
jorgemoya
left a comment
There was a problem hiding this comment.
💯 , love how clean this is. Minor observations before the final approve 👍 .
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| `[scripts-transformer] Unknown BigCommerce Script Consent Category ` + | ||
| `"${bigCommerceCategory}", defaulting to UNKNOWN`, | ||
| ); |
There was a problem hiding this comment.
Remove or just run when not in prod?
| } | ||
| entityId | ||
| consentCategory | ||
| location |
There was a problem hiding this comment.
Should we remove location since we don't use it?
There was a problem hiding this comment.
Yeah good catch, we can always add it back later when the library adds support (which they are considering)
| integrityHashes { | ||
| hash | ||
| } |
There was a problem hiding this comment.
Are we still using integrityHashes for anything?
There was a problem hiding this comment.
Good catch! I added a fix that
.map()'s oversite.content.scripts.edges.node.integrityHashes- Filters out falsy (null)
- If resulting array contains hashes, join them with a single space (following HTML spec)
- Add them to the arbitrary
attributesobject to be added to the<script>element when rendered
e5bb5e3 to
3b51c8a
Compare
3b51c8a to
675089c
Compare
Note
This PR is a replacement for #2651
Closes #2651
What/Why?
This PR adds script loading functionality to Catalyst's consent manager, achieving parity with Stencil's consent-aware script loading behavior.
The implementation replaces the custom
<ScriptManagerScripts />component with the native Script Loader feature of the c15t.com library.Additionally, the consent categories exposed by c15t are different than the consent categories available in the BigCommerce API. The consent categories in the c15t library are hardcoded, so we added a
scriptsTransformerto map BigCommerce's consent categories to C15T's standardized categories:It's also worth noting that we maintain feature parity with Stencil in determining which scripts load based on consent preferences:
ESSENTIALandUNKNOWNscripts are loaded.ESSENTIALandUNKNOWNscripts load.Testing
Demo video:
https://github.com/user-attachments/assets/7f859c23-8419-46e7-b86e-a1e24127879a
Migration
This PR modifies the following files that you may encounter merge conflicts with:
core/app/[locale]/layout.tsx:ScriptsFragmentimport and inclusion inRootLayoutMetadataQueryscriptsTransformerimport<ConsentManager scripts={scripts}>ConsentManagercomponent now requires ascriptsprop. You'll need to query scripts using theScriptsFragmentand transform them viascriptsTransformer()before passing them to the component.core/components/consent-manager/index.tsxandconsent-providers.tsx:scriptspropConsentManagerProviderpasses scripts toClientSideOptionsProviderscriptsprop flows through:ConsentManager→ConsentManagerProvider→ClientSideOptionsProviderNew files added:
core/components/consent-manager/scripts-fragment.ts- GraphQL fragment for querying scriptscore/data-transformers/scripts-transformer.ts- Transforms BC scripts to C15T formatIf you've customized your consent manager implementation, ensure that:
scriptsTransformeris applied to the raw script data before passing to ConsentManager