File size: 1,370 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import { TrackingPrefs, isCountryInGdprZone } from '@automattic/calypso-analytics';
import { isE2ETest } from 'calypso/lib/e2e';
import { isWpMobileApp, isWcMobileApp } from 'calypso/lib/mobile-app';
const isServer = typeof document === 'undefined';
/**
* Returns a boolean indicating whether a GDPR banner should be shown.
*
* Defaults to `false` if the country code is unknown.
* @param countryCode Country code determined either from cookie or from a special header
* @param trackingPrefs Parsed object based on `sensitive_pixel_options` (v2) cookie structure
* @returns Whether the current user could be in the GDPR zone. When the `countryCode` are
* `undefined`, we return `null` which has a meaning of "result unknown".
*/
export default function shouldSeeCookieBanner(
countryCode?: string,
trackingPrefs?: TrackingPrefs
): boolean {
// the banner is not shown for pages embedded as web view inside the mobile app or during e2e tests
if ( isWpMobileApp() || isWcMobileApp() || ( ! isServer && isE2ETest() ) ) {
return false;
}
// the request for consent has already been answered, we no longer need to ask
if ( trackingPrefs?.ok ) {
return false;
}
// if we had issues fetching geo cookies (`countryCode`), fail safe and show the banner
if ( countryCode === undefined ) {
return true;
}
return isCountryInGdprZone( countryCode );
}
|