@onsvisual/svelte-components 0.1.91 → 0.1.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -52,16 +52,46 @@
|
|
|
52
52
|
return -1 < document.cookie.indexOf("cookies_preferences_set=true");
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// extractValue extracts the value from a undecodeable json cookie string
|
|
56
|
+
function extractValue(key, extractionString) {
|
|
57
|
+
const extractionRegex = new RegExp(`'${key}':(.*?)[,}]`);
|
|
58
|
+
const match = extractionString.match(extractionRegex);
|
|
59
|
+
if (match) {
|
|
60
|
+
return match[1];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
// Check if usage cookies are allowed (for Google Analytics + Hotjar)
|
|
67
|
+
// note: this ported function returns the inverse truth value to the dp-renderer code that it's based on
|
|
68
|
+
// ----------------------
|
|
69
|
+
// getUsageCookieValue reads the legacy cookies_policy and ons_cookies_policy to determine the user's usage preference.
|
|
70
|
+
// The legacy policy takes precedence over the new policy. When no policy is found, the user is opted out by default.
|
|
56
71
|
function getUsageCookieValue() {
|
|
57
|
-
|
|
72
|
+
// TODO: this is the legacy cookie (cookies_policy) handling and will be removed in due course
|
|
73
|
+
var legacyPolicyCookie = document.cookie.match(
|
|
58
74
|
new RegExp("(^|;) ?cookies_policy=([^;]*)(;|$)")
|
|
59
75
|
);
|
|
60
|
-
if (
|
|
61
|
-
|
|
76
|
+
if (legacyPolicyCookie) {
|
|
77
|
+
console.debug("legacy cookies_policy found");
|
|
78
|
+
var decodedCookie = decodeURIComponent(legacyPolicyCookie[2]);
|
|
62
79
|
var cookieValue = JSON.parse(decodedCookie);
|
|
80
|
+
console.debug("usage is", cookieValue.usage);
|
|
63
81
|
return cookieValue.usage;
|
|
64
82
|
}
|
|
83
|
+
|
|
84
|
+
// ons_cookie_policy handler
|
|
85
|
+
var policyCookie = document.cookie.match("(?:^|; )ons_cookie_policy=({.*?})");
|
|
86
|
+
if (policyCookie) {
|
|
87
|
+
console.debug("ons_cookie_policy found");
|
|
88
|
+
|
|
89
|
+
var usageValue = extractValue("usage", policyCookie[1]);
|
|
90
|
+
console.debug("usage is", usageValue);
|
|
91
|
+
|
|
92
|
+
return usageValue === "true";
|
|
93
|
+
}
|
|
94
|
+
console.debug("no cookie found - opting out");
|
|
65
95
|
return false;
|
|
66
96
|
}
|
|
67
97
|
|