-
Notifications
You must be signed in to change notification settings - Fork 85
Fides JS Code Snippet - Include wrapper script; add text field to set Privacy Center host URL #7081
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
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Greptile OverviewGreptile SummaryThis PR enhances the JavaScript tag generation UI by adding a manual input field for the Privacy Center hostname and introducing a more comprehensive Fides JS script template with geolocation query parameter handling.
Issues found:
Confidence Score: 3/5
Important Files ChangedFile Analysis
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, 2 comments
clients/admin-ui/src/features/privacy-experience/fidesJsScriptTemplate.ts
Outdated
Show resolved
Hide resolved
clients/admin-ui/src/features/privacy-experience/fidesJsScriptTemplate.ts
Outdated
Show resolved
Hide resolved
tvandort
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! Left a few feedback items. Could also use some tests.
| export const removePropertyIdFromScript = (script: string, hasPropertyId: boolean) => { | ||
| if (!hasPropertyId) { | ||
| script = script.replaceAll('+ "?property_id=" + fidesPropertyId + "&"', ""); | ||
| } | ||
| return script; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have this be inserted instead of removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tvandort I changed the logic to insert the property ID now.
fides/clients/admin-ui/src/features/privacy-experience/fidesJsScriptTemplate.ts
Lines 6 to 11 in 1e1cedb
| */ | |
| const PROPERTY_UNIQUE_ID_TEMPLATE = (propertyId?: string | null): string => { | |
| if (propertyId) { | |
| return propertyId; | |
| } | |
| return "{property-unique-id}"; |
| }); | ||
| addEventListener("FidesInitialized", function () { | ||
| // support custom css hackery |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't want to use the word hackery here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth including an example of how to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed and updated comments
| if (key.startsWith(fidesPrefix)) { | ||
| fidesSearchParams.set( | ||
| key.replace(fidesPrefix, ""), | ||
| key === fidesPrefix + "cache_bust" ? Date.now().toString() : value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider making the cache bust parameter also just pass refresh to the privacy center to make everyone's life easier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Included refresh=true anytime the cache bust parameter is set:
| fidesSearchParams.set( |
| FIDES_JS_SCRIPT_TEMPLATE, | ||
| PRIVACY_CENTER_HOSTNAME_TEMPLATE, | ||
| removePropertyIdFromScript | ||
| } from "./fidesJsScriptTemplate"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea when we want to use relative vs absolute imports as a "general rule". Personally I prefer all absolute but I don't know if that's our general practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched the paths to absolute.
| () => { | ||
| let script = FIDES_JS_SCRIPT_TEMPLATE; | ||
|
|
||
| script = removePropertyIdFromScript(script, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see this more as something like:
getScript({propertyId: "example"}) or getScript()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think of the new implementation. Now, pretty much all of the logic is contained in the script template, and the script tags just handle the rendering of the template with some logic to recompute the dynamic values when those are changed.
| const fidesJsScriptTag = useMemo( | |
| () => { | |
| return FIDES_JS_SCRIPT_TEMPLATE(privacyCenterHostname); | |
| }, | |
| [privacyCenterHostname], | |
| ); |
| let script = FIDES_JS_SCRIPT_TEMPLATE.replaceAll( | ||
| PROPERTY_UNIQUE_ID_TEMPLATE, | ||
| property.id!.toString(), | ||
| ); | ||
| if (isFidesCloud && isSuccess && fidesCloudConfig?.privacy_center_url) { | ||
| script.replace( | ||
| PRIVACY_CENTER_HOSTNAME_TEMPLATE, | ||
| fidesCloudConfig.privacy_center_url, | ||
| ); | ||
| // Use user input if provided, otherwise fall back to Fides Cloud config | ||
| const hostname = | ||
| privacyCenterHostname || | ||
| (isFidesCloud && isSuccess && fidesCloudConfig?.privacy_center_url | ||
| ? fidesCloudConfig.privacy_center_url | ||
| : ""); | ||
| if (hostname) { | ||
| script = script.replaceAll(PRIVACY_CENTER_HOSTNAME_TEMPLATE, hostname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback here, I'd love to see the templating inside of the function that returns the script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See update here:
fides/clients/admin-ui/src/features/privacy-experience/NewJavaScriptTag.tsx
Lines 33 to 37 in 1e1cedb
| const fidesJsScriptTag = useMemo( | |
| () => FIDES_JS_SCRIPT_TEMPLATE(privacyCenterHostname, property), | |
| [privacyCenterHostname, property], | |
| ); | |
| /** | ||
| * Generates the property ID query parameter string for the Fides.js script URL | ||
| */ | ||
| const PROPERTY_UNIQUE_ID_TEMPLATE = (propertyId?: string | null): string => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function naming pattern should be camelcase
| /** | ||
| * Generates the complete Fides.js script tag with privacy center hostname and property ID | ||
| */ | ||
| export const FIDES_JS_SCRIPT_TEMPLATE = (privacyCenterHostname?: string, property?: Property): string => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function naming pattern should be camelcase
| if (propertyId) { | ||
| return propertyId; | ||
| } | ||
| return "{property-unique-id}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this return value ever used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it will return "{property-unique-id}" when there isn't a property in scope, which means this version will be rendered when accessing the script from the Experiences screen. I can add a comment that explains this.
| if (privacyCenterHostname) { | ||
| script = script.replaceAll(PRIVACY_CENTER_HOSTNAME_TEMPLATE, privacyCenterHostname); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template is updated in 2 ways, both replacement and by string interpolation in the string itself. Do we need both?
Ticket ENG-1944
Description Of Changes
Code Changes
fidesJsScriptTemplate.js, which removes the need to update the code snippet in two separate places (originally in both theNewJavascriptTag.tsxandJavascriptTag.tsx.Steps to Confirm
Pre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works