Hash mode (#299)
* Build tracker with hash mode * Extract hash fragment in hash mode * Serve new hash-based trackerpull/308/head
parent
d30f17c807
commit
4aa4dfdcaf
@ -0,0 +1 @@
|
||||
!function(r,i){"use strict";var o=r.location,s=r.document,e=s.querySelector('[src*="'+i+'"]'),l={domain:e&&e.getAttribute("data-domain")||o.hostname};function c(e){console.warn("[Plausible] Ignore event: "+e)}function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(o.hostname)||"file:"===o.protocol)return c("running locally");if("prerender"===s.visibilityState)return c("prerendering");var n={};n.n=e,n.u=o.href,n.d=l.domain,n.r=s.referrer||null,n.w=r.innerWidth,n.h=1;var a=new XMLHttpRequest;a.open("POST",i+"/api/event",!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(n)),a.onreadystatechange=function(){4==a.readyState&&t&&t.callback&&t.callback()}}function n(){t("pageview")}try{var a,u=r.history;u.pushState&&(a=u.pushState,u.pushState=function(){a.apply(this,arguments),n()},r.addEventListener("popstate",n)),r.addEventListener("hashchange",n);var p=r.plausible&&r.plausible.q||[];r.plausible=t;for(var d=0;d<p.length;d++)t.apply(this,p[d]);n()}catch(e){(new Image).src=i+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
||||
@ -1,17 +1,21 @@
|
||||
const uglify = require("uglify-js");
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const Handlebars = require("handlebars");
|
||||
|
||||
function relPath(segment) {
|
||||
return path.join(__dirname, segment)
|
||||
}
|
||||
|
||||
function compilefile(input, output) {
|
||||
function compilefile(input, output, templateVars = {}) {
|
||||
const code = fs.readFileSync(input).toString()
|
||||
const result = uglify.minify(code)
|
||||
const template = Handlebars.compile(code)
|
||||
const rendered = template(templateVars)
|
||||
const result = uglify.minify(rendered)
|
||||
fs.writeFileSync(output, result.code)
|
||||
}
|
||||
|
||||
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.js'))
|
||||
compilefile(relPath('src/plausible.js'), relPath('../priv/tracker/js/plausible.hash.js'), {hashMode: true})
|
||||
compilefile(relPath('src/p.js'), relPath('../priv/tracker/js/p.js'))
|
||||
fs.copyFileSync(relPath('../priv/tracker/js/plausible.js'), relPath('../priv/tracker/js/analytics.js'))
|
||||
|
||||
Loading…
Reference in New Issue