-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for umami analytics in status page #5608
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,6 +203,8 @@ async function createTables() { | |
table.text("custom_css"); | ||
table.boolean("show_powered_by").notNullable().defaultTo(true); | ||
table.string("google_analytics_tag_id"); | ||
table.string("umami_analytics_domain_url"); | ||
table.string("umami_analytics_website_id"); | ||
Comment on lines
+206
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding DB-Design as discussed below: |
||
}); | ||
|
||
// maintenance_status_page | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. | ||
BEGIN TRANSACTION; | ||
|
||
ALTER TABLE status_page | ||
ADD umami_analytics_domain_url VARCHAR; | ||
|
||
ALTER TABLE status_page | ||
ADD umami_analytics_website_id VARCHAR; | ||
|
||
COMMIT; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const jsesc = require("jsesc"); | ||
const { escape } = require("html-escaper"); | ||
|
||
/** | ||
* Returns a string that represents the javascript that is required to insert the Umami Analytics script | ||
* into a webpage. | ||
* @param {string} domainUrl Domain name with tld to use with the Umami Analytics script. | ||
* @param {string} websiteId Website ID to use with the Umami Analytics script. | ||
* @returns {string} HTML script tags to inject into page | ||
*/ | ||
function getUmamiAnalyticsScript(domainUrl, websiteId) { | ||
let escapedDomainUrlJS = jsesc(domainUrl, { isScriptContext: true }); | ||
let escapedWebsiteIdJS = jsesc(websiteId, { isScriptContext: true }); | ||
|
||
if (escapedDomainUrlJS) { | ||
escapedDomainUrlJS = escapedDomainUrlJS.trim(); | ||
} | ||
|
||
if (escapedWebsiteIdJS) { | ||
escapedWebsiteIdJS = escapedWebsiteIdJS.trim(); | ||
} | ||
|
||
// Escape the domain url for use in an HTML attribute. | ||
let escapedDomainUrlHTMLAttribute = escape(escapedDomainUrlJS); | ||
|
||
// Escape the website id for use in an HTML attribute. | ||
let escapedWebsiteIdHTMLAttribute = escape(escapedWebsiteIdJS); | ||
|
||
return ` | ||
<script defer src="https://${escapedDomainUrlHTMLAttribute}/script.js" data-website-id="${escapedWebsiteIdHTMLAttribute}"></script> | ||
`; | ||
} | ||
|
||
module.exports = { | ||
getUmamiAnalyticsScript, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,16 @@ | |
<input id="googleAnalyticsTag" v-model="config.googleAnalyticsId" type="text" class="form-control" data-testid="google-analytics-input"> | ||
</div> | ||
|
||
<!-- Umami Analytics --> | ||
<div class="my-3"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems like a bit too much clutter to me. 🤔 => lets hide them via an analytics selector (None, GA, Umami) where the GA settings are only present when that is selected. |
||
<label for="umamiAnalyticsDomainUrl" class="form-label">{{ $t("Umami Analytics Domain Url") }}</label> | ||
<input id="umamiAnalyticsDomainUrl" v-model="config.umamiAnalyticsDomainUrl" type="text" class="form-control" data-testid="umami-analytics-domain-url-input"> | ||
</div> | ||
<div class="my-3"> | ||
<label for="umamiAnalyticsWebsite" class="form-label">{{ $t("Umami Analytics Website ID") }}</label> | ||
<input id="umamiAnalyticsWebsite" v-model="config.umamiAnalyticsWebsiteId" type="text" class="form-control" data-testid="umami-analytics-website-id-input"> | ||
</div> | ||
|
||
<!-- Custom CSS --> | ||
<div class="my-3"> | ||
<div class="mb-1">{{ $t("Custom CSS") }}</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this and the related parts and add it to a new migration, and only there (the
.sql
files are a crutch which we did not have the time/energy to clean up yet)I think this file will only be run for new users, but not existing users.