-
-
Save alex7r/76390fa2eafd73d12612e86e3f1b44ee to your computer and use it in GitHub Desktop.
GA GDP
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
<?php if($_COOKIE['enable_ga'] && $_COOKIE['enable_ga']!='never'){ ?> | |
<script type="text/javascript"> | |
jQuery( document ).ready(function($) { | |
function useAnalytics(); | |
}); | |
</script> | |
<?php | |
}elseif($_COOKIE['enable_ga']!='never'){ ?> | |
<div class="letus-use-cookies-for-ga" style=" | |
position: fixed; | |
z-index: 10000; | |
bottom: 0; | |
background: #0006; | |
width: 100%; | |
text-align: center; | |
height: 100%; | |
top: 0; | |
"> | |
<div style=" | |
position: absolute; | |
z-index: 1000; | |
bottom: 40%; | |
top: 40%; | |
padding: 30px; | |
background: lightgrey; | |
text-align: center; | |
display: table; | |
vertical-align: middle; | |
width: 100%; | |
"> | |
<p>Please let us take you under our hood...</p> | |
<button type="button" onclick="setACookie('enable_ga','true',{expires: 365*2 }); useAnalytics();"> | |
Allow | |
</button> | |
<button type="button" onclick="setACookie('enable_ga','never',{expires: 24 });"> | |
No way | |
</button> | |
</div> | |
</div> | |
<?php } ?> | |
<script> | |
function setACookie(name, value, options) { | |
options = options || {}; | |
var expires = options.expires; | |
if (typeof expires == "number" && expires) { | |
var d = new Date(); | |
d.setTime(d.getTime() + expires * 24 * 60 * 60 * 1000); | |
expires = options.expires = d; | |
} | |
if (expires && expires.toUTCString) { | |
options.expires = expires.toUTCString(); | |
} | |
value = encodeURIComponent(value); | |
var updatedCookie = name + "=" + value; | |
for (var propName in options) { | |
updatedCookie += "; " + propName; | |
var propValue = options[propName]; | |
if (propValue !== true) { | |
updatedCookie += "=" + propValue; | |
} | |
} | |
document.cookie = updatedCookie; | |
jQuery('.letus-use-cookies-for-ga').slideToggle(800,function () { | |
jQuery('.letus-use-cookies-for-ga').remove(); | |
}); | |
} | |
function useAnalytics() { | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-sadasdsadsad-1', 'kosarev.by'); | |
ga('send', 'pageview'); | |
(function (d, w, c) { | |
(w[c] = w[c] || []).push(function() { | |
try { | |
w.yaCounter123123123 = new Ya.Metrika({id:123123123, | |
webvisor:true, | |
clickmap:true, | |
trackLinks:true, | |
accurateTrackBounce:true}); | |
} catch(e) { } | |
}); | |
var n = d.getElementsByTagName("script")[0], | |
s = d.createElement("script"), | |
f = function () { n.parentNode.insertBefore(s, n); }; | |
s.type = "text/javascript"; | |
s.async = true; | |
s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js"; | |
if (w.opera == "[object Opera]") { | |
d.addEventListener("DOMContentLoaded", f, false); | |
} else { f(); } | |
})(document, window, "yandex_metrika_callbacks"); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment