Skip to content

Commit

Permalink
Merge pull request #16 from coingaming/feat/is-131
Browse files Browse the repository at this point in the history
feat: 🎸 tracking moon components
  • Loading branch information
karlosmid authored Jan 30, 2025
2 parents 21a07e6 + bfc8e5a commit 90c1139
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tracker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion priv/tracker/js/plausible.live-view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/plausible_web/live/sites_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions tracker/src/plausible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 90c1139

Please sign in to comment.