Skip to content
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

Cleaning up for server side render clients #17

Merged
merged 5 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@coinbase/cookie-banner": "1.0.4",
"@coinbase/cookie-manager": "1.1.3",
"@coinbase/cookie-manager": "1.1.4",
"next": "14.1.1",
"react": "^18",
"react-dom": "^18"
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie-banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"react-dom": "^18.1.0"
},
"dependencies": {
"@coinbase/cookie-manager": "^1.1.3",
"@coinbase/cookie-manager": "^1.1.4",
"react-intl": "^6.5.1",
"styled-components": "^5.3.6"
}
Expand Down
7 changes: 7 additions & 0 deletions packages/cookie-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 1.1.4 (06/11/2024)

- Updated next version from 14.0.0 to 14.1.1
- Updated braces from 3.0.2 to 3.0.3
- Removed call to Buffer
- Ensure navigator is defined before referencing

## 1.1.3 (05/03/2024)

- Added logic to honor GCP in non-EU localities
Expand Down
2 changes: 1 addition & 1 deletion packages/cookie-manager/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/cookie-manager",
"version": "1.1.3",
"version": "1.1.4",
"description": "Coinbase Cookie Manager",
"main": "dist/index.js",
"license": "Apache-2.0",
Expand Down
7 changes: 6 additions & 1 deletion packages/cookie-manager/src/utils/applyGpcToAdPref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ const applyGpcToAdPref = (
if (region == Region.EU) {
return preference;
}

if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
return preference;
}

// If we lack GPC or it's set ot false we are done
if (!(navigator as any).globalPrivacyControl) {
if (!(window.navigator as any).globalPrivacyControl) {
return preference;
}

Expand Down
9 changes: 7 additions & 2 deletions packages/cookie-manager/src/utils/applyGpcToCookiePref.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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) {
// TODO: We want to support server side render flows
// where the user can set an initial value and indicate that gpc has been enabled
if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
return preference;
}

if (!(window.navigator as any).globalPrivacyControl) {
return preference;
}
// If the user had opted in to GPC we want to honor it
Expand Down
4 changes: 3 additions & 1 deletion packages/cookie-manager/src/utils/isMaxKBSize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { KB } from '../constants';

const isMaxKBSize = (str: string, max: number) => {
return Buffer.from(str).length / KB > max;
// length value contains the length of the string in UTF-16 code units.
// each code unit is 2 bytes wide
return (str.length * 2) / KB > max;
};

export default isMaxKBSize;
Loading