1class ConsentCoder{ 2 binConvert(x, pad) { 3 if (isNaN(parseFloat(x))) { return; } 4 x = x.toString(2); 5 while (x.length < pad) { 6 x = "0" + x; 7 } 8 return x; 9 } 10 11 getConsentString(opted_categories){ 12 //https://medium.com/@mark.burger/creating-iabs-gdpr-consent-strings-8c55b705878f 13 var consent_payload = ""; 14 15 // VERSION 16 consent_payload += this.binConvert(1, 6); 17 18 // CREATED/CHANGED TIMESTAMPS 19 var q = Math.round((new Date()).getTime() / 100); 20 var ts = this.binConvert(q, 36); 21 consent_payload += ts + ts; 22 23 // CMP ID 24 consent_payload += this.binConvert(1, 12); 25 26 //CMP VERSION 27 consent_payload += this.binConvert(1, 12); 28 29 // CMP SCREEN 30 consent_payload += this.binConvert(1, 6); 31 32 // LANGUAGE CODE : FR (F:6 R:18) 33 consent_payload += this.binConvert(5, 6); 34 consent_payload += this.binConvert(17, 6); 35 36 // VENDOR LIST VERSION 37 consent_payload += this.binConvert(141, 12); 38 39 // // VENDOR LIST TCF POLICY VERSION 40 // consent_payload += this.binConvert(2, 6); 41 42 // // IS SERVICE SPECIFIC 43 // consent_payload += this.binConvert(1, 1); 44 45 // // USE NON STANDARDS STACKS 46 // consent_payload += this.binConvert(0, 1); 47 48 // // SPECIAL FEATURES OPT-IN 49 // consent_payload += "111111111111"; 50 51 // FEATURES OPT-IN | PURPOSES ALLOWED 52 consent_payload += opted_categories; 53 54 // // PURPOSE LEGITIMATE INTEREST TRANSPARENCY 55 // consent_payload += "111111111111111111111111"; 56 57 // //PURPOSE ONE TREATMENT 58 // consent_payload += "0"; 59 60 // //PUBLISHER CC 61 // consent_payload += this.binConvert(5, 6); 62 // consent_payload += this.binConvert(17, 6); 63 64 // MAXIMUM VENDOR ID 65 consent_payload += this.binConvert(615, 16); 66 67 // PARTNER LIST ENCODING TYPE 68 consent_payload += "1"; // RANGE 69 70 // PARTNER LIST DEFAULT CONSENT 71 consent_payload += "1"; // CONSENT 72 73 // EXCEPTIONS LIST LENGTH 74 consent_payload += this.binConvert(0, 12); 75 76 // // NUMBER OF PUBLISHER RESTRICTIONS 77 // consent_payload += this.binConvert(0, 12); 78 79 // COMPLETE PAYLOAD 80 while (consent_payload.length % 8 != 0) { consent_payload += "0"; } 81 82 // TO BIN 83 var binary_payload = []; 84 for (var i = 0; i < consent_payload.length; i += 8) { 85 binary_payload.push(parseInt(consent_payload.substring(i, i + 8), 2)); 86 } 87 88 // TO BASE64 89 var consent = btoa(String.fromCharCode(...binary_payload)) 90 .replace(/\+/g, '-') 91 .replace(/\//g, '_') 92 .replace(/=+$/, ''); 93 94 return consent; 95 } 96}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.