mirror of
https://github.com/ascribe/wp-theme
synced 2024-12-22 09:13:38 +01:00
refined Google Analytics loading, respecting DNT
This commit is contained in:
parent
247ec05ae5
commit
7a6f3c3539
46
assets/_src/js/_dnt.js
Normal file
46
assets/_src/js/_dnt.js
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Returns true or false based on whether doNotTack is enabled. It also takes into account the
|
||||
* anomalies, such as !bugzilla 887703, which effect versions of Fx 31 and lower. It also handles
|
||||
* IE versions on Windows 7, 8 and 8.1, where the DNT implementation does not honor the spec.
|
||||
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1217896 for more details
|
||||
* @params {string} [dnt] - An optional mock doNotTrack string to ease unit testing.
|
||||
* @params {string} [userAgent] - An optional mock userAgent string to ease unit testing.
|
||||
* @returns {boolean} true if enabled else false
|
||||
*/
|
||||
function _dntEnabled(dnt, userAgent) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// for old version of IE we need to use the msDoNotTrack property of navigator
|
||||
// on newer versions, and newer platforms, this is doNotTrack but, on the window object
|
||||
// Safari also exposes the property on the window object.
|
||||
var dntStatus = dnt || navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
|
||||
var ua = userAgent || navigator.userAgent;
|
||||
|
||||
// List of Windows versions known to not implement DNT according to the standard.
|
||||
var anomalousWinVersions = ['Windows NT 6.1', 'Windows NT 6.2', 'Windows NT 6.3'];
|
||||
|
||||
var fxMatch = ua.match(/Firefox\/(\d+)/);
|
||||
var ieRegEx = /MSIE|Trident/i;
|
||||
var isIE = ieRegEx.test(ua);
|
||||
// Matches from Windows up to the first occurance of ; un-greedily
|
||||
// http://www.regexr.com/3c2el
|
||||
var platform = ua.match(/Windows.+?(?=;)/g);
|
||||
|
||||
// With old versions of IE, DNT did not exist so we simply return false;
|
||||
if (isIE && typeof Array.prototype.indexOf !== 'function') {
|
||||
return false;
|
||||
} else if (fxMatch && parseInt(fxMatch[1], 10) < 32) {
|
||||
// Can't say for sure if it is 1 or 0, due to Fx bug 887703
|
||||
dntStatus = 'Unspecified';
|
||||
} else if (isIE && platform && anomalousWinVersions.indexOf(platform.toString()) !== -1) {
|
||||
// default is on, which does not honor the specification
|
||||
dntStatus = 'Unspecified';
|
||||
} else {
|
||||
// sets dntStatus to Disabled or Enabled based on the value returned by the browser.
|
||||
// If dntStatus is undefined, it will be set to Unspecified
|
||||
dntStatus = { '0': 'Disabled', '1': 'Enabled' }[dntStatus] || 'Unspecified';
|
||||
}
|
||||
|
||||
return dntStatus === 'Enabled' ? true : false;
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
|
||||
//=include _dnt.js
|
||||
//=include _faq.js
|
||||
|
||||
$(document).ready(function(){
|
||||
|
||||
if ( $('.subtemplate--faq').length ) {
|
||||
Faq.init();
|
||||
}
|
||||
|
||||
slider();
|
||||
marketplaces();
|
||||
|
2
assets/dist/js/ascribe.js
vendored
2
assets/dist/js/ascribe.js
vendored
File diff suppressed because one or more lines are too long
2
assets/dist/js/ascribe.min.js
vendored
2
assets/dist/js/ascribe.min.js
vendored
File diff suppressed because one or more lines are too long
34
footer.php
34
footer.php
@ -224,6 +224,40 @@ if ($twitter) {
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php wp_footer(); ?>
|
||||
|
||||
<script>
|
||||
if (!_dntEnabled()) {
|
||||
(function(window) {
|
||||
|
||||
// Google Analytics async snippet
|
||||
// http://goo.gl/3FPNDx
|
||||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};
|
||||
ga.l=+new Date;
|
||||
|
||||
// Create the GA tracker
|
||||
ga('create', 'UA-60614729-2', 'auto', {siteSpeedSampleRate: 10});
|
||||
|
||||
// Send initial pageview
|
||||
ga('send', 'pageview');
|
||||
|
||||
// Track uncaught errors
|
||||
window.onerror = function(message, url, line, col) {
|
||||
var desc = message + ' (line: ' + line + ', url: ' + url + ', col: '
|
||||
+ col + ')';
|
||||
|
||||
ga('send', 'exception', {
|
||||
exDescription: 'window.onerror: ' + desc,
|
||||
exFatal: false
|
||||
});
|
||||
};
|
||||
|
||||
}(window));
|
||||
}
|
||||
</script>
|
||||
|
||||
<script async src="//www.google-analytics.com/analytics.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
21
header.php
21
header.php
@ -22,17 +22,21 @@ if ( is_category() || is_tag() ) {
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html class="no-js " lang="en" itemscope itemtype="https://schema.org/Organization" xmlns="http://www.w3.org/1999/html">
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
|
||||
<title><?php echo $title ?></title>
|
||||
<base href="<?php echo $url; ?>">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0">
|
||||
<meta name="description" content="<?php echo $description ?>">
|
||||
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="HandheldFriendly" content="True">
|
||||
<meta name="MobileOptimized" content="320">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="cleartype" content="on">
|
||||
|
||||
<meta property="og:title" content="<?php echo $title; ?>" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:url" content="<?php echo $permalink; ?>" />
|
||||
@ -72,17 +76,6 @@ if ( is_category() || is_tag() ) {
|
||||
})(document);
|
||||
</script>
|
||||
|
||||
<script>
|
||||
(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-60614729-2', 'auto');
|
||||
ga('send', 'pageview');
|
||||
|
||||
</script>
|
||||
|
||||
<?php wp_head(); ?>
|
||||
</head>
|
||||
<body <?php body_class($headColour); ?> >
|
||||
|
Loading…
Reference in New Issue
Block a user