mirror of
				https://github.com/louislam/uptime-kuma.git
				synced 2025-11-04 13:46:13 +08:00 
			
		
		
		
	Feature - Google Analytics - Use Regex to validate UA as per https://support.google.com/analytics/answer/9310895
This commit is contained in:
		@@ -3,8 +3,13 @@ let GoogleAnalytics = (() => {
 | 
				
			|||||||
        return "<script async src=\"https://www.googletagmanager.com/gtag/js?id=" + tagId + "\"></script>" +
 | 
					        return "<script async src=\"https://www.googletagmanager.com/gtag/js?id=" + tagId + "\"></script>" +
 | 
				
			||||||
            "<script>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date());gtag('config', '" + tagId + "'); </script>";
 | 
					            "<script>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date());gtag('config', '" + tagId + "'); </script>";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    function isValidTag(tagInput) {
 | 
				
			||||||
 | 
					        const re = /^\w{1,2}-\d{8}$/g;
 | 
				
			||||||
 | 
					        return tagInput.match(re) != null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
        getGoogleAnalyticsScript: getGoogleAnalyticsScript
 | 
					        getGoogleAnalyticsScript: getGoogleAnalyticsScript,
 | 
				
			||||||
 | 
					        isValidTag: isValidTag
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ const Database = require("../database");
 | 
				
			|||||||
const apicache = require("../modules/apicache");
 | 
					const apicache = require("../modules/apicache");
 | 
				
			||||||
const StatusPage = require("../model/status_page");
 | 
					const StatusPage = require("../model/status_page");
 | 
				
			||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
 | 
					const { UptimeKumaServer } = require("../uptime-kuma-server");
 | 
				
			||||||
 | 
					const googleAnalytics = require("../modules/google-analytics");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Socket handlers for status page
 | 
					 * Socket handlers for status page
 | 
				
			||||||
@@ -163,7 +164,7 @@ module.exports.statusPageSocketHandler = (socket) => {
 | 
				
			|||||||
            statusPage.custom_css = config.customCSS;
 | 
					            statusPage.custom_css = config.customCSS;
 | 
				
			||||||
            statusPage.show_powered_by = config.showPoweredBy;
 | 
					            statusPage.show_powered_by = config.showPoweredBy;
 | 
				
			||||||
            statusPage.modified_date = R.isoDateTime();
 | 
					            statusPage.modified_date = R.isoDateTime();
 | 
				
			||||||
            statusPage.google_analytics_tag_id = config.googleAnalyticsId;
 | 
					            statusPage.google_analytics_tag_id = googleAnalytics.isValidTag(config.googleAnalyticsId) ? config.googleAnalyticsId : "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await R.store(statusPage);
 | 
					            await R.store(statusPage);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user