diff --git a/server/google-analytics.js b/server/google-analytics.js new file mode 100644 index 00000000..b98ca862 --- /dev/null +++ b/server/google-analytics.js @@ -0,0 +1,19 @@ +const jsesc = require("jsesc"); + +/** + * Returns a string that represents the javascript that is required to insert the Google Analytics scripts + * into a webpage. + * @param tagId Google UA/G/AW/DC Property ID to use with the Google Analytics script. + * @returns {string} + */ +function getGoogleAnalyticsScript(tagId) { + let escapedTagId = jsesc(tagId, { isScriptContext: true }); + return ` + + + `; +} + +module.exports = { + getGoogleAnalyticsScript, +}; diff --git a/server/model/status_page.js b/server/model/status_page.js index 5b1c1240..d7185a2e 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -4,7 +4,7 @@ const cheerio = require("cheerio"); const { UptimeKumaServer } = require("../uptime-kuma-server"); const jsesc = require("jsesc"); const Maintenance = require("./maintenance"); -const googleAnalytics = require("../modules/google-analytics"); +const googleAnalytics = require("../google-analytics"); class StatusPage extends BeanModel { @@ -55,9 +55,7 @@ class StatusPage extends BeanModel { const head = $("head"); if (statusPage.googleAnalyticsTagId) { - let escapedGoogleAnalyticsScript = jsesc(googleAnalytics.getGoogleAnalyticsScript(statusPage.googleAnalyticsTagId), { - "isScriptContext": true - }); + let escapedGoogleAnalyticsScript = googleAnalytics.getGoogleAnalyticsScript(statusPage.googleAnalyticsTagId); head.append($(escapedGoogleAnalyticsScript)); } diff --git a/server/modules/google-analytics.js b/server/modules/google-analytics.js deleted file mode 100644 index 8b909b42..00000000 --- a/server/modules/google-analytics.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Returns a string that represents the javascript that is required to insert the Google Analytics scripts - * into a webpage. - * @param tagId Google UA/G/AW/DC Property ID to use with the Google Analytics script. - * @returns {string} - */ -function getGoogleAnalyticsScript(tagId) { - return "" + - ""; -} - -module.exports = { - getGoogleAnalyticsScript, -};