Load gtm only if anonymous_statistics are enabled (#5651)
* Load gtm only if anonymous_statistics are enabled * load gtm.js synchronously
Chris Akritidis committed
Mar 18, 2019 at 12:26 UTC
c3eb734c731c74fe4fb15fbe95ec76b99f48d1b6
3 files changed
+22
-13
web/gui/dashboard.js
+11
-3
@@ -9698,7 +9698,7 @@ NETDATA.registry = {
9698
machines: null, // the user's other URLs
9699
machines_array: null, // the user's other URLs in an array
9700
person_urls: null,
9701
-
9701
+ anonymous_statistics_checked: false,
9702
MASKED_DATA: "***",
9703
9704
isUsingGlobalRegistry: function() {
@@ -9771,8 +9771,16 @@ NETDATA.registry = {
9771
}
9772
NETDATA.registry.machine_guid = data.machine_guid;
9773
NETDATA.registry.hostname = data.hostname;
9774
- if (dataLayer) {
9775
- if (data.anonymous_statistics) dataLayer.push({"anonymous_statistics" : "true", "machine_guid" : data.machine_guid});
9774
+ if (!NETDATA.registry.anonymous_statistics_checked) {
9775
+ NETDATA.registry.anonymous_statistics_checked=true;
9776
+ if (data.anonymous_statistics) {
9777
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
9778
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
9779
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=false;j.src=
9780
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
9781
+ })(window,document,'script','dataLayer','GTM-N6CBMJD');
9782
+ dataLayer.push({"anonymous_statistics" : "true", "machine_guid" : data.machine_guid});
9783
+ }
9784
}
9785
NETDATA.registry.access(2, function (person_urls) {
9786
NETDATA.registry.parsePersonUrls(person_urls);
web/gui/index.html
-7
@@ -2,13 +2,6 @@
2
<!-- SPDX-License-Identifier: GPL-3.0-or-later -->
3
<html lang="en">
4
<head>
5
- <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
6
- new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
7
- j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
8
- 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
9
- })(window,document,'script','dataLayer','GTM-N6CBMJD');
10
- dataLayer.push({"anonymous_statistics" : "false"});
11
- </script>
5
<title>netdata dashboard</title>
6
<meta name="application-name" content="netdata">
7
web/gui/src/dashboard.js/registry.js
+11
-3
@@ -11,7 +11,7 @@ NETDATA.registry = {
11
machines: null, // the user's other URLs
12
machines_array: null, // the user's other URLs in an array
13
person_urls: null,
14
-
14
+ anonymous_statistics_checked: false,
15
MASKED_DATA: "***",
16
17
isUsingGlobalRegistry: function() {
@@ -84,8 +84,16 @@ NETDATA.registry = {
84
}
85
NETDATA.registry.machine_guid = data.machine_guid;
86
NETDATA.registry.hostname = data.hostname;
87
- if (dataLayer) {
88
- if (data.anonymous_statistics) dataLayer.push({"anonymous_statistics" : "true", "machine_guid" : data.machine_guid});
87
+ if (!NETDATA.registry.anonymous_statistics_checked) {
88
+ NETDATA.registry.anonymous_statistics_checked=true;
89
+ if (data.anonymous_statistics) {
90
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
91
+ new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
92
+ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=false;j.src=
93
+ 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
94
+ })(window,document,'script','dataLayer','GTM-N6CBMJD');
95
+ dataLayer.push({"anonymous_statistics" : "true", "machine_guid" : data.machine_guid});
96
+ }
97
}
98
NETDATA.registry.access(2, function (person_urls) {
99
NETDATA.registry.parsePersonUrls(person_urls);