mirror of
https://github.com/plausible/analytics.git
synced 2024-12-23 01:22:15 +03:00
Makes the tracker and its payload smaller (#296)
This commit is contained in:
parent
76896f7cee
commit
1519359bbf
@ -55,6 +55,15 @@ defmodule PlausibleWeb.Api.ExternalController do
|
||||
end
|
||||
|
||||
defp create_event(conn, params) do
|
||||
params = %{
|
||||
"name" => params["n"] || params["name"],
|
||||
"url" => params["u"] || params["url"],
|
||||
"referrer" => params["r"] || params["referrer"],
|
||||
"source" => params["s"] || params["source"],
|
||||
"domain" => params["d"] || params["domain"],
|
||||
"screen_width" => params["w"] || params["screen_width"],
|
||||
}
|
||||
|
||||
uri = params["url"] && URI.parse(URI.decode(params["url"]))
|
||||
user_agent = Plug.Conn.get_req_header(conn, "user-agent") |> List.first()
|
||||
|
||||
|
@ -1 +1 @@
|
||||
!function(o,s){"use strict";var i=o.location,l=o.document,e=l.querySelector('[src*="'+s+'"]'),c={domain:e&&e.getAttribute("data-domain")||i.hostname};function u(e){console.warn("[Plausible] Ignore event: "+e)}function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(i.hostname)||"file:"===i.protocol)return u("running locally");if("prerender"===l.visibilityState)return u("prerendering");var n,a={};a.name=e,a.url=i.protocol+"//"+i.hostname+i.pathname+i.search,a.domain=c.domain,a.referrer=l.referrer||null,a.source=(n=i.search.match(/[?&](ref|source|utm_source)=([^?&]+)/))?n[2]:null,a.user_agent=o.navigator.userAgent,a.screen_width=o.innerWidth;var r=new XMLHttpRequest;r.open("POST",s+"/api/event",!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(a)),r.onreadystatechange=function(){4==r.readyState&&t&&t.callback&&t.callback()}}function n(){t("pageview")}try{var a,r=o.history;r.pushState&&(a=r.pushState,r.pushState=function(){a.apply(this,arguments),n()},o.addEventListener("popstate",n));var p=o.plausible&&o.plausible.q||[];o.plausible=t;for(var h=0;h<p.length;h++)t.apply(this,p[h]);n()}catch(e){(new Image).src=s+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
||||
!function(i,o){"use strict";var s=i.location,l=i.document,e=l.querySelector('[src*="'+o+'"]'),u={domain:e&&e.getAttribute("data-domain")||s.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(s.hostname)||"file:"===s.protocol)return c("running locally");if("prerender"===l.visibilityState)return c("prerendering");var n,a={};a.n=e,a.u=s.href,a.d=u.domain,a.r=l.referrer||null,a.s=(n=s.search.match(/[?&](ref|source|utm_source)=([^?&]+)/))?n[2]:null,a.w=i.innerWidth;var r=new XMLHttpRequest;r.open("POST",o+"/api/event",!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(a)),r.onreadystatechange=function(){4==r.readyState&&t&&t.callback&&t.callback()}}function n(){t("pageview")}try{var a,r=i.history;r.pushState&&(a=r.pushState,r.pushState=function(){a.apply(this,arguments),n()},i.addEventListener("popstate",n));var p=i.plausible&&i.plausible.q||[];i.plausible=t;for(var d=0;d<p.length;d++)t.apply(this,p[d]);n()}catch(e){(new Image).src=o+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
@ -1 +1 @@
|
||||
!function(r,a){"use strict";function o(e){console.warn("[Plausible] Ignoring event because "+e)}function c(){var e=r.location.search.match(/[?&](ref|source|utm_source)=([^?&]+)/);return e?e[2]:null}function s(){var e,t,n=JSON.parse((e="plausible_user",(t=document.cookie.match(new RegExp("(?:^|; )"+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)")))?decodeURIComponent(t[1]):null));return n?{initial_referrer:n.initial_referrer&&decodeURIComponent(n.initial_referrer),initial_source:n.initial_source&&decodeURIComponent(n.initial_source)}:(n={initial_referrer:r.document.referrer||null,initial_source:c()},function(e,t){var n=new Date;n.setTime(n.getTime()+94608e6);var i="; expires="+n.toUTCString();document.cookie=e+"="+(t||"")+i+"; samesite=strict; path=/"}("plausible_user",JSON.stringify({initial_referrer:n.initial_referrer&&encodeURIComponent(n.initial_referrer),initial_source:n.initial_source&&encodeURIComponent(n.initial_source)})),n)}function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(r.location.hostname))return o("website is running locally");if("file:"===r.location.protocol)return o("website is running locally");if("prerender"===r.document.visibilityState)return o("document is prerendering");var n=l.trackAcquisition?s():{};n.name=e,n.url=r.location.protocol+"//"+r.location.hostname+r.location.pathname+r.location.search,n.domain=l.domain,n.referrer=r.document.referrer||null,n.source=c(),n.user_agent=r.navigator.userAgent,n.screen_width=r.innerWidth;var i=new XMLHttpRequest;i.open("POST",a+"/api/event",!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(n)),i.onreadystatechange=function(){i.readyState==XMLHttpRequest.DONE&&t&&t.callback&&t.callback()}}function n(e){t("pageview",e)}try{var l={domain:r.location.hostname},i={page:n,trigger:t,trackPushState:function(){var e,t=r.history;t.pushState&&(e=t.pushState,t.pushState=function(){e.apply(this,arguments),n()}),r.addEventListener("popstate",n)},configure:function(e,t){l[e]=t}},e=r.plausible.q||[];r.plausible=function(){var e=[].slice.call(arguments),t=e.shift();i[t].apply(this,e)};for(var u=0;u<e.length;u++)r.plausible.apply(this,e[u])}catch(e){(new Image).src=a+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
||||
!function(r,o){"use strict";function a(e){console.warn("[Plausible] Ignoring event because "+e)}function c(){var e=r.location.search.match(/[?&](ref|source|utm_source)=([^?&]+)/);return e?e[2]:null}function l(){var e,t,n=JSON.parse((e="plausible_user",(t=document.cookie.match(new RegExp("(?:^|; )"+e.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g,"\\$1")+"=([^;]*)")))?decodeURIComponent(t[1]):null));return n?{initial_referrer:n.initial_referrer&&decodeURIComponent(n.initial_referrer),initial_source:n.initial_source&&decodeURIComponent(n.initial_source)}:(n={initial_referrer:r.document.referrer||null,initial_source:c()},function(e,t){var n=new Date;n.setTime(n.getTime()+94608e6);var i="; expires="+n.toUTCString();document.cookie=e+"="+(t||"")+i+"; samesite=strict; path=/"}("plausible_user",JSON.stringify({initial_referrer:n.initial_referrer&&encodeURIComponent(n.initial_referrer),initial_source:n.initial_source&&encodeURIComponent(n.initial_source)})),n)}function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(r.location.hostname))return a("website is running locally");if("file:"===r.location.protocol)return a("website is running locally");if("prerender"===r.document.visibilityState)return a("document is prerendering");var n=s.trackAcquisition?l():{};n.n=e,n.u=r.location.protocol+"//"+r.location.hostname+r.location.pathname+r.location.search,n.d=s.domain,n.r=r.document.referrer||null,n.s=c(),n.w=r.innerWidth;var i=new XMLHttpRequest;i.open("POST",o+"/api/event",!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(n)),i.onreadystatechange=function(){i.readyState==XMLHttpRequest.DONE&&t&&t.callback&&t.callback()}}function n(e){t("pageview",e)}try{var s={domain:r.location.hostname},i={page:n,trigger:t,trackPushState:function(){var e,t=r.history;t.pushState&&(e=t.pushState,t.pushState=function(){e.apply(this,arguments),n()}),r.addEventListener("popstate",n)},configure:function(e,t){s[e]=t}},e=r.plausible.q||[];r.plausible=function(){var e=[].slice.call(arguments),t=e.shift();i[t].apply(this,e)};for(var u=0;u<e.length;u++)r.plausible.apply(this,e[u])}catch(e){(new Image).src=o+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
@ -1 +1 @@
|
||||
!function(o,s){"use strict";var i=o.location,l=o.document,e=l.querySelector('[src*="'+s+'"]'),c={domain:e&&e.getAttribute("data-domain")||i.hostname};function u(e){console.warn("[Plausible] Ignore event: "+e)}function t(e,t){if(/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(i.hostname)||"file:"===i.protocol)return u("running locally");if("prerender"===l.visibilityState)return u("prerendering");var n,a={};a.name=e,a.url=i.protocol+"//"+i.hostname+i.pathname+i.search,a.domain=c.domain,a.referrer=l.referrer||null,a.source=(n=i.search.match(/[?&](ref|source|utm_source)=([^?&]+)/))?n[2]:null,a.user_agent=o.navigator.userAgent,a.screen_width=o.innerWidth;var r=new XMLHttpRequest;r.open("POST",s+"/api/event",!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(a)),r.onreadystatechange=function(){4==r.readyState&&t&&t.callback&&t.callback()}}function n(){t("pageview")}try{var a,r=o.history;r.pushState&&(a=r.pushState,r.pushState=function(){a.apply(this,arguments),n()},o.addEventListener("popstate",n));var p=o.plausible&&o.plausible.q||[];o.plausible=t;for(var h=0;h<p.length;h++)t.apply(this,p[h]);n()}catch(e){(new Image).src=s+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
||||
!function(i,o){"use strict";var s=i.location,l=i.document,e=l.querySelector('[src*="'+o+'"]'),u={domain:e&&e.getAttribute("data-domain")||s.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(s.hostname)||"file:"===s.protocol)return c("running locally");if("prerender"===l.visibilityState)return c("prerendering");var n,a={};a.n=e,a.u=s.href,a.d=u.domain,a.r=l.referrer||null,a.s=(n=s.search.match(/[?&](ref|source|utm_source)=([^?&]+)/))?n[2]:null,a.w=i.innerWidth;var r=new XMLHttpRequest;r.open("POST",o+"/api/event",!0),r.setRequestHeader("Content-Type","text/plain"),r.send(JSON.stringify(a)),r.onreadystatechange=function(){4==r.readyState&&t&&t.callback&&t.callback()}}function n(){t("pageview")}try{var a,r=i.history;r.pushState&&(a=r.pushState,r.pushState=function(){a.apply(this,arguments),n()},i.addEventListener("popstate",n));var p=i.plausible&&i.plausible.q||[];i.plausible=t;for(var d=0;d<p.length;d++)t.apply(this,p[d]);n()}catch(e){(new Image).src=o+"/api/error?message="+encodeURIComponent(e.message)}}(window,"<%= base_url %>");
|
@ -57,13 +57,12 @@
|
||||
if (window.document.visibilityState === 'prerender') return ignore('document is prerendering');
|
||||
|
||||
var payload = CONFIG['trackAcquisition'] ? getUserData() : {}
|
||||
payload.name = eventName
|
||||
payload.url = getUrl()
|
||||
payload.domain = CONFIG['domain']
|
||||
payload.referrer = window.document.referrer || null
|
||||
payload.source = getSourceFromQueryParam()
|
||||
payload.user_agent = window.navigator.userAgent
|
||||
payload.screen_width = window.innerWidth
|
||||
payload.n = eventName
|
||||
payload.u = getUrl()
|
||||
payload.d = CONFIG['domain']
|
||||
payload.r = window.document.referrer || null
|
||||
payload.s = getSourceFromQueryParam()
|
||||
payload.w = window.innerWidth
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('POST', plausibleHost + '/api/event', true);
|
||||
|
@ -12,10 +12,6 @@
|
||||
console.warn('[Plausible] Ignore event: ' + reason);
|
||||
}
|
||||
|
||||
function getUrl() {
|
||||
return location.protocol + '//' + location.hostname + location.pathname + location.search;
|
||||
}
|
||||
|
||||
function getSourceFromQueryParam() {
|
||||
var result = location.search.match(/[?&](ref|source|utm_source)=([^?&]+)/);
|
||||
return result ? result[2] : null
|
||||
@ -26,13 +22,12 @@
|
||||
if (document.visibilityState === 'prerender') return ignore('prerendering');
|
||||
|
||||
var payload = {}
|
||||
payload.name = eventName
|
||||
payload.url = getUrl()
|
||||
payload.domain = CONFIG['domain']
|
||||
payload.referrer = document.referrer || null
|
||||
payload.source = getSourceFromQueryParam()
|
||||
payload.user_agent = window.navigator.userAgent
|
||||
payload.screen_width = window.innerWidth
|
||||
payload.n = eventName
|
||||
payload.u = location.href
|
||||
payload.d = CONFIG['domain']
|
||||
payload.r = document.referrer || null
|
||||
payload.s = getSourceFromQueryParam()
|
||||
payload.w = window.innerWidth
|
||||
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('POST', plausibleHost + '/api/event', true);
|
||||
|
Loading…
Reference in New Issue
Block a user