You are here

GDPR PopIn

Container Reference: 
Tag Type: 
Custom HTML
Tag Description: 
The GDPR Consent form popin itself with its Style / Html and Js logic
	<!-- santiano.io GDPR

The following code is separated in 3 parts :
-> Styling
-> HTML
-> Javascript
-->



<style>
/* 
  	For the CSS Lovers out there
   	Feel free to externalize and adapt this inline CSS
   	If you have advices for improving the style of this popIn
  	feel free to leave a comment on santiano.io
*/
  
  
.modal{
  display:none;
  position: fixed;
  z-index:9000; /* #over9000 thats' a Vegeta Safety */
  left: 0;
  top:0;
  height: 100%;
  max-height: 100%;
  width:100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.6);
}

.modal-content{
  background:#fff;
  margin: 20% auto;
  width:70%;
  max-width: 550px;
  box-shadow: 0 5px 8px 0 rgba(0,0,0,0.2),0 7px 20px 0 rgba(0,0,0,0.17);
  animation-name:modalopen;
  animation-duration:1.5s;
  border-radius: 10px;
}

#gdprModal {
  
}

#gdprCredit a {
  color: #ffffff;
  text-decoration: underline;
}

#gdprControlBtn,
#gdprOkBtnStep1,
#gdprOkBtnStep2 {
  cursor: pointer;
  border-width: 0px;
  margin-left: 5px;
  padding: 6px 16px;
  font-size: 13px;
  line-height: 1.846;
  border-radius: 3px;
}

#gdprOkBtnStep1,
#gdprOkBtnStep2 {
  background-color: #4caf50;
  color: #ffffff;
}

#gdprControlBtn {
  background-color: #eeeeee;
  color: #000;
}

#gdprOkBtnStep1:hover,
#gdprOkBtnStep2:hover {
  background-color: #009933;
}

#gdprControlBtn:hover{
  background-color: #d7d7d7;
}
#gdprFooter {
  text-align: right;
}

#gdprCredit {
  color: #ffffff;
  text-align: left;
  position: fixed;
  bottom: 15px;
  left: 15px;
}
#gdprHeader h2{
  margin: 0px;
  padding: 20px 10px;
}

#gdprBody {
  padding-bottom: 20px;
  padding-left: 10px;
  padding-right: 10px;
}  

#gdprScreen {
  
} 

@media (max-width : 767.98px){

  #gdprScreenFirst,
  #gdprScreenSecond {
    margin: 0 auto;
    padding: 10px;
    width:100%;
  }
}

@media (min-width: 768px) {
  #gdprScreenFirst,
  #gdprScreenSecond {
    margin: 20% auto;
    padding: 10px;
    width:70%;
    max-width: 550px;
    border-radius: 10px;
  }
}
  
#gdprScreenFirst,
#gdprScreenSecond {
  display:none;
  background:#fff;
  padding: 10px;
  box-shadow: 0 5px 8px 0 rgba(0,0,0,0.2),0 7px 20px 0 rgba(0,0,0,0.17);
  animation-name:modalopen;
  animation-duration:1.5s;
  
}

@keyframes modalopen{
  from{ opacity: 0}
  to {opacity: 1}
}
  
</style>




<div id="gdprModal" class="modal">
  <div id="gdprScreen">
    <div id="gdprScreenFirst">
      <div id="gdprHeader">
        <h2 id="gdpr1Title"></h2>
      </div>
      <div id="gdprBody">
        <p id="gdpr1Paragraph"></p>
      </div>
      <div id="gdprFooter">
        <button id="gdprControlBtn" type="button"></button>
        <button id="gdprOkBtnStep1" type="button"></button>
      </div>
    </div>

    <div id="gdprScreenSecond">
      <div id="gdprHeader">
        <h2 id="gdpr2Title"></h2>
      </div>
      <div id="gdprBody">
        <p id="gdpr2Paragraph"></p>
        <div class="form-check">
          <input type="checkbox" value="" id="gdprStage0">
          <label id="gdprStage0Label" for="gdprStage0"></label>
        </div>
        <div class="form-check">
          <input type="checkbox" value="" id="gdprStage1">
          <label id="gdprStage1Label" for="gdprStage1"></label>
        </div>
        <div class="form-check">
          <input type="checkbox" value="" id="gdprStage2">
          <label id="gdprStage2Label" for="gdprStage2"></label>
        </div>
      </div>
      <div id="gdprFooter">
        <button id="gdprOkBtnStep2" type="button" class="btn btn-success">OK</button>
      </div>
    </div>
  </div>
  <div id="gdprCredit">
    <p>Privacy protected with <a target="_blank" href="http://santiano.io">santiano.io</a></p>
  </div>
</div>
<!-- Start of the JS logic -->
<script>

/* 
  	For the Javascript Lovers out there
   	Feel free to improve my code as I am far from a JS Jedi
   	If you have advices for improving the effciciency of this popIn
  	feel free to leave a comment on santiano.io
*/  
  

var gdprModal = document.getElementById('gdprModal');

var gdprStage0 = document.getElementById('gdprStage0');
var gdprStage1 = document.getElementById('gdprStage1');
var gdprStage2 = document.getElementById('gdprStage2');

// Grabbing the buttons
var gdprControlBtn = document.getElementById('gdprControlBtn');
var gdprOkBtnStep1 = document.getElementById('gdprOkBtnStep1');
var gdprOkBtnStep2 = document.getElementById('gdprOkBtnStep2');


// the First screen ;P
var gdprScreenFirst = document.getElementById('gdprScreenFirst');
// the Control center (itself)
var gdprScreenSecond = document.getElementById('gdprScreenSecond');

// button listeners
gdprControlBtn.addEventListener('click', gdprHideStep1ShowStep2);
gdprOkBtnStep1.addEventListener('click', gdprStep1validation);
gdprOkBtnStep2.addEventListener('click', gdprStep2validation);

// Checkboxes activations
gdprStage0.addEventListener('click', gdprStage0Select);
gdprStage1.addEventListener('click', gdprStage1Select);
gdprStage2.addEventListener('click', gdprStage2Select);

// Checkbox behavior : 
function gdprStage0Select(){
  if(document.getElementById('gdprStage0').checked == false) {
    checkboxUnSelect(gdprStage1);
    checkboxUnSelect(gdprStage2);
  };
};

function gdprUpdateTextContent(){
  // this feature is going to be usefull for Two reasons :
    // i might have to publish the content according to the 'websiteLanguage"
    // these strings can be plugged to the static DataLayer served by the website servers...
  var gdprPopInHtmlStrings = {{gdprPopInHtmlStrings}};

  //filling step 1 :
  document.getElementById('gdpr1Title').innerHTML = gdprPopInHtmlStrings.screenFirst.headerTitle;
  document.getElementById('gdpr1Paragraph').innerHTML = gdprPopInHtmlStrings.screenFirst.textContent;
  document.getElementById('gdprOkBtnStep1').innerHTML = gdprPopInHtmlStrings.screenFirst.buttonOK;
  document.getElementById('gdprControlBtn').innerHTML = gdprPopInHtmlStrings.screenFirst.buttonControl;
  // filling step 2 :
  document.getElementById('gdpr2Title').innerHTML = gdprPopInHtmlStrings.screenSecond.headerTitle;
  document.getElementById('gdpr2Paragraph').innerHTML = gdprPopInHtmlStrings.screenSecond.textContent;
  document.getElementById('gdprStage0Label').innerHTML = gdprPopInHtmlStrings.screenSecond.stage0;
  document.getElementById('gdprStage1Label').innerHTML = gdprPopInHtmlStrings.screenSecond.stage1;
  document.getElementById('gdprStage2Label').innerHTML = gdprPopInHtmlStrings.screenSecond.stage2;
  document.getElementById('gdprOkBtnStep2').innerHTML = gdprPopInHtmlStrings.screenSecond.buttonOK;
}

function gdprStage1Select(){
  if(document.getElementById('gdprStage1').checked == false) {
      checkboxUnSelect(gdprStage2);
    } else {
      checkboxSelect(gdprStage0);
    };
};

function gdprStage2Select(){
  if(document.getElementById('gdprStage2').checked == true) {
    checkboxSelect(gdprStage0);
    checkboxSelect(gdprStage1);
  }
};

// when the GDPR Sreen 1 is Validated
function gdprStep1validation(){
  gdprHideModal();
  setUserConsent();
  gdprAllValidations(); // Yeah
  // promo click 1 OK
};

function gdprStep2validation(){
  gdprHideModal();
  setUserConsent();
  setUserGtmTagsPreference(gdprGrabUserPreferenceFromForm());
  // promo click 
};

function gdprGrabUserPreferenceFromForm(){
	if(document.getElementById('gdprStage2').checked == true) {
    	return 3;
    } else if (document.getElementById('gdprStage1').checked == true) {
    	return 2;
    } else if (document.getElementById('gdprStage0').checked == true) {
    	return 1;
    } else {
    	return 0;
    };
}  

function gdprAllValidations(){
  // console.log('ALL 3 validated my friend');
  setUserGtmTagsPreference(3);

  window.localStorage.setItem('gdprUserConsentTimeStamp', new Date().getTime() );
  // where the dataLayerPush gets updated :) :) :) 
  // promo Click
};

function setUserConsent() {
	window.localStorage.setItem('gdprUserConsent', '1');
  	// could also be stored in a cookie
}
  
function setUserGtmTagsPreference(numBer) {
	// 
  	window.localStorage.setItem('gdprUserConsentSetting', numBer);
    var consentTimeStamp = new Date();
    window.localStorage.setItem('gdprUserConsentTimeStamp', consentTimeStamp.getTime() );
    
}
  
function readUserGtmTagsPreference() {
  	// reading the gdprUserConsentSetting 
	return window.localStorage.getItem('gdprUserConsentSetting');
}

  
function gdprPromoView(
  // next version guys i need sleep
){

}
function gdprPromoClick(
// next version guys as I really need sleep
){
  
}

function checkboxSelect(gdprStage){
  gdprStage.checked = true;
};

function checkboxUnSelect(gdprStage){
  gdprStage.checked = false;
};

function checkboxDisable(gdprStage){
  gdprStage.disabled = 'true';
};


function gdprGrabSettingsFromGtmUpdateForm(){
  var gdprCurrentSettings = readUserGtmTagsPreference();
  var gdprDefaultSettings = 1;
  // the dlv goes here
  if (gdprCurrentSettings == undefined){
    gdprCurrentSettings = gdprDefaultSettings;
  };
  switch(gdprCurrentSettings) {
    case '1':
        checkboxSelect(gdprStage0);
        break;
    case '2':
        checkboxSelect(gdprStage0);
        checkboxSelect(gdprStage1);
        break;
    case '3':
        checkboxSelect(gdprStage0);
        checkboxSelect(gdprStage1);
        checkboxSelect(gdprStage2);
        break;
    default:
        break;
    };
  var gdprStage0IsMandatory = 1;
  if (gdprStage0IsMandatory) {
  	checkboxSelect(gdprStage0);
    checkboxDisable(gdprStage0);
  }
};

function gdprShowStep1(){
  gdprShowModal()
  gdprScreenFirst.style.display ='block';
  gdprGrabSettingsFromGtmUpdateForm();
  gdprUpdateTextContent();
  // promo view 1 or event triggered
};

function gdprShowStep2(){
  gdprShowModal()
  gdprGrabSettingsFromGtmUpdateForm();

  gdprUpdateTextContent()
  gdprScreenSecond.style.display = 'block';
  // promo view 2 from Itself
};

function gdprHideStep1ShowStep2(){
  gdprScreenFirst.style.display ='none';
  gdprScreenSecond.style.display = 'block';
  // promo click 1 "control button"
  // promo view 2 from step 1
};


function gdprShowModal(){
  gdprModal.style.display = 'block';
};

function gdprHideModal(){
  gdprModal.style.display = 'none';
};

// now we are ready to show it guys
var eventCommand = {{eventCommand}};

if (eventCommand == 'gdprShowPopInStep1') {
  gdprShowStep1();

} else if (eventCommand == 'gdprShowPopInStep2') {
  gdprShowStep2();

} else {
  setTimeout(gdprShowStep1, 1000);
}



</script>

Add new comment