mirror of
https://github.com/koichixD/uptime-kuma.git
synced 2026-09-04 09:13:21 +00:00
fix(analytics): fixed issues with db init and refactor of code and names
This commit is contained in:
@@ -14,11 +14,11 @@ function getAnalyticsScript(statusPage) {
|
||||
case "google":
|
||||
return googleAnalytics.getGoogleAnalyticsScript(statusPage.analyticsId);
|
||||
case "umami":
|
||||
return umamiAnalytics.getUmamiAnalyticsScript(statusPage.analyticsDomainUrl, statusPage.analyticsId);
|
||||
return umamiAnalytics.getUmamiAnalyticsScript(statusPage.analyticsScriptUrl, statusPage.analyticsId);
|
||||
case "plausible":
|
||||
return plausibleAnalytics.getPlausibleAnalyticsScript(statusPage.analyticsDomainUrl, statusPage.analyticsId);
|
||||
return plausibleAnalytics.getPlausibleAnalyticsScript(statusPage.analyticsScriptUrl, statusPage.analyticsId);
|
||||
case "matomo":
|
||||
return matomoAnalytics.getMatomoAnalyticsScript(statusPage.analyticsDomainUrl, statusPage.analyticsId);
|
||||
return matomoAnalytics.getMatomoAnalyticsScript(statusPage.analyticsScriptUrl, statusPage.analyticsId);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ function isValidAnalyticsConfig(statusPage) {
|
||||
case "umami":
|
||||
case "plausible":
|
||||
case "matomo":
|
||||
return statusPage.analyticsId != null && statusPage.analyticsDomainUrl != null;
|
||||
return statusPage.analyticsId != null && statusPage.analyticsScriptUrl != null;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,16 +4,16 @@ const { escape } = require("html-escaper");
|
||||
/**
|
||||
* Returns a string that represents the javascript that is required to insert the Plausible Analytics script
|
||||
* into a webpage.
|
||||
* @param {string} plausibleDomainUrl Domain name with tld to use with the Plausible Analytics script.
|
||||
* @param {string} scriptUrl the Plausible Analytics script url.
|
||||
* @param {string} domainsToMonitor Domains to track seperated by a ',' to add Plausible Analytics script.
|
||||
* @returns {string} HTML script tags to inject into page
|
||||
*/
|
||||
function getPlausibleAnalyticsScript(plausibleDomainUrl, domainsToMonitor) {
|
||||
let escapedDomainUrlJS = jsesc(plausibleDomainUrl, { isScriptContext: true });
|
||||
function getPlausibleAnalyticsScript(scriptUrl, domainsToMonitor) {
|
||||
let escapedScriptUrlJS = jsesc(scriptUrl, { isScriptContext: true });
|
||||
let escapedWebsiteIdJS = jsesc(domainsToMonitor, { isScriptContext: true });
|
||||
|
||||
if (escapedDomainUrlJS) {
|
||||
escapedDomainUrlJS = escapedDomainUrlJS.trim();
|
||||
if (escapedScriptUrlJS) {
|
||||
escapedScriptUrlJS = escapedScriptUrlJS.trim();
|
||||
}
|
||||
|
||||
if (escapedWebsiteIdJS) {
|
||||
@@ -21,13 +21,13 @@ function getPlausibleAnalyticsScript(plausibleDomainUrl, domainsToMonitor) {
|
||||
}
|
||||
|
||||
// Escape the domain url for use in an HTML attribute.
|
||||
let escapedDomainUrlHTMLAttribute = escape(escapedDomainUrlJS);
|
||||
let escapedScriptUrlHTMLAttribute = escape(escapedScriptUrlJS);
|
||||
|
||||
// Escape the website id for use in an HTML attribute.
|
||||
let escapedWebsiteIdHTMLAttribute = escape(escapedWebsiteIdJS);
|
||||
|
||||
return `
|
||||
<script defer src="https://${escapedDomainUrlHTMLAttribute}/js/script.js" data-domain="${escapedWebsiteIdHTMLAttribute}"></script>
|
||||
<script defer src="${escapedScriptUrlHTMLAttribute}" data-domain="${escapedWebsiteIdHTMLAttribute}"></script>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,30 +4,30 @@ 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} scriptUrl the Umami Analytics script url.
|
||||
* @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 });
|
||||
function getUmamiAnalyticsScript(scriptUrl, websiteId) {
|
||||
let escapedScriptUrlJS = jsesc(scriptUrl, { isScriptContext: true });
|
||||
let escapedWebsiteIdJS = jsesc(websiteId, { isScriptContext: true });
|
||||
|
||||
if (escapedDomainUrlJS) {
|
||||
escapedDomainUrlJS = escapedDomainUrlJS.trim();
|
||||
if (escapedScriptUrlJS) {
|
||||
escapedScriptUrlJS = escapedScriptUrlJS.trim();
|
||||
}
|
||||
|
||||
if (escapedWebsiteIdJS) {
|
||||
escapedWebsiteIdJS = escapedWebsiteIdJS.trim();
|
||||
}
|
||||
|
||||
// Escape the domain url for use in an HTML attribute.
|
||||
let escapedDomainUrlHTMLAttribute = escape(escapedDomainUrlJS);
|
||||
// Escape the Script url for use in an HTML attribute.
|
||||
let escapedScriptUrlHTMLAttribute = escape(escapedScriptUrlJS);
|
||||
|
||||
// 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>
|
||||
<script defer src="${escapedScriptUrlHTMLAttribute}" data-website-id="${escapedWebsiteIdHTMLAttribute}"></script>
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user