Skip to content

Commit

Permalink
[fix] Initialize Cookie Values (#7)
Browse files Browse the repository at this point in the history
* [fix] Initialize Cookie Values

* convert cookieValues to a state variable
  • Loading branch information
Sneh1999 authored Jan 8, 2024
1 parent 5a07158 commit 5f30efd
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
4 changes: 2 additions & 2 deletions apps/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test": "jest --passWithNoTests"
},
"dependencies": {
"@coinbase/cookie-banner": "1.0.2",
"@coinbase/cookie-manager": "1.1.0",
"@coinbase/cookie-banner": "1.0.3",
"@coinbase/cookie-manager": "1.1.1",
"next": "14.0.0",
"react": "^18",
"react-dom": "^18"
Expand Down
6 changes: 6 additions & 0 deletions packages/cookie-banner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.2 (01/05/2024)

#### Bug

- Update the cookie manager version

## 1.0.2 (12/11/2023 PST)

#### Chore
Expand Down
4 changes: 2 additions & 2 deletions packages/cookie-banner/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coinbase/cookie-banner",
"version": "1.0.2",
"version": "1.0.3",
"main": "dist/index.js",
"license": "Apache-2.0",
"scripts": {
Expand All @@ -26,7 +26,7 @@
"react-dom": "^18.1.0"
},
"dependencies": {
"@coinbase/cookie-manager": "1.1.0",
"@coinbase/cookie-manager": "1.1.1",
"react-intl": "^6.5.1",
"styled-components": "^5.3.6"
}
Expand Down
8 changes: 8 additions & 0 deletions packages/cookie-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# Changelog

## 1.1.1 (01/05/2024)

#### Bug

- Initialized the Cookie values

## 1.1.0 (12/14/2023)

#### 🚀 Updates

- Updated cookie config to include retention durations at both category and cookie levels.
- Introduced an optional boolean field `sessionCookie` in cookie config to accommodate session cookies.
- Implemented a setExpiryForCookie hook that adjusts the cookie's expiration in the following manner:
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.0",
"version": "1.1.1",
"description": "Coinbase Cookie Manager",
"main": "dist/index.js",
"license": "Apache-2.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/cookie-manager/src/CookieContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Cookies, { CookieAttributes } from 'js-cookie';
import React, { createContext, useCallback, useContext, useEffect } from 'react';
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';

import {
ADVERTISING_SHARING_ALLOWED,
Expand Down Expand Up @@ -39,7 +39,7 @@ export const CookieProvider = ({ children }: Props) => {
const { config, region, shadowMode, log, onPreferenceChange } = useTrackingManager();

const POLL_INTERVAL = 500;
let cookieValues: Record<string, any> = {};
const [cookieValues, setCookieValues] = useState(() => getAllCookies());
let trackingPreference: TrackingPreference;
let adTrackingPreference: AdTrackingPreference;

Expand All @@ -63,12 +63,12 @@ export const CookieProvider = ({ children }: Props) => {
const checkCookies = () => {
const currentCookie = getAllCookies();
if (!areRecordsEqual(cookieValues, currentCookie)) {
cookieValues = currentCookie;
trackingPreference = getTrackingPreference(cookieValues, region, config);
adTrackingPreference = getAdTrackingPreference(cookieValues);
setCookieValues(currentCookie);
trackingPreference = getTrackingPreference(currentCookie, region, config);
adTrackingPreference = getAdTrackingPreference(currentCookie);
setGTMVariables(trackingPreference, adTrackingPreference);
const cookiesToRemove: Array<string> = [];
Object.keys(cookieValues).forEach((c) => {
Object.keys(currentCookie).forEach((c) => {
const trackerInfo = getTrackerInfo(c, config);
if (REQUIRED_COOKIE_MANAGER_COOKIES.includes(c)) {
return;
Expand Down

0 comments on commit 5f30efd

Please sign in to comment.