diff --git a/server/database.js b/server/database.js index 52c701fb5..19c09a00f 100644 --- a/server/database.js +++ b/server/database.js @@ -69,7 +69,7 @@ class Database { "patch-ping-packet-size.sql": true, "patch-maintenance-table2.sql": true, "patch-add-gamedig-monitor.sql": true, - "patch-add-google-analytics-status-page-tag.sql": true + "patch-add-google-analytics-status-page-tag.sql": true, }; /** diff --git a/server/model/status_page.js b/server/model/status_page.js index 8dbf1a8c2..2d90b6392 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -4,6 +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"); class StatusPage extends BeanModel { @@ -53,6 +54,12 @@ class StatusPage extends BeanModel { const head = $("head"); + await StatusPage.getStatusPageData(statusPage).then( (page) => { + if (page.config?.googleAnalyticsId) { + head.append($(googleAnalytics.getGoogleAnalyticsScript(page.config.googleAnalyticsId))); + } + }); + // OG Meta Tags head.append(``); head.append(``); @@ -225,7 +232,7 @@ class StatusPage extends BeanModel { customCSS: this.custom_css, footerText: this.footer_text, showPoweredBy: !!this.show_powered_by, - googleAnalyticsId: this.google_analytics_tag_id + googleAnalyticsId: this.google_analytics_tag_id, }; } @@ -246,7 +253,7 @@ class StatusPage extends BeanModel { customCSS: this.custom_css, footerText: this.footer_text, showPoweredBy: !!this.show_powered_by, - googleAnalyticsId: this.google_analytics_tag_id + googleAnalyticsId: this.google_analytics_tag_id, }; } diff --git a/server/modules/google-analytics.js b/server/modules/google-analytics.js new file mode 100644 index 000000000..55820a857 --- /dev/null +++ b/server/modules/google-analytics.js @@ -0,0 +1,11 @@ +let GoogleAnalytics = (() => { + function getGoogleAnalyticsScript(tagId) { + return "" + + ""; + } + return { + getGoogleAnalyticsScript: getGoogleAnalyticsScript + }; +})(); + +module.exports = GoogleAnalytics; diff --git a/src/languages/en.js b/src/languages/en.js new file mode 100644 index 000000000..e69de29bb diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 40a8e7c97..41aa7993d 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -300,15 +300,6 @@ {{ config.customCSS }} - - - - - window.dataLayer = window.dataLayer || []; - function gtag(){dataLayer.push(arguments);} - gtag('js', new Date()); - gtag('config', '{{ config.googleAnalyticsId }}'); -