Skip to content

Commit

Permalink
Get cookie data as object
Browse files Browse the repository at this point in the history
- added getter `CookieConsentWrapper.consentCookieData`
- updated CHANGELOG
- updated the package version to `0.4.8-beta.2`
  • Loading branch information
tg666 committed Feb 15, 2024
1 parent 2660936 commit d8a674e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added fields `Integration > CMP API > Default environment` and `Integration > CMP API > Environment code` in the GTM template.
- Added option `evironment` in the `CmpApiOptions`. The environment is taken into account in the integration with CMP.
- Added getter `CookieConsentWrapper.consentCookieData` that returns data from the consent cookie (`cc-settings` by default) as an object or null if the consent doesn't exists.

### Changed

- Credentials are now omitted in CPM integration requests.

## [0.4.7] - 2023-10-04

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "68publishers-cookie-consent",
"version": "0.4.8-beta.1",
"version": "0.4.8-beta.2",
"description": "Cookie consent wrapper based on orestbida/cookieconsent with GTM integration.",
"homepage": "http://www.68publishers.io/",
"main": "index.js",
Expand Down
22 changes: 22 additions & 0 deletions src/CookieConsentWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ class CookieConsentWrapper {
return this._cookieTables;
}

get consentCookieData() {
const cookieName = this._config.pluginOptions.cookie_name;
let cookieValue = document.cookie.match("(^|;)\\s*" + cookieName + "\\s*=\\s*([^;]+)");
cookieValue = cookieValue ? cookieValue.pop() : null;

if (null === cookieValue) {
return null;
}

try{
cookieValue = JSON.parse(cookieValue)
} catch (e) {
try {
cookieValue = JSON.parse(decodeURIComponent(cookieValue))
} catch (e) {
cookieValue = null;
}
}

return cookieValue;
}

setStaticUserIdentity(id) {
this._user = this.user.withStaticIdentity(id);
}
Expand Down

0 comments on commit d8a674e

Please sign in to comment.