diff --git a/apps/example/package.json b/apps/example/package.json index 88455bc..d4216dc 100644 --- a/apps/example/package.json +++ b/apps/example/package.json @@ -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" diff --git a/packages/cookie-banner/package.json b/packages/cookie-banner/package.json index c49fd7e..907b138 100644 --- a/packages/cookie-banner/package.json +++ b/packages/cookie-banner/package.json @@ -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" } diff --git a/packages/cookie-manager/CHANGELOG.md b/packages/cookie-manager/CHANGELOG.md index 99a00d8..c0556f8 100644 --- a/packages/cookie-manager/CHANGELOG.md +++ b/packages/cookie-manager/CHANGELOG.md @@ -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 diff --git a/packages/cookie-manager/package.json b/packages/cookie-manager/package.json index eb9d92f..a74f878 100644 --- a/packages/cookie-manager/package.json +++ b/packages/cookie-manager/package.json @@ -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", diff --git a/packages/cookie-manager/src/utils/applyGpcToAdPref.ts b/packages/cookie-manager/src/utils/applyGpcToAdPref.ts index df36dfc..fd07934 100644 --- a/packages/cookie-manager/src/utils/applyGpcToAdPref.ts +++ b/packages/cookie-manager/src/utils/applyGpcToAdPref.ts @@ -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; } diff --git a/packages/cookie-manager/src/utils/applyGpcToCookiePref.ts b/packages/cookie-manager/src/utils/applyGpcToCookiePref.ts index 3cda347..e0b02e2 100644 --- a/packages/cookie-manager/src/utils/applyGpcToCookiePref.ts +++ b/packages/cookie-manager/src/utils/applyGpcToCookiePref.ts @@ -1,5 +1,4 @@ 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 @@ -7,7 +6,13 @@ const applyGpcToCookiePref = (preference: TrackingPreference): TrackingPreferenc 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 diff --git a/packages/cookie-manager/src/utils/isMaxKBSize.ts b/packages/cookie-manager/src/utils/isMaxKBSize.ts index efb3e66..f6f4add 100644 --- a/packages/cookie-manager/src/utils/isMaxKBSize.ts +++ b/packages/cookie-manager/src/utils/isMaxKBSize.ts @@ -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;