Browser Console Utilities
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.
Banner Visibility
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.
Consent Preferences
Get Consent Preferences
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()
Set Consent Preferences
window.DG_BANNER_API.setConsentPreferences(preferences, config)
Sets the consent preferences for a user.
This function accepts the following parameters:
-
preferencesis a JSON object containing an array of the status of consent for each category purpose. This parameter follows the same structure as the output ofgetConsentPreferences(){
"isCustomised": true,
"cookieOptions": [
{
"gtm_key": "dg-category-essential",
"isEnabled": true
},
{
"gtm_key": "dg-category-functional",
"isEnabled": false
},
{
"gtm_key": "dg-category-marketing",
"isEnabled": false
},
{
"gtm_key": "dg-category-performance",
"isEnabled": false
}
]
} -
configis a JSON object that accepts therunPreferenceCallbacksboolean that determines whether configured callbacks should be run after preferences are set.{ "runPreferenceCallbacks": false }
Get Category Status
window.DG_BANNER_API.categoryEnabled('<CATEGORY>')
Returns true if the category key provided was given consent, either via policy or banner notice interaction.
Valid <CATEGORY> replacements are: essential, performance, marketing, functional
Configuration & Debugging
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- returnstrueif the banner is set to show on first page load, based on your policy settings.consentPolicy- the current policy that guides both theconsentModeandshowBannervalues.layout- this object returns the configuration set for eachlayerthat is rendered on the page. Of particular note is thebanner_api_idfor 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-idand, 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 commands to see if there are any scripts on your site that would be eligible for management:
window.DG_BANNER_API.plugins.scriptControl.unmanagedScripts()
window.DG_BANNER_API.plugins.scriptControl.managedScripts()
Some of these scripts may be managed via an integration, so you may not necessarily need to use ScriptControl for all reported scripts.
Get 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
Get Configured Cookie Rules
this.DG_BANNER_API.getCategories().flatMap((c) => c.cookie_patterns)
Returns a list of Cookie Rules configured on the site.
Privacy & Compliance
Get GPC Signal Status
window.navigator.globalPrivacyControl
DataGrail Consent rejects all non-essential trackers if set to true.
Get US Privacy String
window.DG_BANNER_API.getUSPrivacyString()
Returns the IAB US Privacy String (CCPA compliance format) indicating whether a user has opted out of data sales based on their consent preferences.
Return values:
1YNN- User consented to marketing (did NOT opt out)1YYN- User opted out of marketing (restricted targeted advertising)
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.