mirror of
https://github.com/plausible/analytics.git
synced 2024-11-23 20:13:31 +03:00
Simple script format (#31)
* New script format * Add popstate listener to p.js * Render site creation error with focus
This commit is contained in:
parent
1e417f03a9
commit
e1ed9d59d9
@ -116,6 +116,7 @@
|
|||||||
page();
|
page();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
window.addEventListener('popstate', page)
|
||||||
}
|
}
|
||||||
|
|
||||||
function configure(key, val) {
|
function configure(key, val) {
|
||||||
|
@ -111,11 +111,12 @@
|
|||||||
|
|
||||||
var his = window.history
|
var his = window.history
|
||||||
if (his.pushState) {
|
if (his.pushState) {
|
||||||
var originalFn = his['pushState']
|
var originalPushState = his['pushState']
|
||||||
his.pushState = function() {
|
his.pushState = function() {
|
||||||
originalFn.apply(this, arguments)
|
originalPushState.apply(this, arguments)
|
||||||
page();
|
page();
|
||||||
}
|
}
|
||||||
|
window.addEventListener('popstate', page)
|
||||||
}
|
}
|
||||||
|
|
||||||
const queue = (window.plausible && window.plausible.q) || []
|
const queue = (window.plausible && window.plausible.q) || []
|
||||||
|
@ -21,7 +21,7 @@ defmodule PlausibleWeb.SiteController do
|
|||||||
|> put_session(site.domain <> "_offer_email_report", true)
|
|> put_session(site.domain <> "_offer_email_report", true)
|
||||||
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/snippet")
|
|> redirect(to: "/#{URI.encode_www_form(site.domain)}/snippet")
|
||||||
{:error, :site, changeset, _} ->
|
{:error, :site, changeset, _} ->
|
||||||
render(conn, "new.html", changeset: changeset)
|
render(conn, "new.html", changeset: changeset, layout: {PlausibleWeb.LayoutView, "focus.html"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -214,15 +214,11 @@
|
|||||||
<div class="my-4">
|
<div class="my-4">
|
||||||
<p>Include this snippet in the <code><head></code> of your website.</p>
|
<p>Include this snippet in the <code><head></code> of your website.</p>
|
||||||
<div class="relative">
|
<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">
|
<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>
|
<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>
|
</a>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
@ -4,16 +4,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="my-4">
|
<div class="my-4">
|
||||||
<p>Paste this snippet in the <code><head></code> of your website.</p>
|
<p>Paste this snippet in the <code><head></code> of your website.</p>
|
||||||
|
|
||||||
<div class="relative">
|
<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">
|
<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>
|
<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>
|
</a>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
<%= link("Start collecting data →", class: "button mt-4 w-full", to: "/#{URI.encode_www_form(@site.domain)}") %>
|
<%= link("Start collecting data →", class: "button mt-4 w-full", to: "/#{URI.encode_www_form(@site.domain)}") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -13,17 +13,9 @@ defmodule PlausibleWeb.SiteView do
|
|||||||
PlausibleWeb.Endpoint.url() <> "/share/" <> link.slug
|
PlausibleWeb.Endpoint.url() <> "/share/" <> link.slug
|
||||||
end
|
end
|
||||||
|
|
||||||
def snippet() do
|
def snippet(site) do
|
||||||
"""
|
"""
|
||||||
<script>
|
<script async defer data-domain="#{site.domain}" src="https://plausibe.io/js/plausible.js"></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>\
|
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user