analytics/assets/js/app.js

120 lines
4.3 KiB
JavaScript
Raw Normal View History

Adds manual, editable, auto-suggested filters, and negated&globbed path-based filters (#1121) * Adds manual-filters + friends commit 308192044d726e9a6f7406e333048ab3407aa260 Merge: 39287ab a299fab Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 03:40:55 2021 -0500 Merge branch 'manual-filters' into manual-filters-2 commit a299fab1fbe98ec04ea3dfbfbd175a2af5e73804 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 02:20:26 2021 -0500 Changes to split and pattern matched function for time_on_page commit 10f10c933af56a3482747f818bd580a8a1903ae2 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 01:53:18 2021 -0500 Fixes a couple of minor UX issues commit f2e5ce8eb33460cb2d1dc9ac0bd0d4ad0a20aa31 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri Jun 11 01:49:10 2021 -0500 Fixes time on page for globbed and negated page paths commit bb18af6526068860e4090dc91d02455e515f1238 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu Jun 10 05:24:05 2021 -0500 Close to finalized version of updated version Just needs some additional testing + potentially code cleanup commit d0b7bfe3dacb4c611e6857bed308b5954aa2cc1e Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 28 04:21:21 2021 -0500 Real Dialyzer Fix commit 296a76af34ff7e16c83e5b5bf62f0547dc30ece9 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 28 03:44:29 2021 -0500 Dialyzer fix commit 91f3b44017afb3838bbb4de8ec9f3ba4d39709bc Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:11:24 2021 -0500 Changelog commit e041f75745ab57b0d3c00d4a9ff7f8a490b27c17 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:09:52 2021 -0500 Formatting commit f689642204b02f6544dc072b95c9c22e180b9e87 Merge: e00929b 4ff25f6 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:08:47 2021 -0500 Merge branch 'master' into manual-filters commit e00929b1c51411fe4bf939266d3aeb6f67dcb2ab Merge: 83887c4 806975e Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 17:01:48 2021 -0500 Merge branch 'manual-filters' of github.com:Vigasaurus/plausible-analytics into manual-filters commit 83887c49ccc7fbc50ba1766bfa74c77994ef1900 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:59:32 2021 -0500 Adds tests for suggestions, formats goals suggestion query commit 1cb7732a08a50eddb81166fb796bf5731a0c5aba Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:36:31 2021 -0500 Adds goals as auto-complete capable filter commit 4ca39cc406777794bab7586116115031c6d8a82a Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 16:08:22 2021 -0500 95% completed auto-complete setup Still needs: - tests - goals added as filter commit 22d38c4cd83dd1d72ec435e1b8cf6fc3eb70d957 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Thu May 27 03:47:19 2021 -0500 80% of auto-complete filters progress Still needs - countries and screen into new format - re-style dropdown and background - drop debounce time - tests commit 806975ede9ebcbaa03ce888c41f20da866413697 Merge: 81c5e05 1a93542 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 15:28:21 2021 -0500 Merge branch 'master' into manual-filters commit 81c5e05760bf7f5d6fc05290e662ab61f9a4b73b Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 15:21:03 2021 -0500 Makes colorings on top bar elements consistent commit fa7f6c22680f5f00b89c7ea99032b409a5f8bbd2 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Tue May 25 14:58:25 2021 -0500 Makes requested changes, adds different version of filter button commit 7dc65b9b7a5a9678499a7c404109e710ae7da36d Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 04:29:01 2021 -0500 Changelog commit c684f1c76a2599324c19ca32de10b2f2849fd5e9 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 04:26:14 2021 -0500 Various UI Improvements - Makes edit buttons full-length & properly sized - Adds remove filter button in edit menu commit a632e7a8eea4a9897052cb08d3f7605403c227f7 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 03:11:50 2021 -0500 Adds tests for exclusions and wildcards commit eb91a7942b662d412511a4c47501a9b6d7f2d625 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Sat May 22 03:02:23 2021 -0500 Fixes editing UX on list view commit 6209d72aeede6aa8ce4f8e009d2ea168bb8f77a7 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 04:01:17 2021 -0500 Bugfix in realtime view, formatting commit 007d44df38dba254154b3450aacec9dd253ccd95 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 03:23:16 2021 -0500 Second pass - mostly everything user-facing is done Still needs: - Tests - Potentially negating other filters - Potentially some code cleanup commit cb7b5b9fbd83f618cf4ebbe6582a9202b4989033 Author: Vignesh Joglekar <rexvigasaurus@gmail.com> Date: Fri May 21 01:49:52 2021 -0500 First pass on manual filter & path regex/negated filters Still needs: - Form structure on filter modal - Edit filter button - Filter dropdown UI improvement - Filter modal mount data collection - Tests - Potentially negating other filters * Fixes an issue between the updated React version and Flatpickr not showing up Reverting to v16 was the simplest fix without diving into the issue upstream with Flatpickr * Resolves comments on UI and code style Co-authored-by: Uku Taht <Uku.taht@gmail.com>
2021-06-21 14:42:16 +03:00
import "../css/app.css"
import "flatpickr/dist/flatpickr.min.css"
2019-09-02 14:29:19 +03:00
import "./polyfills/closest"
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
2019-09-02 14:29:19 +03:00
import "phoenix_html"
2020-11-16 16:38:44 +03:00
import 'alpinejs'
2019-09-02 14:29:19 +03:00
const triggers = document.querySelectorAll('[data-dropdown-trigger]')
for (const trigger of triggers) {
trigger.addEventListener('click', function(e) {
e.stopPropagation()
e.currentTarget.nextElementSibling.classList.remove('hidden')
})
}
if (triggers.length > 0) {
document.addEventListener('click', function(e) {
const dropdown = e.target.closest('[data-dropdown]')
if (dropdown && e.target.tagName === 'A') {
dropdown.classList.add('hidden')
}
})
2019-09-02 14:29:19 +03:00
document.addEventListener('click', function(e) {
const clickedInDropdown = e.target.closest('[data-dropdown]')
if (!clickedInDropdown) {
for (const dropdown of document.querySelectorAll('[data-dropdown]')) {
dropdown.classList.add('hidden')
}
}
})
}
2019-10-31 08:39:51 +03:00
const registerForm = document.getElementById('register-form')
if (registerForm) {
registerForm.addEventListener('submit', function(e) {
e.preventDefault();
setTimeout(submitForm, 1000);
var formSubmitted = false;
function submitForm() {
if (!formSubmitted) {
formSubmitted = true;
registerForm.submit();
}
}
2020-02-05 17:08:34 +03:00
plausible('Signup', {callback: submitForm});
2019-10-31 08:39:51 +03:00
})
}
const changelogNotification = document.getElementById('changelog-notification')
if (changelogNotification) {
showChangelogNotification(changelogNotification)
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) {
const lastUpdated = Number(localStorage.lastChangelogUpdate)
const lastChecked = Number(localStorage.lastChangelogClick)
2021-01-26 11:32:03 +03:00
const hasNewUpdateSinceLastClicked = lastUpdated > lastChecked
const notOlderThanThreeDays = Date.now() - lastUpdated < 1000 * 60 * 60 * 72
if ((!lastChecked || hasNewUpdateSinceLastClicked) && notOlderThanThreeDays) {
el.innerHTML = `
<a href="https://plausible.io/changelog" target="_blank">
<svg class="w-5 h-5 text-gray-600 dark:text-gray-100" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
2021-01-26 11:32:03 +03:00
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v13m0-13V6a2 2 0 112 2h-2zm0 0V5.5A2.5 2.5 0 109.5 8H12zm-7 4h14M5 12a2 2 0 110-4h14a2 2 0 110 4M5 12v7a2 2 0 002 2h10a2 2 0 002-2v-7"></path>
</svg>
<svg class="w-4 h-4 text-pink-500 absolute" style="left: 14px; top: 2px;" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<circle cx="8" cy="8" r="4" fill="currentColor" />
</svg>
</a>
`
const link = el.getElementsByTagName('a')[0]
link.addEventListener('click', function() {
localStorage.lastChangelogClick = Date.now()
setTimeout(() => { link.remove() }, 100)
})
}
}
const embedButton = document.getElementById('generate-embed')
if (embedButton) {
embedButton.addEventListener('click', function(e) {
const baseUrl = document.getElementById('base-url').value
const embedCode = document.getElementById('embed-code')
const theme = document.getElementById('theme').value.toLowerCase()
const background = document.getElementById('background').value
try {
const embedLink = new URL(document.getElementById('embed-link').value)
embedLink.searchParams.set('embed', 'true')
embedLink.searchParams.set('theme', theme)
if (background) {
embedLink.searchParams.set('background', background)
}
2021-03-16 16:06:58 +03:00
embedCode.value = `<iframe plausible-embed src="${embedLink.toString()}" scrolling="no" frameborder="0" loading="lazy" style="width: 1px; min-width: 100%; height: 1600px;"></iframe>
<div style="font-size: 14px; padding-bottom: 14px;">Stats powered by <a target="_blank" style="color: #4F46E5; text-decoration: underline;" href="https://plausible.io">Plausible Analytics</a></div>
<script async src="${baseUrl}/js/embed.host.js"></script>`
} catch (e) {
2021-03-16 16:06:58 +03:00
console.error(e)
embedCode.value = 'ERROR: Please enter a valid URL in the shared link field'
}
})
}