UNPKG

@schibsted/sourcepoint

Version:

Package containing scripts used by Schibsteds' sites to integrate with Sourcepoint CMP

34 lines (27 loc) 1.19 kB
export function isNativeConsentPassed(_window) { const searchParams = new URLSearchParams(_window.location?.search); const hasConsentParam = searchParams.has('_sp_pass_consent'); try { if (hasConsentParam) { _window.sessionStorage.setItem('_sp_pass_consent', 'true'); return true; } const storedConsent = _window.sessionStorage.getItem('_sp_pass_consent'); if (storedConsent === 'true') { searchParams.set('_sp_pass_consent', 'true'); const newUrl = `${_window.location.pathname}?${searchParams.toString()}${_window.location.hash}`; _window.history.replaceState({}, '', newUrl); return true; } } catch (e) { return hasConsentParam; } return false; } const mobileWebViewUa = ['Hermes', '_app_', 'tv.nu', 'FinnApp', 'Omni']; export function isWebView(_navigator) { return mobileWebViewUa.some((webviewAgent) => _navigator.userAgent.includes(webviewAgent)); }; export function checkIfShouldDisableOnWebview(window, navigator, config) { return isWebView(navigator) && !config.disableNativeConsentCheck && !isNativeConsentPassed(window) };