pull/2859/head
Adam Rutkowski 4 years ago
parent f92847e8c1
commit e3b8067628

@ -5,6 +5,23 @@ import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
import "phoenix_html"
import 'alpinejs'
import { Socket } from "phoenix"
import { LiveSocket } from "phoenix_live_view"
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, { params: { _csrf_token: csrfToken } })
// Connect if there are any LiveViews on the page
liveSocket.connect()
// Expose liveSocket on window for web console debug logs and latency simulation:
// >> liveSocket.enableDebug()
// >> liveSocket.enableLatencySim(1000)
// The latency simulator is enabled for the duration of the browser session.
// Call disableLatencySim() to disable:
// >> liveSocket.disableLatencySim()
window.liveSocket = liveSocket
const triggers = document.querySelectorAll('[data-dropdown-trigger]')
for (const trigger of triggers) {
@ -49,7 +66,7 @@ if (registerForm) {
}
}
/* eslint-disable-next-line no-undef */
plausible('Signup', {callback: submitForm});
plausible('Signup', { callback: submitForm });
})
}
@ -58,12 +75,12 @@ const changelogNotification = document.getElementById('changelog-notification')
if (changelogNotification) {
showChangelogNotification(changelogNotification)
fetch('https://plausible.io/changes.txt', {headers: {'Content-Type': 'text/plain'}})
fetch('https://plausible.io/changes.txt', { headers: { 'Content-Type': 'text/plain' } })
.then((res) => res.text())
.then((res) => {
localStorage.lastChangelogUpdate = new Date(res).getTime()
showChangelogNotification(changelogNotification)
})
})
}
function showChangelogNotification(el) {
@ -71,7 +88,7 @@ function showChangelogNotification(el) {
const lastChecked = Number(localStorage.lastChangelogClick)
const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked
const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72
const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72
if ((!lastChecked || hasNewUpdateSinceLastClicked) && notOlderThanThreeDays) {
el.innerHTML = `
<a href="https://plausible.io/changelog" target="_blank">

@ -35,8 +35,9 @@
"debounce-promise": "^3.1.2",
"iframe-resizer": "^4.3.2",
"mini-css-extract-plugin": "^1.6.0",
"phoenix": "1.5.0",
"phoenix_html": "2.12",
"phoenix": "^1.7.2",
"phoenix_html": "^3.3.1",
"phoenix_live_view": "^0.18.18",
"postcss": "^8.3.0",
"postcss-loader": "^6.1.1",
"react": "^16.13.1",
@ -68,6 +69,12 @@
"webpack-bundle-analyzer": "^4.4.2"
}
},
"../../../../../../deps/phoenix": {
"extraneous": true
},
"../../../../../../deps/phoenix_html": {
"extraneous": true
},
"node_modules/@ampproject/remapping": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz",
@ -6805,14 +6812,19 @@
}
},
"node_modules/phoenix": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/phoenix/-/phoenix-1.5.0.tgz",
"integrity": "sha512-Vzz6eb64BEufIXTVkTcT5HiNdRyLY2DF/l2eN1LaeedRbBhGCsdRWdDISFjBSjxODjqY+w2NmSzBeHM8MieLRw=="
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/phoenix/-/phoenix-1.7.2.tgz",
"integrity": "sha512-jwWDOsUNEQZkLNSwzfLJ6AMFUkyZ+ILU+NkBBtoAK020QPpV/dYEQHGMQoFScj89MFjJlLdkE1W97i8S+4FdGg=="
},
"node_modules/phoenix_html": {
"version": "2.12.0",
"resolved": "https://registry.npmjs.org/phoenix_html/-/phoenix_html-2.12.0.tgz",
"integrity": "sha512-UulYUsew5h2qeCSIMs1VWINkkpCauEn8uEq0zt2Ky9FpfEW6LsasMJ+Vgi01tUBbBFEy73E+sUvucQ+okL69Aw=="
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/phoenix_html/-/phoenix_html-3.3.1.tgz",
"integrity": "sha512-t/9Saqpe8vznZYHMDim7HS32Dd2/rKf3+uxuKKNRADLpGXVIDjselOY6pK8aNaLiY2gnlqsoz6yIpUBuoLT63w=="
},
"node_modules/phoenix_live_view": {
"version": "0.18.18",
"resolved": "https://registry.npmjs.org/phoenix_live_view/-/phoenix_live_view-0.18.18.tgz",
"integrity": "sha512-KVWZPH4XRCWofBbxNv4jSQ5clxBV1Mo9pkw5CmcMZDYLzdsk47am9+FiiEj7fapgYKnPNtPNIHZNKj2/yzgzZw=="
},
"node_modules/picocolors": {
"version": "1.0.0",
@ -14775,14 +14787,19 @@
"integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw=="
},
"phoenix": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/phoenix/-/phoenix-1.5.0.tgz",
"integrity": "sha512-Vzz6eb64BEufIXTVkTcT5HiNdRyLY2DF/l2eN1LaeedRbBhGCsdRWdDISFjBSjxODjqY+w2NmSzBeHM8MieLRw=="
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/phoenix/-/phoenix-1.7.2.tgz",
"integrity": "sha512-jwWDOsUNEQZkLNSwzfLJ6AMFUkyZ+ILU+NkBBtoAK020QPpV/dYEQHGMQoFScj89MFjJlLdkE1W97i8S+4FdGg=="
},
"phoenix_html": {
"version": "2.12.0",
"resolved": "https://registry.npmjs.org/phoenix_html/-/phoenix_html-2.12.0.tgz",
"integrity": "sha512-UulYUsew5h2qeCSIMs1VWINkkpCauEn8uEq0zt2Ky9FpfEW6LsasMJ+Vgi01tUBbBFEy73E+sUvucQ+okL69Aw=="
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/phoenix_html/-/phoenix_html-3.3.1.tgz",
"integrity": "sha512-t/9Saqpe8vznZYHMDim7HS32Dd2/rKf3+uxuKKNRADLpGXVIDjselOY6pK8aNaLiY2gnlqsoz6yIpUBuoLT63w=="
},
"phoenix_live_view": {
"version": "0.18.18",
"resolved": "https://registry.npmjs.org/phoenix_live_view/-/phoenix_live_view-0.18.18.tgz",
"integrity": "sha512-KVWZPH4XRCWofBbxNv4jSQ5clxBV1Mo9pkw5CmcMZDYLzdsk47am9+FiiEj7fapgYKnPNtPNIHZNKj2/yzgzZw=="
},
"picocolors": {
"version": "1.0.0",

@ -37,8 +37,9 @@
"debounce-promise": "^3.1.2",
"iframe-resizer": "^4.3.2",
"mini-css-extract-plugin": "^1.6.0",
"phoenix": "1.5.0",
"phoenix_html": "2.12",
"phoenix": "^1.7.2",
"phoenix_html": "^3.3.1",
"phoenix_live_view": "^0.18.18",
"postcss": "^8.3.0",
"postcss-loader": "^6.1.1",
"react": "^16.13.1",

@ -4,6 +4,7 @@ config :plausible,
ecto_repos: [Plausible.Repo, Plausible.IngestRepo]
config :plausible, PlausibleWeb.Endpoint,
live_view: [signing_salt: "F19F4RBTbQ66AiYD"],
pubsub_server: Plausible.PubSub,
render_errors: [
view: PlausibleWeb.ErrorView,

@ -37,7 +37,7 @@ defmodule Plausible.Funnel do
timestamps()
end
def changeset(funnel, attrs \\ %{}) do
def changeset(funnel \\ %__MODULE__{}, attrs \\ %{}) do
funnel
|> cast(attrs, [:name])
|> cast_assoc(:steps, with: &Step.changeset/2)

@ -2,6 +2,15 @@ defmodule PlausibleWeb.Endpoint do
use Sentry.PlugCapture
use Phoenix.Endpoint, otp_app: :plausible
@session_options [
store: :cookie,
key: "_plausible_key",
signing_salt: "3IL0ob4k",
# 5 years, this is super long but the SlidingSessionTimeout will log people out if they don't return for 2 weeks
max_age: 60 * 60 * 24 * 365 * 5,
extra: "SameSite=Lax"
]
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
@ -43,13 +52,9 @@ defmodule PlausibleWeb.Endpoint do
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session,
store: :cookie,
key: "_plausible_key",
signing_salt: "3IL0ob4k",
# 5 years, this is super long but the SlidingSessionTimeout will log people out if they don't return for 2 weeks
max_age: 60 * 60 * 24 * 365 * 5,
extra: "SameSite=Lax"
plug Plug.Session, @session_options
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
plug CORSPlug
plug PlausibleWeb.Router

@ -0,0 +1,43 @@
defmodule PlausibleWeb.Live.FunnelSettings do
use Phoenix.LiveView
use Phoenix.HTML
alias Plausible.{Sites, Goals, Funnels}
def mount(
_params,
%{"site_id" => _site_id, "domain" => domain, "current_user_id" => user_id},
socket
) do
site = Sites.get_for_user!(user_id, domain, [:owner, :admin])
funnels = Funnels.list(site)
goals = Goals.for_site(site)
{:ok, assign(socket, site: site, funnels: funnels, goals: goals, add_funnel?: false)}
end
def render(assigns) do
~H"""
<%= if @add_funnel? do %>
<.live_component module={PlausibleWeb.Live.FunnelSettings.Form} id="funnelForm" site={@site} form={to_form(Plausible.Funnel.changeset())} goals={@goals} />
<% else %>
<.live_component module={PlausibleWeb.Live.FunnelSettings.List} id="funnelsList" funnels={@funnels} site={@site} />
<button type="button" class="button mt-6" phx-click="add_funnel">+ Add funnel</button>
<% end %>
"""
end
def handle_event("add_funnel", _value, socket) do
{:noreply, assign(socket, :add_funnel?, true)}
end
def handle_event("cancel_add_funnel", _value, socket) do
{:noreply, assign(socket, :add_funnel?, false)}
end
def handle_event("validate", value, socket) do
IO.inspect(value, label: :validate)
{:noreply, socket}
end
end

@ -0,0 +1,86 @@
defmodule PlausibleWeb.Live.FunnelSettings.Form do
use Phoenix.LiveComponent
use Phoenix.HTML
# good
def mount(socket) do
{:ok, assign(socket, step_count: 2)}
end
def update(assigns, socket) do
{:ok, assign(socket, form: assigns.form, goals: assigns.goals)}
end
def render(assigns) do
~H"""
<div class="grid grid-cols-4 gap-6 mt-6">
<div class="col-span-4 sm:col-span-2">
<.form :let={f} for={@form} phx-change="validate" phx-submit="save">
<%= label f, "Funnel name", class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<.input field={@form[:name]} />
<%= label f, "Funnel Steps", class: "mt-6 block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= for _step_number <- 1..@step_count do %>
<.select goals={@goals} myself={@myself} />
<% end %>
<%= if @step_count < 5 do %>
<a class="underline text-indigo-600 cursor-pointer" phx-click="add-step" phx-target={@myself}>Add another step</a>
<% end %>
<br/><hr/>
<button type="button" class="button mt-6">Save</button>
<button type="button" class="button mt-6" phx-click="cancel_add_funnel">Cancel</button>
</.form>
</div>
</div>
"""
end
attr :field, Phoenix.HTML.FormField
def input(assigns) do
~H"""
<input type="text" id={@field.id} name={@field.name} value={@field.value} class="focus:ring-indigo-500 focus:border-indigo-500 dark:bg-gray-900 dark:text-gray-300 block w-full rounded-md sm:text-sm border-gray-300 dark:border-gray-500" />
"""
end
attr :goals, :map, required: true
attr :myself, :any, required: true
def select(assigns) do
~H"""
<select phx-change="changed" phx-target={@myself} name="steps[]" class="dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" id="site_timezone">
<%= for goal <- @goals do %>
<option value={goal.id}>
<%= Plausible.Goal.display_name(goal) %>
</option>
<% end %>
</select>
"""
end
def handle_event("add-step", _value, socket) do
step_count = socket.assigns.step_count
if step_count < 5 do
{:noreply, assign(socket, step_count: step_count + 1)}
else
{:noreply, socket}
end
end
def handle_event(event, value, socket) do
IO.inspect(event, label: :event)
IO.inspect(value, label: :value)
[_ | except_first] = socket.assigns.goals
{:noreply, assign(socket, goals: except_first)}
end
end
# goal_options = [{"N/A", ""} | Enum.map(@goals, fn goal -> {Plausible.Goal.display_name(goal), goal.id} end)] %>
#
# end

@ -0,0 +1,25 @@
defmodule PlausibleWeb.Live.FunnelSettings.List do
use Phoenix.LiveComponent
use Phoenix.HTML
def render(assigns) do
~H"""
<div>
<%= if Enum.count(@funnels) > 0 do %>
<div class="mt-4">
<%= for funnel <- @funnels do %>
<div class="border-b border-gray-300 dark:border-gray-500 py-3 flex justify-between">
<span class="text-sm font-medium text-gray-900 dark:text-gray-100"><%= funnel.name %></span>
<%= button(to: "", method: :delete, class: "text-sm text-red-600", data: [confirm: "Are you sure you want to remove funnel '#{funnel.name}'? This will just affect the UI, all of your analytics data will stay intact."]) do %>
<svg class="feather feather-sm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>
<% end %>
</div>
<% end %>
</div>
<% else %>
<div class="mt-4 dark:text-gray-100">No funnels configured for this site yet</div>
<% end %>
</div>
"""
end
end

@ -6,7 +6,7 @@ defmodule PlausibleWeb.Router do
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :fetch_live_flash
plug :put_secure_browser_headers
plug PlausibleWeb.FirstLaunchPlug, redirect_to: "/register"
plug PlausibleWeb.SessionTimeoutPlug, timeout_after_seconds: @two_weeks_in_seconds
@ -247,10 +247,10 @@ defmodule PlausibleWeb.Router do
get "/:website/settings/visibility", SiteController, :settings_visibility
get "/:website/settings/goals", SiteController, :settings_goals
# get "/:website/settings/funnels", SiteController, :settings_funnels
get "/:website/settings/funnels", SiteController, :settings_funnels
# post "/:website/settings/funnels", SiteController, :save_funnel
live "/:website/settings/funnels", FunnelSettingsLive
# live "/:website/settings/funnels", Live.FunnelSettings
get "/:website/settings/search-console", SiteController, :settings_search_console
get "/:website/settings/email-reports", SiteController, :settings_email_reports

@ -5,6 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="Plausible is a lightweight and open-source web analytics tool. Your website data is 100% yours and the privacy of your visitors is respected."/>
<meta name="csrf-token" content=<%= Plug.CSRFProtection.get_csrf_token() %> />
<link rel="icon" type="image/png" sizes="32x32" href="<%= PlausibleWeb.Router.Helpers.static_path(@conn, "/images/icon/plausible_favicon.png") %>">
<link rel="apple-touch-icon" href="/images/icon/apple-touch-icon.png">
<title><%= assigns[:title] || "Plausible · Simple, privacy-friendly alternative to Google Analytics" %></title>

@ -1,41 +1,10 @@
<header class="relative">
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">Your Funnels</h2>
</header>
<ul>
<%= for funnel <- @funnels do %>
<li>[ID: <%= funnel.id %>] <a href="#<%= funnel.id %>"><%= funnel.name %></a></li>
<% end %>
</ul>
<hr/>
<header class="relative">
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">New funnel</h2>
</header>
<% goal_options = [{"N/A", ""} | Enum.map(@goals, fn goal -> {Plausible.Goal.display_name(goal), goal.id} end)] %>
<%= form_for @conn, "/#{@site.domain}/settings/funnels", [class: "max-w-sm"], fn f -> %>
<%= label f, :funnel_name, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= text_input f, :funnel_name, class: "shadow-sm dark:bg-gray-900 dark:text-gray-300 focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 dark:border-gray-500 rounded-md dark:bg-gray-800" %>
<%= label f, :step_1, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= select f, :step_1, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
<%= label f, :step_2, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= select f, :step_2, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
<%= label f, :step_3, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= select f, :step_3, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
<%= label f, :step_4, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= select f, :step_4, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
<%= label f, :step_5, class: "block text-sm font-medium text-gray-700 dark:text-gray-300" %>
<%= select f, :step_5, goal_options, class: "dark:bg-gray-900 mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 dark:border-gray-500 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md dark:text-gray-100 cursor-pointer" %>
<%= submit "Save funnel", class: "button mt-4" %>
<% end %>
<div class="shadow bg-white dark:bg-gray-800 sm:rounded-md sm:overflow-hidden py-6 px-4 sm:p-6">
<header class="relative">
<h2 class="text-lg leading-6 font-medium text-gray-900 dark:text-gray-100">Funnels</h2>
<p class="mt-1 text-sm leading-5 text-gray-500 dark:text-gray-200">Compose goals into funnels</p>
<%= link(to: "https://plausible.io/docs/goal-conversions", target: "_blank", rel: "noreferrer") do %>
<svg class="w-6 h-6 absolute top-0 right-0 text-gray-400" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z" clip-rule="evenodd"></path></svg>
<% end %>
</header>
<%= live_render(@conn, PlausibleWeb.Live.FunnelSettings, session: %{"site_id" => @site.id, "domain" => @site.domain}) %>
</div>

Loading…
Cancel
Save