working counter script
This commit is contained in:
parent
4a7123ba81
commit
f90ea024e9
|
@ -1,3 +1,3 @@
|
|||
# milions
|
||||
# Millions
|
||||
|
||||
non-tracking web counter/analytics inspired by plausible.io and Simple analytics
|
||||
a non-tracking web counter/analytics inspired by plausible.io and Simple analytics
|
|
@ -10,6 +10,6 @@
|
|||
|
||||
<p><a href="">ping</a></p>
|
||||
|
||||
<script src="millions.js"></script>
|
||||
<script src="millions_v1.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,14 +1,59 @@
|
|||
/* Milions non-tracking web counter/analytics */
|
||||
(function(){
|
||||
/* Millions - a non-tracking web counter/analytics */
|
||||
(function(counterHost){
|
||||
if (!window) return;
|
||||
|
||||
if ("doNotTrack" in navigator && navigator["doNotTrack"] === "1") return;
|
||||
// inspired by:
|
||||
// https://github.com/simpleanalytics/scripts/blob/master/src/default.js
|
||||
// https://docs.simpleanalytics.com/what-we-collect
|
||||
// https://docs.simpleanalytics.com/uniques
|
||||
// https://christianheilmann.com/2015/12/25/detecting-adblock-without-an-extra-http-overhead/
|
||||
|
||||
console.log('href', document.location.href);
|
||||
console.log('ref', document.referrer);
|
||||
console.log('DNT', "doNotTrack" in navigator && navigator["doNotTrack"] === "1");
|
||||
console.log('innerWidth', window.innerWidth);
|
||||
console.log('UA', navigator.userAgent);
|
||||
var getLocation = function(href) {
|
||||
var match = href.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
||||
return match && {
|
||||
href: href,
|
||||
protocol: match[1],
|
||||
host: match[2],
|
||||
hostname: match[3],
|
||||
port: match[4],
|
||||
pathname: match[5],
|
||||
search: match[6],
|
||||
hash: match[7]
|
||||
} || { href: href };
|
||||
}
|
||||
var parseQuery = function(queryString) {
|
||||
var query = {};
|
||||
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i].split('=');
|
||||
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
var selfUrl = getLocation(document.location.href);
|
||||
// commented out for now // if (selfUrl=='localhost') return;
|
||||
var refUrl = getLocation(document.referrer);
|
||||
|
||||
var bonzUrl = selfUrl.protocol + '//' + counterHost + '/one.php?for=' + selfUrl.hostname + '&path=' + encodeURIComponent(selfUrl.pathname) + '&width=' + window.innerWidth;
|
||||
|
||||
if (refUrl.href=='' || (refUrl.hostname && selfUrl.hostname != refUrl.hostname)) {
|
||||
bonzUrl += '&unique=1';
|
||||
}
|
||||
|
||||
var Q = parseQuery(selfUrl.search);
|
||||
|
||||
if (Q.utm_source || Q.ref || Q.pk_campaign) {
|
||||
bonzUrl += '&ref=' + encodeURIComponent(Q.utm_source || Q.ref || Q.pk_campaign);
|
||||
} else if (Q.fbclid) {
|
||||
bonzUrl += '&ref=facebook';
|
||||
} else if (refUrl.hostname && selfUrl.hostname != refUrl.hostname) {
|
||||
bonzUrl += '&ref=' + encodeURIComponent(refUrl.hostname + refUrl.pathname);
|
||||
}
|
||||
|
||||
console.log(refUrl.hostname);
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET", bonzUrl, true);
|
||||
req.send(null);
|
||||
// we don't care about response yet
|
||||
})('localhost');
|
Loading…
Reference in New Issue