@coinbase/cookie-manager
Advanced tools
Comparing version 1.1.4 to 1.1.5
# Changelog | ||
## 1.1.5 (06/12/2024) | ||
- Added support for initialCookieValues, initialGPCValue | ||
## 1.1.4 (06/11/2024) | ||
@@ -4,0 +8,0 @@ |
@@ -47,3 +47,3 @@ "use strict"; | ||
const CookieProvider = ({ children }) => { | ||
const { config, region, shadowMode, log, onPreferenceChange } = (0, TrackingManagerContext_1.useTrackingManager)(); | ||
const { config, region, shadowMode, log, onPreferenceChange, initialCookieValues, initialGPCValue, } = (0, TrackingManagerContext_1.useTrackingManager)(); | ||
const POLL_INTERVAL = 500; | ||
@@ -54,2 +54,3 @@ const [cookieValues, setCookieValues] = (0, react_1.useState)(() => (0, getAllCookies_1.default)(region)); | ||
let adTrackingPreference; | ||
const gpc = initialGPCValue || false; | ||
const removeCookies = (0, react_1.useCallback)((cookies) => { | ||
@@ -67,11 +68,12 @@ cookies.forEach((c) => { | ||
(0, react_1.useEffect)(() => { | ||
// TODO clean up hydration | ||
if (typeof window !== 'undefined') { | ||
const checkCookies = () => { | ||
const currentCookie = (0, getAllCookies_1.default)(region); | ||
const currentCookie = (0, getAllCookies_1.default)(region, initialCookieValues); | ||
if (priorCookieValue == undefined || !(0, getAllCookies_1.areRecordsEqual)(priorCookieValue, currentCookie)) { | ||
priorCookieValue = currentCookie; | ||
setCookieValues(currentCookie); | ||
// Grab out prefences (they wil have GPC applied if present) | ||
trackingPreference = getTrackingPreference(currentCookie, region, config); | ||
adTrackingPreference = getAdTrackingPreference(currentCookie, region); | ||
// Grab out prefences (they will have GPC applied if present) | ||
trackingPreference = getTrackingPreference(currentCookie, region, config, gpc); | ||
adTrackingPreference = getAdTrackingPreference(currentCookie, region, gpc); | ||
(0, setGTMVariables_1.default)(trackingPreference, adTrackingPreference); | ||
@@ -174,3 +176,3 @@ const cookiesToRemove = []; | ||
}; | ||
const getTrackingPreference = (cookieCache, region, config) => { | ||
const getTrackingPreference = (cookieCache, region, config, gpcDefault) => { | ||
const trackingPreference = region === types_1.Region.EU | ||
@@ -183,6 +185,6 @@ ? cookieCache[constants_1.EU_CONSENT_PREFERENCES_COOKIE] | ||
// Apply GPC when present | ||
return (0, applyGpcToCookiePref_1.applyGpcToCookiePref)(preference); | ||
return (0, applyGpcToCookiePref_1.applyGpcToCookiePref)(preference, gpcDefault || false); | ||
}; | ||
// Do we want to change the ADVERTISING_SHARING_ALLOWED value to clear prior values? | ||
const getAdTrackingPreference = (cookieCache, region) => { | ||
const getAdTrackingPreference = (cookieCache, region, gpcHeader) => { | ||
const adTrackingPreference = cookieCache[constants_1.ADVERTISING_SHARING_ALLOWED]; | ||
@@ -192,8 +194,8 @@ const adTrackingDefault = region === types_1.Region.EU ? { value: 'false' } : { value: 'true' }; | ||
const adPreference = adTrackingPreference || adTrackingDefault; | ||
return (0, applyGpcToAdPref_1.applyGpcToAdPref)(region, adPreference); | ||
return (0, applyGpcToAdPref_1.applyGpcToAdPref)(region, adPreference, gpcHeader || false); | ||
}; | ||
const useCookie = (cookieName) => { | ||
const cookieCache = (0, react_1.useContext)(CookieContext); | ||
const { config, region, log, shadowMode, onError } = (0, TrackingManagerContext_1.useTrackingManager)(); | ||
const trackingPreference = getTrackingPreference(cookieCache, region, config); | ||
const { config, region, log, shadowMode, onError, initialGPCValue } = (0, TrackingManagerContext_1.useTrackingManager)(); | ||
const trackingPreference = getTrackingPreference(cookieCache, region, config, initialGPCValue); | ||
const setCookie = setCookieFunction({ | ||
@@ -200,0 +202,0 @@ cookieName, |
@@ -61,2 +61,4 @@ import { CookieAttributes } from 'js-cookie'; | ||
log: LogFunction; | ||
initialCookieValues?: Record<string, string>; | ||
initialGPCValue?: boolean; | ||
}; | ||
@@ -63,0 +65,0 @@ export type AdTrackingPreference = { |
import { AdTrackingPreference, Region } from '../types'; | ||
declare const applyGpcToAdPref: (region: Region, preference: AdTrackingPreference) => AdTrackingPreference; | ||
declare const applyGpcToAdPref: (region: Region, preference: AdTrackingPreference, gpcHeader?: boolean) => AdTrackingPreference; | ||
export { applyGpcToAdPref }; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyGpcToAdPref = void 0; | ||
const types_1 = require("../types"); | ||
const applyGpcToAdPref = (region, preference) => { | ||
const getGpc_1 = __importDefault(require("./getGpc")); | ||
const applyGpcToAdPref = (region, preference, gpcHeader) => { | ||
// We are only applying GPC in non-EU countries at this point | ||
@@ -10,9 +14,8 @@ if (region == types_1.Region.EU) { | ||
} | ||
if (typeof window === 'undefined' || typeof window.navigator === 'undefined') { | ||
// If the browser is has global privacy control enabled | ||
// we will honor it | ||
const gpc = (0, getGpc_1.default)(gpcHeader); | ||
if (!gpc) { | ||
return preference; | ||
} | ||
// If we lack GPC or it's set ot false we are done | ||
if (!window.navigator.globalPrivacyControl) { | ||
return preference; | ||
} | ||
// If the user already has sharing turned off nothing to do here | ||
@@ -19,0 +22,0 @@ if (preference.value == false) { |
import { TrackingPreference } from '../types'; | ||
declare const applyGpcToCookiePref: (preference: TrackingPreference) => TrackingPreference; | ||
declare const applyGpcToCookiePref: (preference: TrackingPreference, gpcHeader?: boolean) => TrackingPreference; | ||
export { applyGpcToCookiePref }; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applyGpcToCookiePref = void 0; | ||
const types_1 = require("../types"); | ||
const getGpc_1 = __importDefault(require("./getGpc")); | ||
// { region: Region.DEFAULT, consent: ['necessary', 'performance', 'functional', 'targeting'] } | ||
const applyGpcToCookiePref = (preference) => { | ||
const applyGpcToCookiePref = (preference, gpcHeader) => { | ||
// We are only applying GPC in non-EU countries at this point | ||
@@ -11,10 +15,8 @@ if (preference.region == types_1.Region.EU) { | ||
} | ||
// 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') { | ||
// If the browser is has global privacy control enabled | ||
// we will honor it | ||
const gpc = (0, getGpc_1.default)(gpcHeader); | ||
if (!gpc) { | ||
return preference; | ||
} | ||
if (!window.navigator.globalPrivacyControl) { | ||
return preference; | ||
} | ||
// If the user had opted in to GPC we want to honor it | ||
@@ -21,0 +23,0 @@ const categories = preference.consent.filter((cat) => cat !== types_1.TrackingCategory.TARGETING); |
@@ -28,2 +28,3 @@ "use strict"; | ||
exports.deserializeCookies = deserializeCookies; | ||
// TODO clean up hydration | ||
function getAllCookies(region, initialCookies) { | ||
@@ -30,0 +31,0 @@ if (typeof window === 'undefined' && initialCookies) { |
{ | ||
"name": "@coinbase/cookie-manager", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Coinbase Cookie Manager", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -217,2 +217,6 @@ # Cookie Manager | ||
`initialCookieValues?:Record<string, string> `: Useful for server side rendering flows - setting of initial cookie values | ||
`initialGPCValue?:boolean`: Useful for server side rendering flows - honoring of Set-GPC header | ||
Example usage: | ||
@@ -219,0 +223,0 @@ |
@@ -69,2 +69,4 @@ import { CookieAttributes } from 'js-cookie'; | ||
log: LogFunction; | ||
initialCookieValues?: Record<string, string>; | ||
initialGPCValue?: boolean; | ||
}; | ||
@@ -71,0 +73,0 @@ |
import { AdTrackingPreference, Region } from '../types'; | ||
import getGpc from './getGpc'; | ||
const applyGpcToAdPref = ( | ||
region: Region, | ||
preference: AdTrackingPreference | ||
preference: AdTrackingPreference, | ||
gpcHeader?: boolean | ||
): AdTrackingPreference => { | ||
@@ -11,12 +13,9 @@ // We are only applying GPC in non-EU countries at this point | ||
} | ||
if (typeof window === 'undefined' || typeof window.navigator === 'undefined') { | ||
// If the browser is has global privacy control enabled | ||
// we will honor it | ||
const gpc = getGpc(gpcHeader); | ||
if (!gpc) { | ||
return preference; | ||
} | ||
// If we lack GPC or it's set ot false we are done | ||
if (!(window.navigator as any).globalPrivacyControl) { | ||
return preference; | ||
} | ||
// If the user already has sharing turned off nothing to do here | ||
@@ -23,0 +22,0 @@ if (preference.value == false) { |
import { Region, TrackingCategory, TrackingPreference } from '../types'; | ||
import getGpc from './getGpc'; | ||
// { region: Region.DEFAULT, consent: ['necessary', 'performance', 'functional', 'targeting'] } | ||
const applyGpcToCookiePref = (preference: TrackingPreference): TrackingPreference => { | ||
const applyGpcToCookiePref = ( | ||
preference: TrackingPreference, | ||
gpcHeader?: boolean | ||
): TrackingPreference => { | ||
// We are only applying GPC in non-EU countries at this point | ||
@@ -9,11 +13,9 @@ if (preference.region == Region.EU) { | ||
// 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') { | ||
// If the browser is has global privacy control enabled | ||
// we will honor it | ||
const gpc = getGpc(gpcHeader); | ||
if (!gpc) { | ||
return preference; | ||
} | ||
if (!(window.navigator as any).globalPrivacyControl) { | ||
return preference; | ||
} | ||
// If the user had opted in to GPC we want to honor it | ||
@@ -20,0 +22,0 @@ const categories = preference.consent.filter((cat) => cat !== TrackingCategory.TARGETING); |
@@ -28,2 +28,3 @@ import Cookies from 'js-cookie'; | ||
// TODO clean up hydration | ||
export default function getAllCookies(region: Region, initialCookies?: Record<string, string>) { | ||
@@ -30,0 +31,0 @@ if (typeof window === 'undefined' && initialCookies) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141077
109
2935
531