Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Simple script format (#31)
Uku Tahte1ed9d59d906
diff --git a/assets/js/p.js b/assets/js/p.jsindex 929b79a7dc..c494ab5eca 100644--- a/assets/js/p.js+++ b/assets/js/p.js@@ -116,6 +116,7 @@page();}}+ window.addEventListener('popstate', page)}function configure(key, val) {diff --git a/assets/js/plausible.js b/assets/js/plausible.jsindex cee5003a9d..27433abf03 100644--- a/assets/js/plausible.js+++ b/assets/js/plausible.js@@ -111,11 +111,12 @@var his = window.historyif (his.pushState) {- var originalFn = his['pushState']+ var originalPushState = his['pushState']his.pushState = function() {- originalFn.apply(this, arguments)+ originalPushState.apply(this, arguments)page();}+ window.addEventListener('popstate', page)}const queue = (window.plausible && window.plausible.q) || []diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.exindex 4a163c2f9f..f39b3406b7 100644--- a/lib/plausible_web/controllers/site_controller.ex+++ b/lib/plausible_web/controllers/site_controller.ex@@ -21,7 +21,7 @@ defmodule PlausibleWeb.SiteController do|> put_session(site.domain <> "_offer_email_report", true)|> redirect(to: "/#{URI.encode_www_form(site.domain)}/snippet"){:error, :site, changeset, _} ->- render(conn, "new.html", changeset: changeset)+ render(conn, "new.html", changeset: changeset, layout: {PlausibleWeb.LayoutView, "focus.html"})endenddiff --git a/lib/plausible_web/templates/site/settings.html.eex b/lib/plausible_web/templates/site/settings.html.eexindex d15b0ed47d..f877632f1e 100644--- a/lib/plausible_web/templates/site/settings.html.eex+++ b/lib/plausible_web/templates/site/settings.html.eex@@ -214,15 +214,11 @@<div class="my-4"><p>Include this snippet in the <code><head></code> of your website.</p><div class="relative">- <%= textarea f, :domain, id: "snippet_code", class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-2 resize-none", value: snippet(), rows: 9 %>+ <%= textarea f, :domain, id: "snippet_code", class: "transition overflow-hidden bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 pr-6 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-2 resize-none", value: snippet(@site), rows: 2 %><a onclick="var textarea = document.getElementById('snippet_code'); textarea.focus(); textarea.select(); document.execCommand('copy');" href="javascript:void(0)" class="no-underline text-indigo text-sm hover:underline"><svg class="absolute text-indigo" style="top: 24px; right: 12px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg></a></div>- <div class="mt-4 text-sm">- Is your website a single-page application?- <%= link("Read the docs", class: "text-indigo hover:underline", to: "https://docs.plausible.io/single-page-application-support", target: "_blank") %>- </div></div><% end %>diff --git a/lib/plausible_web/templates/site/snippet.html.eex b/lib/plausible_web/templates/site/snippet.html.eexindex 489e29bd8d..be0e40906d 100644--- a/lib/plausible_web/templates/site/snippet.html.eex+++ b/lib/plausible_web/templates/site/snippet.html.eex@@ -4,16 +4,13 @@</div><div class="my-4"><p>Paste this snippet in the <code><head></code> of your website.</p>+<div class="relative">- <%= textarea f, :domain, id: "snippet_code", class: "transition bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-4 resize-none", value: snippet(), rows: 9 %>+ <%= textarea f, :domain, id: "snippet_code", class: "transition overflow-hidden bg-grey-lighter appearance-none border border-transparent rounded w-full p-2 pr-6 text-grey-darker leading-normal appearance-none focus:outline-none focus:bg-white focus:border-grey-light text-xs mt-4 resize-none", value: snippet(@site), rows: 2 %><a onclick="var textarea = document.getElementById('snippet_code'); textarea.focus(); textarea.select(); document.execCommand('copy');" href="javascript:void(0)" class="no-underline text-indigo text-sm hover:underline"><svg class="absolute text-indigo" style="top: 24px; right: 12px;" xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg></a></div>- <div class="mt-4 text-sm">- Is your website a single-page application?- <%= link("Read the docs", class: "text-indigo hover:underline", to: "https://docs.plausible.io/single-page-application-support", target: "_blank") %>- </div></div><%= link("Start collecting data →", class: "button mt-4 w-full", to: "/#{URI.encode_www_form(@site.domain)}") %><% end %>diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.exindex b00243fbf3..375aa50db5 100644--- a/lib/plausible_web/views/site_view.ex+++ b/lib/plausible_web/views/site_view.ex@@ -13,17 +13,9 @@ defmodule PlausibleWeb.SiteView doPlausibleWeb.Endpoint.url() <> "/share/" <> link.slugend- def snippet() do+ def snippet(site) do"""- <script>- (function (w,d,s,o,f,js,fjs) {- w[o] = w[o] || function () { (w[o].q = w[o].q || []).push(arguments) };- js = d.createElement(s), fjs = d.getElementsByTagName(s)[0];- js.id = o; js.src = f; js.async = 1; fjs.parentNode.insertBefore(js, fjs);- }(window, document, 'script', 'plausible', 'https://plausible.io/js/p.js'));-- plausible('page')- </script>\+ <script async defer data-domain="#{site.domain}" src="https://plausibe.io/js/plausible.js"></script>"""endend