diff --git a/package-lock.json b/package-lock.json index a9a33ae..6e76dd1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "license": "MPL-2.0", "dependencies": { + "@mozmeao/dnt-helper": "^1.0.0", "bootstrap": "^4.3.1", "chart.js": "^2.8.0", "dayjs": "^1.8.15", @@ -1505,6 +1506,11 @@ "node": ">=4.0.0" } }, + "node_modules/@mozmeao/dnt-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@mozmeao/dnt-helper/-/dnt-helper-1.0.0.tgz", + "integrity": "sha512-Q+fu1VBdG8x/WtJV+5mLXTF5/QJTiHQNWlE4Jf5kqsQw5cEKxjUHLD4qfxcuvwRkbErXyDz1xpWuTglBzIhedw==" + }, "node_modules/@types/q": { "version": "1.5.2", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz", diff --git a/package.json b/package.json index 2e4db7c..8e72fd3 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "homepage": "https://github.com/mozilla/http-observatory-website#readme", "dependencies": { + "@mozmeao/dnt-helper": "^1.0.0", "bootstrap": "^4.3.1", "chart.js": "^2.8.0", "dayjs": "^1.8.15", diff --git a/src/js/ga.js b/src/js/ga.js new file mode 100644 index 0000000..b8cf6f9 --- /dev/null +++ b/src/js/ga.js @@ -0,0 +1,16 @@ +import dntEnabled from "@mozmeao/dnt-helper"; + +if (!dntEnabled()) { + var gaScript = document.createElement("script"); + gaScript.async = 1; + gaScript.src = "https://www.googletagmanager.com/gtag/js?id=G-0YL01S2FDK"; + document.head.appendChild(gaScript); + + window.dataLayer = window.dataLayer || []; + function gtag() { + dataLayer.push(arguments); + } + gtag("js", new Date()); + + gtag("config", "G-0YL01S2FDK"); +} diff --git a/src/js/index.js b/src/js/index.js index 36e32d5..9095593 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -10,6 +10,7 @@ import constants from './constants.js'; import statistics from './statistics.js'; import thirdParty from './third-party/third-party.js'; import utils from './utils.js'; +import './ga.js'; window.$ = $;