-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration for Osano/GDPR (#17565)
- Loading branch information
Showing
10 changed files
with
141 additions
and
11 deletions.
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"); | ||
}; |