Skip to content

Commit d5223e0

Browse files
committed
feat: store language code of the consent in the cookie
1 parent f87853b commit d5223e0

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

docs/reference/api-reference.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ Returns the plugin's own cookie, or just one of the fields.
343343
consentId: string
344344
consentTimestamp: string,
345345
lastConsentTimestamp: string,
346+
languageCode: string,
346347
services: {[key: string]: string[]}
347348
}
348349
```
@@ -514,4 +515,4 @@ Reset CookieConsent.
514515
- **Example**:
515516
```javascript
516517
CookieConsent.reset(true);
517-
```
518+
```

src/utils/cookies.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ export const saveCookiePreferences = () => {
166166
data: state._cookieData,
167167
consentTimestamp: state._consentTimestamp.toISOString(),
168168
consentId: state._consentId,
169-
services: deepCopy(state._acceptedServices)
169+
services: deepCopy(state._acceptedServices),
170+
languageCode: globalObj._state._currentLanguageCode
170171
};
171-
172+
172173
if (state._lastConsentTimestamp) {
173174
state._savedCookieContent.lastConsentTimestamp = state._lastConsentTimestamp.toISOString();
174175
}
@@ -399,4 +400,4 @@ export const getAllCookies = (regex) => {
399400
}
400401

401402
return cookieNames;
402-
};
403+
};

tests/cookies.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe("Cookie should be created successfully", () => {
3232
expect(typeof ccCookie.consentId).toBe('string');
3333
expect(ccCookie.consentTimestamp).toBeDefined();
3434
expect(ccCookie.lastConsentTimestamp).toBeDefined();
35+
expect(ccCookie.languageCode).toEqual('en');
3536
expect(ccCookie.categories).toEqual(['necessary', 'analytics', 'ads']);
3637
expect(ccCookie.services).toMatchObject({
3738
necessary: ['service1'],
@@ -64,4 +65,4 @@ describe("Cookie should be created successfully", () => {
6465
expect(allCookies.length).toBe(2);
6566
expect(allCookies).toContain('service1Cookie1', 'service1Cookie2');
6667
})
67-
})
68+
})

types/index.d.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ declare namespace CookieConsent {
175175
*/
176176
lastConsentTimestamp: string
177177

178+
/**
179+
* Language code of the consent.
180+
*/
181+
languageCode: string
182+
178183
/**
179184
* All enabled services.
180185
*/
@@ -214,10 +219,10 @@ declare namespace CookieConsent {
214219
* @default 'Lax'
215220
*/
216221
sameSite?: 'Lax' | 'Strict' | 'None'
217-
222+
218223
/**
219224
* Cookie secure flag.
220-
*
225+
*
221226
* @default true
222227
*/
223228
secure?: boolean
@@ -688,4 +693,4 @@ declare global {
688693
interface Window {
689694
CookieConsent: typeof CookieConsent
690695
}
691-
}
696+
}

0 commit comments

Comments
 (0)