-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 integration for Osano/GDPR #17565
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { isGdprCountry } from "./dataPrivacy"; | ||
|
||
const mockTimeZone = (timeZone: string) => { | ||
jest.spyOn(Intl, "DateTimeFormat").mockImplementation( | ||
() => | ||
({ | ||
resolvedOptions: () => | ||
({ | ||
timeZone, | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any), | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} as any) | ||
); | ||
}; | ||
|
||
describe("dataPrivacy", () => { | ||
describe("isGdprCountry()", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("should return true for timezones inside EU", () => { | ||
mockTimeZone("Europe/Berlin"); | ||
expect(isGdprCountry()).toBe(true); | ||
}); | ||
|
||
it("should return false for non EU countries", () => { | ||
mockTimeZone("America/Chicago"); | ||
expect(isGdprCountry()).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
declare global { | ||
interface Window { | ||
Osano?: { | ||
cm: { | ||
mode: "production" | "debug"; | ||
showDrawer: (type: string) => void; | ||
}; | ||
}; | ||
} | ||
} | ||
|
||
const GDPR_TIMEZONES = [ | ||
"Africa/Ceuta", | ||
"Asia/Famagusta", | ||
"Asia/Nicosia", | ||
"Atlantic/Azores", | ||
"Atlantic/Canary", | ||
"Atlantic/Madeira", | ||
"Europe/Amsterdam", | ||
"Europe/Athens", | ||
"Europe/Berlin", | ||
"Europe/Bratislava", | ||
"Europe/Brussels", | ||
"Europe/Bucharest", | ||
"Europe/Budapest", | ||
"Europe/Busingen", | ||
"Europe/Copenhagen", | ||
"Europe/Dublin", | ||
"Europe/Helsinki", | ||
"Europe/Lisbon", | ||
"Europe/Ljubljana", | ||
"Europe/Luxembourg", | ||
"Europe/Madrid", | ||
"Europe/Malta", | ||
"Europe/Paris", | ||
"Europe/Prague", | ||
"Europe/Riga", | ||
"Europe/Rome", | ||
"Europe/Sofia", | ||
"Europe/Stockholm", | ||
"Europe/Tallinn", | ||
"Europe/Vienna", | ||
"Europe/Vilnius", | ||
"Europe/Warsaw", | ||
"Europe/Zagreb", | ||
]; | ||
|
||
export const isGdprCountry = (): boolean => { | ||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; | ||
return GDPR_TIMEZONES.includes(timeZone); | ||
}; | ||
|
||
export const loadOsano = (): void => { | ||
if (!process.env.REACT_APP_OSANO) { | ||
return; | ||
} | ||
|
||
// Create style element to hide osano widget | ||
const style = document.createElement("style"); | ||
style.appendChild(document.createTextNode(".osano-cm-widget { display: none; }")); | ||
document.head.appendChild(style); | ||
|
||
// Create and append the script tag to load osano | ||
const script = document.createElement("script"); | ||
script.src = `https://cmp.osano.com/${process.env.REACT_APP_OSANO}/osano.js`; | ||
document.head.appendChild(script); | ||
}; | ||
|
||
export const isOsanoActive = (): boolean => { | ||
return window.Osano?.cm.mode === "production"; | ||
}; | ||
|
||
export const showOsanoDrawer = (): void => { | ||
window.Osano?.cm.showDrawer("osano-cm-dom-info-dialog-open"); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just curious: is browser timezone a sufficient way to enforce GDPR? Seems a bit unreliable to me, but I don't have a better suggestion.
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 agree, this is not a really foolproof way. Luckily this is really only used to determine the default state of the newsletter flag and such I think it's an "okay enough" approach, without requiring to get a third party geo location service in place (which would be the better approach detecting by IP location). Osano itself for showing the right consent banner actually uses a proper IP based approach, so it's really only for the default state of this one switch we're needing to use this weaker approach.