Skip to content

Commit

Permalink
fix umami metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Nov 25, 2024
1 parent 4ef9a11 commit 88eeb5c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
9 changes: 2 additions & 7 deletions assets/src/js/app/embed/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ const sha1 = require('sha1');
message.send('init');
const data = await message.receiveOnce('init');
if (window._umami) {
const umami = (await import('../../lib/umami')).init(window, window._umami, {
(await import('../../lib/umami')).init(window, Object.assign(window._umami, {
referrer: data.referer,
});
if (window._tier !== 'free') {
umami.identify({
tier: window._tier,
});
}
}));
}
const c = await check();
if (c) {
Expand Down
8 changes: 5 additions & 3 deletions assets/src/js/app/embed/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import message from './message';
import initAsyncView from '../../lib/asyncView';

// (await import('../../lib/umami')).init(window, window._umami, {
// referrer: window._embedSettings.referer,
// });
if (window._umami) {
(await import('../../lib/umami')).init(window, Object.assign(window._umami, {
tag: 'embed',
}));
}

function setHeight() {
const width = document.body.offsetWidth;
Expand Down
7 changes: 2 additions & 5 deletions assets/src/js/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ function hideProgress() {

if (window._umami) {
const umami = (await import('../lib/umami')).init(window, window._umami);
if (window._tier !== 'free') {
umami.identify({
tier: window._tier,
});
}
window.umami = umami;

}

window.progress = {
Expand Down
5 changes: 5 additions & 0 deletions assets/src/js/app/nav.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import av from '../lib/av';
av(async function() {
if (window.umami && window._tier !== 'free') {
window.umami.identify({
tier: window._tier,
});
}
const self = this;
const themeSelector = (await import('../lib/themeSelector')).themeSelector;
themeSelector(this.querySelector('[data-toggle-theme]'));
Expand Down
6 changes: 3 additions & 3 deletions assets/src/js/lib/umami.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function init(window, config, initProps = {}) {
export function init(window, config) {
const {
screen: { width, height },
navigator: { language },
Expand All @@ -10,8 +10,8 @@ export function init(window, config, initProps = {}) {
const { hostname, href } = location;
let { referrer } = document;

if (initProps.referrer) {
referrer = initProps.referrer;
if (config.referrer) {
referrer = config.referrer;
}

const _data = 'data-';
Expand Down
1 change: 0 additions & 1 deletion templates/layouts/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
{{- if useUmami }}
window._umami = {{ umamiConfig | json }};
{{- end }}
window._tier = "{{ .Claims | tierName }}"
</script>
{{ "layout.js" | asset }}
{{ "baskerville.css" | asset }}
Expand Down
3 changes: 3 additions & 0 deletions templates/partials/nav.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{{ define "nav" }}
<script>
window._tier = "{{ .Claims | tierName }}"
</script>
<div class="navbar sticky top-0">
<div class="flex-1">
<a class="btn btn-sm btn-accent btn-outline" href="/" data-async-target="main">webtor.io</a>
Expand Down
2 changes: 1 addition & 1 deletion templates/views/embed/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<form class="hidden progress-alert progress-alert-block mb-10 closeable bg-black/50" data-async-progress-log="{{ .Job | makeJobLogURL }}">
{{ if .DomainSettings.Ads }}
<div class="font-baskerville text-4xl sm:text-5xl sm:absolute sm:right-0 sm:top-0 p-2 sm:p-4 sm:pt-4 pt-0 z-50 text-center">
<a href="{{ domain }}" target="_blank">
<a href="{{ domain }}" target="_blank" data-umami-event="embed-click-logo">
<span>web</span><span class="text-accent">tor</span>
</a>
</div>
Expand Down

0 comments on commit 88eeb5c

Please sign in to comment.