Skip to content

Commit

Permalink
Merge pull request from GHSA-v4v2-8h88-65qj
Browse files Browse the repository at this point in the history
  • Loading branch information
louislam authored Nov 24, 2023
1 parent 121d1a1 commit f28dccf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
14 changes: 10 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"express-static-gzip": "~2.1.7",
"form-data": "~4.0.0",
"gamedig": "~4.1.0",
"html-escaper": "^3.0.3",
"http-graceful-shutdown": "~3.1.7",
"http-proxy-agent": "~5.0.0",
"https-proxy-agent": "~5.0.1",
Expand Down
14 changes: 9 additions & 5 deletions server/google-analytics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const jsesc = require("jsesc");
const { escape } = require("html-escaper");

/**
* Returns a string that represents the javascript that is required to insert the Google Analytics scripts
Expand All @@ -7,15 +8,18 @@ const jsesc = require("jsesc");
* @returns {string}
*/
function getGoogleAnalyticsScript(tagId) {
let escapedTagId = jsesc(tagId, { isScriptContext: true });
let escapedTagIdJS = jsesc(tagId, { isScriptContext: true });

if (escapedTagId) {
escapedTagId = escapedTagId.trim();
if (escapedTagIdJS) {
escapedTagIdJS = escapedTagIdJS.trim();
}

// Escape the tag ID for use in an HTML attribute.
let escapedTagIdHTMLAttribute = escape(tagId);

return `
<script async src="https://www.googletagmanager.com/gtag/js?id=${escapedTagId}"></script>
<script>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date());gtag('config', '${escapedTagId}'); </script>
<script async src="https://www.googletagmanager.com/gtag/js?id=${escapedTagIdHTMLAttribute}"></script>
<script>window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date());gtag('config', '${escapedTagIdJS}'); </script>
`;
}

Expand Down

0 comments on commit f28dccf

Please sign in to comment.