mirror of
https://github.com/koichixD/uptime-kuma.git
synced 2026-09-04 17:23:21 +00:00
fix(analytics): fixed issues with db init and refactor of code and names
This commit is contained in:
@@ -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