Instantly share code, notes, and snippets.
Created
February 22, 2022 07:05
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save ozkanozcan/b38d3c6459d3db079f233bd9aa157122 to your computer and use it in GitHub Desktop.
Cookie Policy Confirmation
This file contains 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
<div id="cookiePolicy" class=""><div class="cookie-policy-confirmation" style="display: flex;"> | |
<div class="wrapper"> | |
<p class="info"> | |
İnternet sitemizde kullanılan çerezlerle ilgili bilgi almak ve tercihlerinizi yönetmek için <a href="/cerez-politikasi" target="_blank">Çerez Politikası</a>, daha fazla bilgi için <a href="/aydinlatma-metni" target="_blank">Aydınlatma Metni</a> sayfalarını ziyaret edebilirsiniz. Sitemizi kullanarak çerezleri kullanmamızı kabul edersiniz. | |
</p> | |
<div class="buttons"> | |
<button class="acceptCookies btn" onclick="acceptCookies()">Kabul Et | |
</button><button class="policy-close" onclick="closeButtonCookie()">x</button> | |
</div> | |
</div> | |
</div> | |
<style> | |
.cookie-policy-confirmation{ | |
left: 0px; | |
right: 0px; | |
bottom: 0px; | |
margin: auto; | |
z-index: 999999999; | |
width: 100%; | |
max-width: 100%; | |
min-width: 320px; | |
font-size: 12px; | |
background-color: rgb(255, 255, 255); | |
color: rgb(51, 51, 51); | |
line-height: 1.3; | |
box-shadow: rgba(0, 0, 0, 0.5) 10px 10px 155px 0px; | |
display: none; | |
position: fixed; | |
} | |
.cookie-policy-confirmation .wrapper{ | |
width: 100%; | |
padding:5px 10px; | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-pack: space-between; | |
-ms-flex-pack: space-between; | |
justify-content: space-between; | |
-webkit-box-align: center; | |
-ms-flex-align: center; | |
align-items: center; | |
} | |
.cookie-policy-confirmation .info a{ | |
color: #666;font-weight: bold; text-decoration: underline; | |
} | |
.cookie-policy-confirmation .buttons{ | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-pack: center; | |
-ms-flex-pack: center; | |
justify-content: center; | |
-webkit-box-align: center; | |
-ms-flex-align: center; | |
align-items: center; | |
} | |
.cookie-policy-confirmation .buttons .btn{ | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-pack: center; | |
-ms-flex-pack: center; | |
justify-content: center; | |
-webkit-box-align: center; | |
-ms-flex-align: center; | |
align-items: center; | |
width: 100px; height: 30px; | |
background: #000000; | |
color: white; | |
font-size: 12px; | |
font-weight: bold; | |
-webkit-border-radius: 5px; | |
-moz-border-radius: 5px; | |
border-radius: 5px; | |
cursor: pointer; | |
} | |
.cookie-policy-confirmation .buttons .policy-close{ | |
width: 30px;height: 30px; margin: 0 0 0 30px; | |
color: #333; line-height: 0px; | |
font-weight: bold; | |
font-size: 19px; | |
background-color: #f2f2f2; | |
cursor: pointer; | |
display: -webkit-box; | |
display: -ms-flexbox; | |
display: flex; | |
-webkit-box-pack: center; | |
-ms-flex-pack: center; | |
justify-content: center; | |
-webkit-box-align: center; | |
-ms-flex-align: center; | |
align-items: center; | |
-webkit-border-radius: 5px; | |
-moz-border-radius: 5px; | |
border-radius: 5px; | |
} | |
@media (max-width:768px) { | |
.cookie-policy-confirmation{font-size:11px;} | |
.cookie-policy-confirmation .buttons{ | |
flex-direction: column-reverse; | |
} | |
.cookie-policy-confirmation .buttons .policy-close{ | |
margin: 0px 0 20px auto; | |
} | |
} | |
</style> | |
<script type="text/javascript"> | |
var euCountries = [ | |
"EU", "AD", "AL", "AT", "BA", "BE", "BG", "BY", "CH", "CS", "CZ", "DE", "DK", "EE", "ES", "FI", "FO", "FR", "FX", "GB", "GI", | |
"GR", "HR", "HU", "IE", "IS", "IT", "LI", "LT", "LU", "LV", "MC", "MD", "MK", "MT", "NL", "NO", "PL", "PT", "RO", "SE", "SI", | |
"SJ", "SK", "SM", "TR", "UA", "VA" | |
]; | |
var cookiePolicy = getCookiePolicy("cookiePolicy"); | |
if (cookiePolicy != 1) { | |
// var request = new XMLHttpRequest(); | |
// request.open('GET', '/dynamics/geoipj', true); | |
// request.onload = function() { | |
// if (request.status >= 200 && request.status < 400) { | |
// var data = JSON.parse(request.responseText); | |
// if(euCountries.indexOf(data.country) > -1){ | |
// document.getElementsByClassName("cookie-policy-confirmation")[0].style['display'] = 'flex'; | |
// } | |
// } | |
// }; | |
// request.send(); | |
document.getElementsByClassName("cookie-policy-confirmation")[0].style['display'] = 'flex'; | |
} | |
function setCookiePolicy(cname, cvalue, exdays) { | |
var d = new Date(); | |
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); | |
var expires = "expires=" + d.toUTCString(); | |
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; | |
} | |
function getCookiePolicy(cname) { | |
var name = cname + "="; | |
var ca = document.cookie.split(';'); | |
for (var i = 0; i < ca.length; i++) { | |
var c = ca[i]; | |
while (c.charAt(0) == ' ') { | |
c = c.substring(1); | |
} | |
if (c.indexOf(name) == 0) { | |
return c.substring(name.length, c.length); | |
} | |
} | |
return ""; | |
}</script> | |
<script type="text/javascript"> | |
var cookieKey = 'npa'; | |
var cookieHours = 8760; | |
var cookieTrackEvent = function(eventCategory,eventAction,eventLabel){ | |
if(typeof dataLayer != "undefined"){ | |
dataLayer.push({ | |
'event': 'GAEvent', | |
'eventCategory': eventCategory, | |
'eventAction': eventAction, | |
'eventLabel': eventLabel, | |
'position': 1, | |
'share': '' | |
}); | |
}else{// | |
ga('send', eventCategory, eventLabel, eventAction, 1); | |
} | |
} | |
function acceptCookies() { | |
var npDfp = 0; | |
setCookiePolicy(cookieKey, npDfp, cookieHours); | |
setCookiePolicy("cookiePolicy", 1, 365); | |
document.getElementsByClassName("cookie-policy-confirmation")[0].style['display'] = 'none'; | |
cookieTrackEvent("cookiePolicy","cookiePolicyAccept","cookiePolicyAccept"); | |
} | |
function closeButtonCookie() { | |
var npDfp = 0; | |
setCookiePolicy(cookieKey, npDfp, 1); | |
setCookiePolicy("cookiePolicy", 1, 1); | |
document.getElementsByClassName("cookie-policy-confirmation")[0].style['display'] = 'none'; | |
cookieTrackEvent("cookiePolicy","cookiePolicyClose","cookiePolicyClose"); | |
} | |
</script> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment