Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a-not-so-shitty-google-analytics-javascript-code
<?php
session_start();
if(! isset($_SESSION['uniqueID'])){ $_SESSION['uniqueID'] = uniqid(); }
setlocale(LC_ALL, 'he_IL.UTF-8');
mb_internal_encoding('UTF-8');
//setlocale(LC_CTYPE, 'en_US.UTF-8');
//header('Content-Type: text/plain;charset=UTF-8');
//header('Content-Type: text/plain;charset=windows-1255');
?><!DOCTYPE html>
<html lang="en-US"><head></head>
<body>
<!-- some content -->
<!-- ............ -->
<!-- (page's end) -->
<script>
window["GoogleAnalyticsObject"] = "ga";
window["ga"] = window["ga"] || function () {
window["ga"].l = 1 * new Date();
window["ga"].q = window["ga"].q || [];
window["ga"].q.push(arguments);
};
</script>
<script src="https://www.google-analytics.com/analytics.js"></script>
<script>
window["ga"]("create", "UA-THE_CODE_FROM_GOOGLE-1", "THE_DETAIL_FROM_GOOGLE");
window["ga"]("require", "displayfeatures");
window["ga"]("require", "linkid", "linkid.js");
window["ga"]("set", "&uid", "<?php print($_SESSION['uniqueID']); ?>");
window["ga"]("send", "pageview");
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.