Browser Console Utilities For Developers
We have several helper functions that you can use to test or debug DataGrail Consent on your website. Use these commands within the browser console.
Show The Consent Banner
window.DG_BANNER_API.showConsentBanner()
Instantly reveals the Consent banner layout rendered on the page, based on your policy settings.
Show a Banner Layer
window.DG_BANNER_API.showLayer('[banner_api_id]')
Instantly reveals the specific Consent banner layer within the layout delivered to your website, based on your policy settings.
Hide The Consent Banner
window.DG_BANNER_API.hideConsentBanner()
Instantly hides the Consent banner on your website.
Check Consent Status
window.DG_BANNER_API.getConsentPreferences()
Returns an JSON object containing an array of the status of consent for each category purpose.
You can also use the following command:
window.DG_BANNER_API.getCategories()
Check if a Category is Enabled
window.DG_BANNER_API.categoryEnabled([CATEGORY])
Returns true
if the category key provided was given consent, either via policy or banner notice interaction.
Possible [CATEGORY]
values are: essential
, performance
, marketing
, functional
Get Consent Configuration
window.DG_BANNER_API.config()
Returns a JSON object of the current configuration of Consent delivered to the current website.
The response body contains several values useful for self-serve debugging purposes:
consentMode
- the current policy behavior for Consent, based on your geolocation. Can be set to one of the two following values:optout
- the data subject is currently being tracked and must opt-out of trackingoptin
- the data subject is not being tracked and must opt-in to being tracked
showBanner
- returnstrue
if the banner is set to show on first page load, based on your policy settings.consentPolicy
- the current policy that guides both theconsentMode
andshowBanner
values.layout
- this object returns the configuration set for eachlayer
that is rendered on the page. Of particular note is thebanner_api_id
for each layer, which you can use to show a specific layer using theshowConsentBanner()
function above.plugins
- reports if DataGrail Consent plugins are active:scriptControl
- manages custom, inline scriptscookieBlocking
- will block cookies based on managed rules created within DataGrail.
Get Unmanaged Scripts
ScriptControl is the DataGrail Consent plugin that manages inline scripts configured with DataGrail Consent. You can use the following commands to report on the scripts DataGrail are either managed or unmanaged.
- Managed scripts are those that contain a
data-consent-id
and, thus, will be set to execute or not based on a consent preference or policy setting. - Unmanaged scripts do not contain a
data-consent-id
, so they will not be controlled by DataGrail Consent.
It is useful to run the following command to see if there are any scripts on your site that would be eligible for management:
window.DG_BANNER_API.plugins.scriptControl.unmanagedScripts()
Some of these scripts may be managed via an integration, so you may not necessarily need to use ScriptControl for all reported scripts.
Check if a GPC Signal is Enabled
window.navigator.globalPrivacyControl
DataGrail Consent rejects all non-essential trackers if set to true
.
Check Current GTM Container
const searchScript = "www.googletagmanager.com/gtm.js", searchQSKey = "id=";
Array.from(document.querySelectorAll("script")).filter((x) => {
if (x.src.includes(searchScript)) {
let index_start = x.src.indexOf(searchQSKey) + searchQSKey.length;
let index_end = x.src.indexOf("&", index_start);
index_end = index_end == -1 ? x.src.length : index_end;
let search_value = x.src.substring(index_start, index_end);
console.log(x.src, search_value);
}
});
This will enumerate each container URL and container ID embedded within the website's page code. Here's an example output for DataGrail's website:
https://www.googletagmanager.com/gtm.js?id=GTM-K4JV5F7 GTM-K4JV5F7
Disclaimer: The information contained in this message does not constitute as legal advice. We would advise seeking professional counsel before acting on or interpreting any material.