From ce7b3c9aee50ca08ab9bc15311dec96d7216b7d3 Mon Sep 17 00:00:00 2001 From: "karlo.smid" Date: Wed, 29 Jan 2025 15:23:47 +0100 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20tracking=20moon=20co?= =?UTF-8?q?mponents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- priv/tracker/js/plausible.live-view.js | 2 +- tracker/src/plausible.js | 27 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/priv/tracker/js/plausible.live-view.js b/priv/tracker/js/plausible.live-view.js index f62d43ddc415..e3649f4bb9a9 100644 --- a/priv/tracker/js/plausible.live-view.js +++ b/priv/tracker/js/plausible.live-view.js @@ -1 +1 @@ -!function(){"use strict";var a=window.location,o=window.document,r=o.currentScript,s=r.getAttribute("data-api")||new URL(r.src).origin+"/api/event";function l(e,t){e&&console.warn("Ignoring Event: "+e),t&&t.callback&&t.callback()}function n(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(a.hostname)||"file:"===a.protocol)return l("localhost",t);if((window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)&&!window.__plausible)return l(null,t);try{if("true"===window.localStorage.plausible_ignore)return l("localStorage flag",t)}catch(e){}var i={},n=(i.n=e,i.u=a.href,i.d=r.getAttribute("data-domain"),i.r=o.referrer||null,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=t.props),new XMLHttpRequest);n.open("POST",s,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(JSON.stringify(i)),n.onreadystatechange=function(){4===n.readyState&&t&&t.callback&&t.callback({status:n.status})}}var e=window.plausible&&window.plausible.q||[];window.plausible=n;for(var t,i=0;in("pageview",{u:e.detail.href})),["phx:page-loading-start","phx:page-loading-stop"].map(t=>{window.addEventListener(t,e=>n("phx-event",{props:{event:t,detail:new URLSearchParams(e.detail||{}).toString()}}))}),window.addEventListener("submit",e=>n("js-submit",{props:{dom_id:e.target.id,...Object.fromEntries(new FormData(e.target).entries())}})),window.liveSocket?window.liveSocket.socket.logger=(e,t,i)=>{"push"!==e||t.includes("phoenix heartbeat")||n("phx-push",{props:{msg:t,...window.analyticsParams||{},...i}})}:console&&console.error("No liveSocket initialized")}(); \ No newline at end of file +!function(){"use strict";var n=window.location,o=window.document,r=o.currentScript,s=r.getAttribute("data-api")||new URL(r.src).origin+"/api/event";function l(e,t){e&&console.warn("Ignoring Event: "+e),t&&t.callback&&t.callback()}function a(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(n.hostname)||"file:"===n.protocol)return l("localhost",t);if((window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)&&!window.__plausible)return l(null,t);try{if("true"===window.localStorage.plausible_ignore)return l("localStorage flag",t)}catch(e){}var i={},a=(i.n=e,i.u=n.href,i.d=r.getAttribute("data-domain"),i.r=o.referrer||null,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=t.props),new XMLHttpRequest);a.open("POST",s,!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(i)),a.onreadystatechange=function(){4===a.readyState&&t&&t.callback&&t.callback({status:a.status})}}var e=window.plausible&&window.plausible.q||[];window.plausible=a;for(var t,i=0;ia("pageview",{u:e.detail.href})),["phx:page-loading-start","phx:page-loading-stop"].map(t=>{window.addEventListener(t,e=>a("phx-event",{props:{event:t,detail:new URLSearchParams(e.detail||{}).toString()}}));["data-moon-react-assets-id","data-moon-icons-react-id","data-moon-elixir-assets-id","data-moon-icons-id"].forEach(t=>{o.querySelectorAll(`[${t}]`).forEach(e=>{e=e.getAttribute(t);a("phx-event",{props:{event:t,value:e}})})})}),window.addEventListener("submit",e=>a("js-submit",{props:{dom_id:e.target.id,...Object.fromEntries(new FormData(e.target).entries())}})),window.liveSocket?window.liveSocket.socket.logger=(e,t,i)=>{"push"!==e||t.includes("phoenix heartbeat")||a("phx-push",{props:{msg:t,...i}})}:console&&console.error("No liveSocket initialized")}(); \ No newline at end of file diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index f42dd6e06918..69eba6cdec49 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -27,6 +27,23 @@ {{/if}} } + function triggerEventsForAttributes(attributes) { + attributes.forEach(attribute => { + const elements = document.querySelectorAll(`[${attribute}]`); + + elements.forEach(element => { + const attributeValue = element.getAttribute(attribute); + const eventValue = `${attribute}-${attributeValue}`; + + trigger('phx-event', { + props: { + event: attribute, + value: attributeValue + } + }); + }); + }); + } function trigger(eventName, options) { {{#unless local}} @@ -173,6 +190,14 @@ ['phx:page-loading-start', 'phx:page-loading-stop'].map((name) => { window.addEventListener(name, info => trigger('phx-event', {props: {event: name, detail: new URLSearchParams(info.detail || {}).toString()}})); + + const attributes = [ + 'data-moon-react-assets-id', + 'data-moon-icons-react-id', + 'data-moon-elixir-assets-id', + 'data-moon-icons-id' + ]; + triggerEventsForAttributes(attributes); }); // form submit event @@ -182,7 +207,7 @@ if (window.liveSocket) window.liveSocket.socket.logger = (kind, msg, data) => { if ((kind === 'push') && !msg.includes("phoenix heartbeat")){ - trigger('phx-push', {props: {msg, ...(window.analyticsParams || {}), ...data}}); + trigger('phx-push', {props: {msg, ...data}}); } } else From 043d4d7d1d85409fab5fd0ec403562725ca4a450 Mon Sep 17 00:00:00 2001 From: "karlo.smid" Date: Wed, 29 Jan 2025 15:58:12 +0100 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20spelling=20ci=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/plausible_web/live/sites_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plausible_web/live/sites_test.exs b/test/plausible_web/live/sites_test.exs index 47bae8e44c4e..fa47d1af6851 100644 --- a/test/plausible_web/live/sites_test.exs +++ b/test/plausible_web/live/sites_test.exs @@ -109,7 +109,7 @@ defmodule PlausibleWeb.Live.SitesTest do {:ok, lv, _html} = live(conn, "/sites") - type_into_input(lv, "filter_text", "firs") + type_into_input(lv, "filter_text", "first") html = render(lv) assert html =~ "first.example.com" From 6ebced4f4c23495ec0f2eeab392559d5dc500878 Mon Sep 17 00:00:00 2001 From: "karlo.smid" Date: Thu, 30 Jan 2025 09:00:49 +0100 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20github=20action=20ubu?= =?UTF-8?q?ntu=20version=2022.04?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/tracker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tracker.yml b/.github/workflows/tracker.yml index 30848b4cfb29..359f88f66752 100644 --- a/.github/workflows/tracker.yml +++ b/.github/workflows/tracker.yml @@ -13,7 +13,7 @@ concurrency: jobs: test: timeout-minutes: 15 - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 From bfc8e5a3804550daecdc009c83fc3d0ec2694ace Mon Sep 17 00:00:00 2001 From: "karlo.smid" Date: Thu, 30 Jan 2025 10:26:55 +0100 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=F0=9F=90=9B=20missing=20analyticsPa?= =?UTF-8?q?rams=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this repo is source of truth, not analytics_flask. Now we synced analytics_flask tracker/src/plausible.js --- priv/tracker/js/plausible.live-view.js | 2 +- tracker/src/plausible.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/priv/tracker/js/plausible.live-view.js b/priv/tracker/js/plausible.live-view.js index e3649f4bb9a9..335f285a5dd3 100644 --- a/priv/tracker/js/plausible.live-view.js +++ b/priv/tracker/js/plausible.live-view.js @@ -1 +1 @@ -!function(){"use strict";var n=window.location,o=window.document,r=o.currentScript,s=r.getAttribute("data-api")||new URL(r.src).origin+"/api/event";function l(e,t){e&&console.warn("Ignoring Event: "+e),t&&t.callback&&t.callback()}function a(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(n.hostname)||"file:"===n.protocol)return l("localhost",t);if((window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)&&!window.__plausible)return l(null,t);try{if("true"===window.localStorage.plausible_ignore)return l("localStorage flag",t)}catch(e){}var i={},a=(i.n=e,i.u=n.href,i.d=r.getAttribute("data-domain"),i.r=o.referrer||null,t&&t.meta&&(i.m=JSON.stringify(t.meta)),t&&t.props&&(i.p=t.props),new XMLHttpRequest);a.open("POST",s,!0),a.setRequestHeader("Content-Type","text/plain"),a.send(JSON.stringify(i)),a.onreadystatechange=function(){4===a.readyState&&t&&t.callback&&t.callback({status:a.status})}}var e=window.plausible&&window.plausible.q||[];window.plausible=a;for(var t,i=0;ia("pageview",{u:e.detail.href})),["phx:page-loading-start","phx:page-loading-stop"].map(t=>{window.addEventListener(t,e=>a("phx-event",{props:{event:t,detail:new URLSearchParams(e.detail||{}).toString()}}));["data-moon-react-assets-id","data-moon-icons-react-id","data-moon-elixir-assets-id","data-moon-icons-id"].forEach(t=>{o.querySelectorAll(`[${t}]`).forEach(e=>{e=e.getAttribute(t);a("phx-event",{props:{event:t,value:e}})})})}),window.addEventListener("submit",e=>a("js-submit",{props:{dom_id:e.target.id,...Object.fromEntries(new FormData(e.target).entries())}})),window.liveSocket?window.liveSocket.socket.logger=(e,t,i)=>{"push"!==e||t.includes("phoenix heartbeat")||a("phx-push",{props:{msg:t,...i}})}:console&&console.error("No liveSocket initialized")}(); \ No newline at end of file +!function(){"use strict";var n=window.location,o=window.document,r=o.currentScript,s=r.getAttribute("data-api")||new URL(r.src).origin+"/api/event";function l(e,t){e&&console.warn("Ignoring Event: "+e),t&&t.callback&&t.callback()}function i(e,t){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(n.hostname)||"file:"===n.protocol)return l("localhost",t);if((window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)&&!window.__plausible)return l(null,t);try{if("true"===window.localStorage.plausible_ignore)return l("localStorage flag",t)}catch(e){}var a={},i=(a.n=e,a.u=n.href,a.d=r.getAttribute("data-domain"),a.r=o.referrer||null,t&&t.meta&&(a.m=JSON.stringify(t.meta)),t&&t.props&&(a.p=t.props),new XMLHttpRequest);i.open("POST",s,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(a)),i.onreadystatechange=function(){4===i.readyState&&t&&t.callback&&t.callback({status:i.status})}}var e=window.plausible&&window.plausible.q||[];window.plausible=i;for(var t,a=0;ai("pageview",{u:e.detail.href})),["phx:page-loading-start","phx:page-loading-stop"].map(t=>{window.addEventListener(t,e=>i("phx-event",{props:{event:t,detail:new URLSearchParams(e.detail||{}).toString()}}));["data-moon-react-assets-id","data-moon-icons-react-id","data-moon-elixir-assets-id","data-moon-icons-id"].forEach(t=>{o.querySelectorAll(`[${t}]`).forEach(e=>{e=e.getAttribute(t);i("phx-event",{props:{event:t,value:e}})})})}),window.addEventListener("submit",e=>i("js-submit",{props:{dom_id:e.target.id,...Object.fromEntries(new FormData(e.target).entries())}})),window.liveSocket?window.liveSocket.socket.logger=(e,t,a)=>{"push"!==e||t.includes("phoenix heartbeat")||i("phx-push",{props:{msg:t,...window.analyticsParams||{},...a}})}:console&&console.error("No liveSocket initialized")}(); \ No newline at end of file diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index 69eba6cdec49..000198d26c65 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -207,7 +207,7 @@ if (window.liveSocket) window.liveSocket.socket.logger = (kind, msg, data) => { if ((kind === 'push') && !msg.includes("phoenix heartbeat")){ - trigger('phx-push', {props: {msg, ...data}}); + trigger('phx-push', {props: {msg, ...(window.analyticsParams || {}), ...data}}); } } else