Last active
February 12, 2025 07:03
-
-
Save prabapro/8ee6ac539bfc081b513aed911e9dfc8d to your computer and use it in GitHub Desktop.
Log Google Consent Mode v2 status to the browser console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (()=>{l=e=>void 0==e?"":e?"granted":"denied",c=e=>"granted"==e?"color: #0C0":"color: #C00";let e={ad_personalization:"Marketing",ad_storage:"Marketing",ad_user_data:"Marketing",analytics_storage:"Statistics",functionality_storage:"Necessary",security_storage:"Necessary",personalization_storage:"Preferences"};if(!window.google_tag_data){console.warn("No Consent Mode data found");return}var t="ics"in google_tag_data?google_tag_data.ics.entries:null;if(!t){console.log("No Consent Mode data available");return}let a={};Object.keys(t).forEach(t=>{let o=e[t]||"Other";a[o]||(a[o]=[]),a[o].push(t)});let o=Object.keys(a).sort();console.log("%cGoogle Consent Mode v2 Status:","font-size: 1rem");let n=!1;o.forEach(e=>{console.log(`%c | |
| ${e}:`,"font-weight: bold"),a[e].sort().forEach(e=>{let a=l(t[e].default),o=l(t[e].update);if(""==a&&""==o)return;n=!0;let r=" "+e+":"+(""!=a?"\n Default: %c"+a:"%c")+"%c"+(""!=o?"\n Update: %c"+o:"%c");console.log(r,""!=a?c(a):"","",""!=o?c(o):"","")})}),n||console.log("No default Consent settings found")})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment