1+ const COOKIE_CONSENT_NECESSARY = 1 ;
2+ const COOKIE_CONSENT_PERFORMANCE = 2 ;
3+ const COOKIE_CONSENT_FUNCTIONAL = 3 ;
4+ const COOKIE_CONSENT_ADVERTISING = 4 ;
5+
6+ function addScripts ( lvl ) {
7+ //Reject all
8+ if ( ! lvl ) {
9+ return ;
10+ }
11+
12+ // Necessary
13+ if ( lvl . includes ( COOKIE_CONSENT_NECESSARY ) ) {
14+ // GTM
15+ ( function ( w , d , s , l , i ) {
16+ w [ l ] = w [ l ] || [ ] ;
17+ w [ l ] . push ( {
18+ 'gtm.start' : new Date ( ) . getTime ( ) ,
19+ event : 'gtm.js'
20+ } ) ;
21+ var f = d . getElementsByTagName ( s ) [ 0 ] ,
22+ j = d . createElement ( s ) ,
23+ dl = l != 'dataLayer' ? '&l=' + l : '' ;
24+ j . async = true ;
25+ j . src =
26+ '//www.googletagmanager.com/gtm.js?id=' + i + dl ;
27+ f . parentNode . insertBefore ( j , f ) ;
28+ } ) ( window , document , 'script' , 'dataLayer' , 'GTM-W7FRLJ' ) ;
29+ }
30+
31+ // Functional
32+ if ( lvl . includes ( COOKIE_CONSENT_FUNCTIONAL ) ) {
33+ ( function ( d , s , id ) {
34+ var js , fjs = d . getElementsByTagName ( s ) [ 0 ] ,
35+ p = / ^ h t t p : / . test ( d . location ) ? 'http' : 'https' ;
36+ if ( ! d . getElementById ( id ) ) {
37+ js = d . createElement ( s ) ;
38+ js . id = id ;
39+ js . src = p + '://platform.twitter.com/widgets.js' ;
40+ fjs . parentNode . insertBefore ( js , fjs ) ;
41+ }
42+ } ) ( document , 'script' , 'twitter-wjs' ) ;
43+ }
44+ }
45+
46+ // Add required scripts without waiting for the user consent
47+ addScripts ( window . OnetrustActiveGroups ) ;
48+
49+ // Poll for the consent being onscreen.
50+ const POLL_MAX = 10 ;
51+ const POLL_INTERVAL = 200 ;
52+ let tries = 0 ;
53+ const poll = window . setInterval ( ( ) => {
54+ if ( tries >= POLL_MAX ) {
55+ addScripts ( window . OnetrustActiveGroups )
56+ return window . clearInterval ( poll ) ;
57+ }
58+
59+ if ( document . getElementById ( "onetrust-accept-btn-handler" ) ) {
60+ window . OneTrust . OnConsentChanged ( ( ) => addScripts ( window . OnetrustActiveGroups ) ) ;
61+ return window . clearInterval ( poll ) ;
62+ } else {
63+ tries ++ ;
64+ }
65+ } , POLL_INTERVAL ) ;
0 commit comments