Skip to content

Commit

Permalink
fix: untested fixes for IS-11
Browse files Browse the repository at this point in the history
  • Loading branch information
phgrey committed Jul 17, 2024
1 parent d0888a6 commit f2fcf1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/plausible_web/templates/site/snippet.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
) %>
Expand Down
8 changes: 4 additions & 4 deletions lib/plausible_web/views/site_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
"""
<script defer data-domain="#{site.domain}" src="#{tracker}"></script>
<script defer data-domain="#{site.domain}" src="#{src}"></script>
"""
end

Expand Down
26 changes: 7 additions & 19 deletions tracker/src/plausible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}}));
});

Expand All @@ -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")
Expand Down

0 comments on commit f2fcf1c

Please sign in to comment.