Skip to content

Commit

Permalink
Add option to set the cookie domain
Browse files Browse the repository at this point in the history
  • Loading branch information
cphilleo committed May 9, 2019
1 parent b48a5ab commit 0ce5b36
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ For detailed explanations, please visit the [documentation](https://oil.axelspri
| advanced_settings | Replaces the No Button with an advanced settings button, displaying the Cookie Preference Center. The CPC enables the user to choose their own level of privacy. These settings are stored in the oil cookie (both SOI and POI) as well. | False
| advanced_settings_purposes_default | All purposes in the advanced settings layer should be activated by default | false
| config_version | Specifies the version of your OIL configuration. It will be stored with the consent cookie to track which explicit configuration version consent was granted for.| None
| cookie_domain | Specifies the domain to write the cookie to. Can be used to set the cookie on a valid parent domain: e.g sub.example.com -> .example.com. | Current hostname
| cookie_expires_in_days | Value in days until the domain cookie used to save the users decision in days | 31
| cpc_type | Specifies the type (the layout) of the Cookie Preference Center. Currently, two types are supported: 'standard' and 'tabs'. Depending on this parameter additional label configuration may be necessary. See section <<Full Label Configuration>> for details. | standard
| customPurposes | Array of custom purposes defined by publisher. IDs for custom purposes may range from 25-88. | None
Expand Down
1 change: 1 addition & 0 deletions docs/src/docs/03-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ This is a full list of configurable options.
| advanced_settings_purposes_default | All purposes in the advanced settings layer should be activated by default | false
| config_version | Specifies the version of your OIL configuration. It will be stored with the consent cookie to track which explicit configuration version consent was granted for.| None
| cookie_expires_in_days | Value in days until the domain cookie used to save the users decision in days | 31
| cookie_domain | Specifies the domain to write the cookie to. Can be used to set the cookie on a valid parent domain: e.g sub.example.com -> .example.com. | Current hostname
| cpc_type | Specifies the type (the layout) of the Cookie Preference Center. Currently, two types are supported: 'standard' and 'tabs'. Depending on this parameter additional label configuration may be necessary. See section <<Full Label Configuration>> for details. | standard
| customPurposes | Array of custom purposes defined by publisher. IDs for custom purposes may range from 25-88. | None
| customVendorListUrl | Custom vendor list ('non IAB vendors') to use, will be loaded at the same time as the iabVendorList. | None
Expand Down
4 changes: 4 additions & 0 deletions src/scripts/core/core_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ export function getCookieExpireInDays() {
return getConfigValue(OIL_CONFIG.ATTR_COOKIE_EXPIRES_IN_DAYS, 31);
}

export function getCookieDomain() {
return getConfigValue(OIL_CONFIG.ATTR_COOKIE_DOMAIN, '');
}

export function getLocaleVariantName() {
const defaultLocaleId = 'enEN_01';
let localeVariantName = getLocale();
Expand Down
1 change: 1 addition & 0 deletions src/scripts/core/core_constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const OIL_CONFIG = {
ATTR_HUB_LOCATION: 'poi_hub_location', // complete hub location, gets generated
ATTR_PREVIEW_MODE: 'preview_mode',
ATTR_COOKIE_EXPIRES_IN_DAYS: 'cookie_expires_in_days',
ATTR_COOKIE_DOMAIN: 'cookie_domain',
ATTR_TIMESTAMP: 'timestamp',
ATTR_PRIVACY_PAGE_URL: 'privacy_page_url',
ATTR_POI_GROUP_NAME: 'poi_group_name',
Expand Down
11 changes: 6 additions & 5 deletions src/scripts/core/core_cookies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Cookie from 'js-cookie';
import { logInfo } from './core_log';
import { getConfigVersion, getCookieExpireInDays, getCustomPurposes, getDefaultToOptin, getLanguage, getLanguageFromLocale, getLocaleVariantName } from './core_config';
import { getConfigVersion, getCookieExpireInDays, getCookieDomain, getCustomPurposes, getDefaultToOptin, getLanguage, getLanguageFromLocale, getLocaleVariantName } from './core_config';
import { getLocaleVariantVersion } from './core_utils';
import { OIL_CONFIG_DEFAULT_VERSION, OIL_SPEC } from './core_constants';
import { getCustomVendorListVersion, getLimitedVendorIds, getPurposes, getVendorList, loadVendorListAndCustomVendorList } from './core_vendor_lists';
Expand All @@ -18,10 +18,10 @@ export function setSessionCookie(name, value) {
Cookie.set(name, value);
}

export function setDomainCookie(name, value, expires_in_days) {
export function setDomainCookie(name, value, expires_in_days, domain) {
// decoded consent data must not be written to the cookie
delete value.consentData;
Cookie.set(name, value, {expires: expires_in_days});
Cookie.set(name, value, {expires: expires_in_days, domain: domain});
}

export function getOilCookie(cookieConfig) {
Expand Down Expand Up @@ -84,7 +84,7 @@ export function setSoiCookieWithPoiCookieData(poiCookieJson) {
consentString: consentString,
configVersion: configVersion
};
setDomainCookie(cookieConfig.name, cookie, cookieConfig.expires);
setDomainCookie(cookieConfig.name, cookie, cookieConfig.expires, cookieConfig.domain);
resolve(cookie);
}).catch(error => reject(error));
});
Expand Down Expand Up @@ -115,7 +115,7 @@ export function buildSoiCookie(privacySettings) {
export function setSoiCookie(privacySettings) {
return new Promise((resolve, reject) => {
buildSoiCookie(privacySettings).then((cookie) => {
setDomainCookie(OIL_DOMAIN_COOKIE_NAME, cookie, getCookieExpireInDays());
setDomainCookie(OIL_DOMAIN_COOKIE_NAME, cookie, getCookieExpireInDays(), getCookieDomain());
resolve(cookie);
}).catch(error => reject(error));
});
Expand Down Expand Up @@ -257,6 +257,7 @@ function getOilCookieConfig() {
return {
name: OIL_DOMAIN_COOKIE_NAME,
expires: getCookieExpireInDays(),
domain: getCookieDomain(),
defaultCookieContent: {
opt_in: false,
version: OilVersion.get(),
Expand Down

0 comments on commit 0ce5b36

Please sign in to comment.