-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from coinbase/gpc
Support for GPC
- Loading branch information
Showing
14 changed files
with
221 additions
and
55 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
14 changes: 14 additions & 0 deletions
14
packages/cookie-manager/src/utils/applyGpcToAdPref.test.ts
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,14 @@ | ||
import { Region } from '../types'; | ||
import { applyGpcToAdPref } from './applyGpcToAdPref'; | ||
|
||
describe('applyGpcToAdPref', () => { | ||
it('removes targeting when GPC is ON in non-EU', () => { | ||
(navigator as any).globalPrivacyControl = true; | ||
expect(applyGpcToAdPref(Region.DEFAULT, { value: true })).toEqual({ value: false }); | ||
}); | ||
|
||
it('ignores GPC when in EU', () => { | ||
(navigator as any).globalPrivacyControl = true; | ||
expect(applyGpcToAdPref(Region.EU, { value: true })).toEqual({ value: true }); | ||
}); | ||
}); |
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,31 @@ | ||
import { AdTrackingPreference, Region } from '../types'; | ||
|
||
const applyGpcToAdPref = ( | ||
region: Region, | ||
preference: AdTrackingPreference | ||
): AdTrackingPreference => { | ||
// We are only applying GPC in non-EU countries at this point | ||
if (region == Region.EU) { | ||
return preference; | ||
} | ||
// If we lack GPC or it's set ot false we are done | ||
if (!(navigator as any).globalPrivacyControl) { | ||
return preference; | ||
} | ||
|
||
// If the user already has sharing turned off nothing to do here | ||
if (preference.value == false) { | ||
return preference; // already allowing sharing | ||
} | ||
|
||
// We could set the updated at time to now if we'd like | ||
// preference.updated_at = new Date().getTime(); | ||
|
||
const pref: AdTrackingPreference = preference.updated_at | ||
? { value: false, updated_at: preference.updated_at } | ||
: { value: false }; | ||
|
||
return pref; | ||
}; | ||
|
||
export { applyGpcToAdPref }; |
44 changes: 44 additions & 0 deletions
44
packages/cookie-manager/src/utils/applyGpcToCookiePref.test.ts
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,44 @@ | ||
import { Region, TrackingCategory } from '../types'; | ||
import { applyGpcToCookiePref } from './applyGpcToCookiePref'; | ||
|
||
describe('applyGpcToCookiePref', () => { | ||
it('removes targeting when GPC is ON in non-EU', () => { | ||
(navigator as any).globalPrivacyControl = true; | ||
expect( | ||
applyGpcToCookiePref({ region: Region.DEFAULT, consent: [TrackingCategory.TARGETING] }) | ||
).toEqual({ | ||
region: Region.DEFAULT, | ||
consent: [], | ||
}); | ||
}); | ||
|
||
it('does not remove targeting when GPC is ON in EU', () => { | ||
(navigator as any).globalPrivacyControl = true; | ||
expect( | ||
applyGpcToCookiePref({ region: Region.EU, consent: [TrackingCategory.TARGETING] }) | ||
).toEqual({ | ||
region: Region.EU, | ||
consent: [TrackingCategory.TARGETING], | ||
}); | ||
}); | ||
|
||
it('retains targeting when GPC is OFF', () => { | ||
(navigator as any).globalPrivacyControl = false; | ||
expect( | ||
applyGpcToCookiePref({ region: Region.DEFAULT, consent: [TrackingCategory.TARGETING] }) | ||
).toEqual({ | ||
region: Region.DEFAULT, | ||
consent: [TrackingCategory.TARGETING], | ||
}); | ||
}); | ||
|
||
it('retains targeting when GPC is undefined', () => { | ||
delete (navigator as any).globalPrivacyControl; | ||
expect( | ||
applyGpcToCookiePref({ region: Region.DEFAULT, consent: [TrackingCategory.TARGETING] }) | ||
).toEqual({ | ||
region: Region.DEFAULT, | ||
consent: [TrackingCategory.TARGETING], | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import { Region, TrackingCategory, TrackingPreference } from '../types'; | ||
|
||
// { region: Region.DEFAULT, consent: ['necessary', 'performance', 'functional', 'targeting'] } | ||
const applyGpcToCookiePref = (preference: TrackingPreference): TrackingPreference => { | ||
// We are only applying GPC in non-EU countries at this point | ||
if (preference.region == Region.EU) { | ||
return preference; | ||
} | ||
|
||
if (!(navigator as any).globalPrivacyControl) { | ||
return preference; | ||
} | ||
// If the user had opted in to GPC we want to honor it | ||
const categories = preference.consent.filter((cat) => cat !== TrackingCategory.TARGETING); | ||
|
||
if (categories == preference.consent) { | ||
return preference; | ||
} | ||
const pref = { region: preference.region, consent: categories }; | ||
|
||
return pref; | ||
}; | ||
|
||
export { applyGpcToCookiePref }; |
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 |
---|---|---|
|
@@ -1077,42 +1077,6 @@ | |
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" | ||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== | ||
|
||
"@coinbase/[email protected]": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/@coinbase/cookie-banner/-/cookie-banner-1.0.1.tgz#90a10f13b62356baca41117cbcf98a20bff7e1cd" | ||
integrity sha512-tVgNjNaSCC7nts/uju+vWkucWyXPSL4CaZflc5rkLuEKb7ZnY0otZnqDPRx0O4/0xLQ72tY9nw41/+HhTsKOqg== | ||
dependencies: | ||
"@coinbase/cookie-manager" "^1.0.0" | ||
react-intl "^6.5.1" | ||
styled-components "^5.3.6" | ||
|
||
"@coinbase/[email protected]": | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/@coinbase/cookie-banner/-/cookie-banner-1.0.3.tgz#a755e4ac9ffa0f3bfe22fc84ec4d88863ad82ad3" | ||
integrity sha512-RMCyb42Ja4vxdZlN8tsFQaQgZUJwx7yvSFZeMnArQyHlKOjpzvJ+NCXY3G4aVYEGC0j86otsZ5Xe43F+qs2MYw== | ||
dependencies: | ||
"@coinbase/cookie-manager" "1.1.1" | ||
react-intl "^6.5.1" | ||
styled-components "^5.3.6" | ||
|
||
"@coinbase/[email protected]": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@coinbase/cookie-manager/-/cookie-manager-1.1.0.tgz#3a47a89989953e0cb32b6b63445879252e42477b" | ||
integrity sha512-r8UR7jSYxAPKIV7jSlqkmWfWi7kdcfMo7hJ0dV0FF2wMx1IIMU6V72BmuMpmn7Ov7HizAKtEcl/I/9fSWRVIQw== | ||
dependencies: | ||
"@coinbase/cookie-banner" "1.0.1" | ||
"@coinbase/cookie-manager" "1.1.0" | ||
js-cookie "^3.0.5" | ||
|
||
"@coinbase/[email protected]": | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/@coinbase/cookie-manager/-/cookie-manager-1.1.1.tgz#f204ade281a2e2dccdf6e77baa7433cd054656a4" | ||
integrity sha512-1fjLrWOyM2392eaDdgqIHlZHGuziRRzQZib3RuYSTdrX9z81muDc/oSvakb6VeDtfZkje0+3MHhnkSscaa5tUg== | ||
dependencies: | ||
"@coinbase/cookie-banner" "1.0.1" | ||
"@coinbase/cookie-manager" "1.1.0" | ||
js-cookie "^3.0.5" | ||
|
||
"@cspotcode/source-map-support@^0.8.0": | ||
version "0.8.1" | ||
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" | ||
|