From f2fcf1cc4204179a707c93c983efadf1aa6e785b Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Wed, 17 Jul 2024 12:37:47 +0200 Subject: [PATCH] fix: untested fixes for IS-11 --- .../templates/site/snippet.html.heex | 2 +- lib/plausible_web/views/site_view.ex | 8 +++--- tracker/src/plausible.js | 26 +++++-------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/plausible_web/templates/site/snippet.html.heex b/lib/plausible_web/templates/site/snippet.html.heex index 729962354dc7..834959bd209a 100644 --- a/lib/plausible_web/templates/site/snippet.html.heex +++ b/lib/plausible_web/templates/site/snippet.html.heex @@ -20,7 +20,7 @@ id: "snippet_code", class: "transition overflow-hidden bg-gray-100 dark:bg-gray-900 appearance-none border border-transparent rounded w-full p-2 pr-6 text-gray-700 dark:text-gray-300 leading-normal appearance-none focus:outline-none focus:bg-white dark:focus:bg-gray-800 focus:border-gray-400 dark:focus:border-gray-500 text-xs mt-4 resize-none", - value: render_snippet(@site), + value: render_snippet(@site, ["live-view"]), rows: 3, readonly: "readonly" ) %> diff --git a/lib/plausible_web/views/site_view.ex b/lib/plausible_web/views/site_view.ex index a3ae89f77679..2333a0fac19d 100644 --- a/lib/plausible_web/views/site_view.ex +++ b/lib/plausible_web/views/site_view.ex @@ -10,11 +10,11 @@ defmodule PlausibleWeb.SiteView do Plausible.Sites.shared_link_url(site, link) end - def render_snippet(site) do - tracker = "#{plausible_url()}/js/script.js" - + def render_snippet(site, addons \\ []) do + filename = Enum.join(["script"] ++ addons ++ ["js"], ".") + src = "#{plausible_url()}/js/#{filename}" """ - + """ end diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index e8b67ca97d15..12072dfbc0c2 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -169,24 +169,11 @@ {{/if}} {{#if live_view}} - window.addEventListener('phx:navigate', info => trigger('pageview', {u: info.detail.href})) - - // https://hexdocs.pm/phoenix_live_view/bindings.html - const bindings = ['phx-click', 'phx-click-away', 'phx-change', 'phx-submit', 'phx-feedback-for', 'phx-feedback-group', - 'phx-disable-with', 'phx-trigger-action', 'phx-auto-recover', 'phx-blur', 'phx-focus', 'phx-window-blur', 'phx-window-focus', - 'phx-keydown', 'phx-keyup', 'phx-window-keydown', 'phx-window-keyup', 'phx-key', 'phx-viewport-top', 'phx-viewport-bottom', - 'phx-mounted', 'phx-update', 'phx-remove', 'phx-hook', 'phx-mounted', 'phx-disconnected', 'phx-connected', 'phx-debounce', - 'phx-throttle', 'phx-track-static']; - - const events = ["phx:page-loading-start", - "phx:page-loading-stop", - "track-uploads", - "phx:live-file:updated" - ].concat(bindings) - .concat(bindings.map(name => name.replace('phx-', 'phx:'))) - .concat(bindings.map(name => name.replace('phx-', '')).filter(name => name != 'submit')) - ; - events.map((name) => { + {{#unless manual}} + window.addEventListener('phx:navigate', info => trigger('pageview', {u: info.detail.href})) + {{/unless}} + + ['phx-click', 'phx-change', 'phx-submit', 'phx-viewport-top', 'phx-viewport-bottom', 'phx-mounted', 'phx-connected', 'phx-disconnected'].map((name) => { window.addEventListener(name, info => trigger('phx-event', {props: {event: name, detail: new URLSearchParams(info.detail || {}).toString()}})); }); @@ -196,7 +183,8 @@ //track socket activity if (window.liveSocket) window.liveSocket.socket.logger = (kind, msg, data) => { - if(kind === 'push') trigger('phx-event', {props: {msg, ...data}}) + console.log("FFFFFFFFFFFFF", kind, msg, data); + if(kind === 'push') trigger('phx-push', {props: {msg, ...data}}) } else console && console.error("No liveSocket initialized")