1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 14:26:41 -04:00

fix analytics

This commit is contained in:
2020-04-28 08:45:56 -04:00
parent b0893ff52f
commit 9a87b9fa8d
6 changed files with 26 additions and 85 deletions

View File

@ -1,10 +1,6 @@
/* jshint browser: true, laxbreak:true, -W080 */
/*!
* Copyright (c) 2018-2020 Simple Analytics. Licensed under MIT.
* https://github.com/simpleanalytics/scripts/blob/master/LICENSE
*/
/*! Simple Analytics - Privacy friendly analytics (docs.simpleanalytics.com/script; 2020-03-02; 21e2) */
// https://github.com/simpleanalytics/scripts/blob/3918189e9137b55522a2dbeb3d7cb4bc2c26c52a/src/default.js
(function(window, baseUrl, apiUrlPrefix, version, saGlobal) {
@ -90,7 +86,7 @@
data = assign(payload, data);
new Image().src =
fullApiUrl +
"/s.gif?" +
"/send.gif?" +
Object.keys(data)
.filter(function(key) {
return data[key] != undefinedVar;
@ -128,11 +124,6 @@
false
);
/** if spa **/
var pushState = "pushState";
var dis = window.dispatchEvent;
/** endif **/
/** if duration **/
var duration = "duration";
var start = now();
@ -150,8 +141,8 @@
// Don't track when localhost
/** unless testing **/
//if (loc.hostname.indexOf(".") == -1)
// return warn(notSending + "from " + loc.localhost);
if (loc.hostname.indexOf(".") == -1)
return warn(notSending + "from " + loc.localhost);
/** endunless **/
try {
@ -288,11 +279,6 @@
// Obfuscate personal data in URL by dropping the search and hash
var path = decodeURIComponentFunc(loc.pathname);
/** if hash **/
// Add hash to path when script is put in to hash mode
if (mode == "hash" && loc.hash) path += loc.hash.split("?")[0];
/** endif **/
// Don't send the last path again (this could happen when pushState is used to change the path hash or search)
if (lastSendPath == path) return;
@ -336,64 +322,6 @@
sendPageView(isPushState, isPushState || userNavigated);
};
/** if spa **/
var his = window.history;
var hisPushState = his ? his.pushState : undefinedVar;
// Overwrite history pushState function to
// allow listening on the pushState event
if (hisPushState && Event && dis) {
var stateListener = function(type) {
var orig = his[type];
return function() {
var rv = orig.apply(this, arguments);
var event;
if (typeof Event == "function") {
event = new Event(type);
} else {
// Fix for IE
event = doc.createEvent("Event");
event.initEvent(type, true, true);
}
event.arguments = arguments;
dis(event);
return rv;
};
};
his.pushState = stateListener(pushState);
addEventListenerFunc(
pushState,
function() {
pageview(1);
},
false
);
addEventListenerFunc(
"popstate",
function() {
pageview(1);
},
false
);
}
/** endif **/
/** if hash **/
// When in hash mode, we record a pageview based on the onhashchange function
if (mode == "hash" && "onhashchange" in window) {
addEventListenerFunc(
"hashchange",
function() {
pageview(1);
},
false
);
}
/** endif **/
pageview();
/** if events **/
@ -445,4 +373,4 @@
} catch (e) {
sendError(e);
}
})(window, "{{ (urls.Parse .Site.BaseURL).Host }}");
})(window, "{{ (urls.Parse .Site.BaseURL).Host }}/sa");

View File

@ -1,9 +1,8 @@
/* jshint indent: 2, browser: true, bitwise: true, plusplus: true */
/*!
* Copyright (c) 2018 Twitter, Inc. and other contributors. Licensed under MIT.
* https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
*/
/*! Copyright Twitter Inc. and other contributors. Licensed under MIT *//*
https://github.com/twitter/twemoji/blob/gh-pages/LICENSE
*/
(function (

View File

@ -261,7 +261,7 @@
</footer>
{{ if eq hugo.Environment "production" }}
<amp-pixel src="https://s.jarv.is/image.gif" layout="nodisplay"></amp-pixel>
<amp-pixel src="{{ "sa/noscript.gif" | absURL }}?hostname=CANONICAL_HOSTNAME&path=CANONICAL_PATH&referrer=DOCUMENT_REFERRER&https=true&ua=USER_AGENT&width=SCREEN_WIDTH&type=pageview" layout="nodisplay"></amp-pixel>
{{ end }}
</body>
</html>

View File

@ -1,5 +1,4 @@
{{ if eq hugo.Environment "production" }}
<link rel="preconnect" href="https://s.jarv.is" crossorigin>
{{ if and .IsPage (and (eq .Type .Site.Params.mainSection) (ne .Params.comments false)) }}
<link rel="preconnect" href="https://utteranc.es" crossorigin>
<link rel="preconnect" href="https://api.utteranc.es" crossorigin>

View File

@ -81,10 +81,25 @@
# Proxy data to Simple Analytics endpoint
[[redirects]]
from = "/s.gif*"
from = "/sa/send.gif*"
to = "https://queue.simpleanalyticscdn.com/simple.gif:splat"
status = 200
force = true
[[redirects]]
from = "/sa/noscript.gif*"
to = "https://queue.simpleanalyticscdn.com/noscript.gif:splat"
status = 200
force = true
[[redirects]]
from = "/sa/append"
to = "https://queue.simpleanalyticscdn.com/append"
status = 200
force = true
[[redirects]]
from = "/sa/post"
to = "https://api.simpleanalytics.io/post"
status = 200
force = true
# Support ancient RSS subscriptions and links from WordPress era:
[[redirects]]

View File

@ -22,7 +22,7 @@
"start": "hugo server --disableFastRender --buildDrafts --buildFuture --port 1337 --bind 0.0.0.0 --verbose",
"optimize": "run-s optimize:**",
"optimize:html": "html-minifier --html5 --collapse-whitespace --collapse-boolean-attributes --preserve-line-breaks --minify-css --file-ext html --input-dir public --output-dir public **/*.html",
"optimize:js": "terser --mangle --compress passes=3,negate_iife=false,keep_fargs=false,sequences=false,reduce_vars=false --mangle-props --output public/js/app.js -- public/js/app.js",
"optimize:js": "terser --compress passes=3,negate_iife=false,keep_fargs=false,sequences=false,reduce_vars=false --mangle reserved=['sa'] --output public/js/app.js -- public/js/app.js",
"optimize:img": "find ./public -type d ! -path './public/vendor*' | xargs -n1 -P8 -I{} imagemin {}/* --plugin=jpegoptim --plugin.jpegoptim.progressive --plugin.jpegoptim.stripAll --plugin=pngquant --plugin.pngquant.quality={0.1,0.3} --plugin.pngquant.speed=1 --plugin.pngquant.strip --plugin=gifsicle --plugin=svgo --out-dir={}",
"lint": "run-s lint:**",
"lint:scss": "stylelint assets/sass/**/* --syntax scss",