dvConsentDomain function
domain as dartvel.analytics.consent.domain gives it, checked: lower
case, without a leading dot; null when not given. A public suffix, an
address or anything that is not a host name is refused, since a browser
drops a cookie for it without a word.
Implementation
String? dvConsentDomain(String? domain) {
if (domain == null) return null;
String name = domain.trim().toLowerCase();
if (name.startsWith('.')) name = name.substring(1);
if (dvIsPublicSuffix(name)) {
throw ArgumentError.value(domain, 'domain',
'is a public suffix; a browser refuses a cookie for it, so consent '
'could not be shared. Name the site\'s own domain, such as example.com');
}
if (!RegExp(r'^[a-z0-9-]+(\.[a-z0-9-]+)+$').hasMatch(name) ||
RegExp(r'^[0-9.]+$').hasMatch(name) ||
dvRegistrableDomain(name) == null) {
throw ArgumentError.value(domain, 'domain',
'is not a domain name the hosts can share a cookie under, such as example.com');
}
return name;
}