Skip to content

Commit 4c9f38a

Browse files
authored
Fix Web GUI breaking with ad blockers (#560)
1 parent 959f63f commit 4c9f38a

9 files changed

Lines changed: 36 additions & 30 deletions

File tree

plugins/cpp/webgui/js/cppMenu.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ function (topic, Menu, MenuItem, PopupMenuItem, astHelper, model, urlHandler, vi
6767
elementInfo : nodeInfo
6868
});
6969

70-
if (gtag) {
71-
gtag ('event', 'documentation', {
70+
if (window.gtag) {
71+
window.gtag ('event', 'documentation', {
7272
'event_category' : urlHandler.getState('wsid'),
7373
'event_label' : urlHandler.getFileInfo().name
7474
+ ': '

plugins/cpp_reparse/webgui/js/cppReparseFileAST.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ function (on, topic, declare, Color, Deferred, dom, ContentPane, Tooltip,
6161
}
6262
);
6363

64-
if (gtag) {
65-
gtag ('event', 'cpp_reparse_file', {
64+
if (window.gtag) {
65+
window.gtag ('event', 'cpp_reparse_file', {
6666
'event_category' : urlHandler.getState('wsid'),
6767
'event_label' : urlHandler.getFileInfo().name
6868
});
@@ -80,8 +80,8 @@ function (on, topic, declare, Color, Deferred, dom, ContentPane, Tooltip,
8080
}
8181
);
8282

83-
if (gtag) {
84-
gtag ('event', 'cpp_reparse_node', {
83+
if (window.gtag) {
84+
window.gtag ('event', 'cpp_reparse_node', {
8585
'event_category' : urlHandler.getState('wsid'),
8686
'event_label' : urlHandler.getFileInfo().name
8787
+ ': '

plugins/git/webgui/js/gitBlame.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ function (on, topic, declare, Color, dom, Tooltip, Text, model, viewHandler,
137137
blameForLines.push(blameForLine);
138138
});
139139

140-
if (gtag) {
141-
gtag ('event', 'git_blame', {
140+
if (window.gtag) {
141+
window.gtag ('event', 'git_blame', {
142142
'event_category' : urlHandler.getState('wsid'),
143143
'event_label' : urlHandler.getFileInfo().name
144144
});

plugins/metrics/webgui/js/metrics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,8 @@ function (declare, dom, topic, style, MenuItem, Button, CheckBox, Select,
536536
});
537537
});
538538

539-
if (gtag) {
540-
gtag ('event', 'metrics', {
539+
if (window.gtag) {
540+
window.gtag ('event', 'metrics', {
541541
'event_category' : urlHandler.getState('wsid'),
542542
'event_label' : urlHandler.getFileInfo().name
543543
});

plugins/search/webgui/js/searchResult.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ function (ObjectStoreModel, BorderContainer, declare, Memory, Observable, topic,
259259
params.range = range;
260260
params.filter = filter;
261261

262-
if (gtag) {
262+
if (window.gtag) {
263263
var type = this._searchTypes.find(t => t.id === data.searchType);
264-
gtag('event', 'search: ' + type.name, {
264+
window.gtag('event', 'search: ' + type.name, {
265265
'event_category': urlHandler.getState('wsid'),
266266
'event_label': params.query
267267
});

webgui/scripts/codecompass/view/codeBites.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ function (declare, array, dom, style, topic, on, ContentPane, ResizeHandle,
130130
}]]
131131
});
132132

133-
if (gtag) {
134-
gtag ('event', 'code_bites', {
133+
if (window.gtag) {
134+
window.gtag ('event', 'code_bites', {
135135
'event_category' : urlHandler.getState('wsid'),
136136
'event_label' : urlHandler.getFileInfo().name
137137
+ ': '

webgui/scripts/codecompass/view/component/Text.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ function (declare, domClass, dom, style, query, topic, ContentPane, Dialog,
343343

344344
this._getSyntaxHighlight(this._fileInfo);
345345

346-
if (gtag) {
347-
gtag('event', 'page_view', {
346+
if (window.gtag) {
347+
window.gtag('event', 'page_view', {
348348
page_location: window.location.href,
349349
page_path: window.location.pathname + window.location.hash,
350350
page_title: urlFileInfo.path
@@ -485,8 +485,8 @@ function (declare, domClass, dom, style, query, topic, ContentPane, Dialog,
485485
astHelper.jumpToDef(astNodeInfo.id, service);
486486
}
487487

488-
if (gtag) {
489-
gtag('event', 'click_on_word', {
488+
if (window.gtag) {
489+
window.gtag('event', 'click_on_word', {
490490
'event_category' : urlHandler.getState('wsid'),
491491
'event_label' : urlHandler.getFileInfo().name
492492
+ ': '

webgui/scripts/codecompass/view/diagram.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ function (declare, attr, dom, query, topic, BorderContainer, ContentPane,
7171
this._handlerId = handlerId;
7272
this._diagramType = diagramType;
7373

74-
if (gtag) {
75-
gtag ('event', 'load_diagram: ' + diagramType.toString(), {
74+
if (window.gtag) {
75+
window.gtag ('event', 'load_diagram: ' + diagramType.toString(), {
7676
'event_category' : urlHandler.getState('wsid'),
7777
'event_label' : urlHandler.getFileInfo().name
7878
});

webgui/scripts/ga.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
var gtag = null;
1+
window.gtag = null;
22
$(document).ready(function() {
33
$.ajax({
44
url: 'ga.txt',
55
dataType: 'text',
66
success: function (gaId) {
7-
console.log('Google Analytics enabled: ' + gaId);
8-
$.getScript('https://www.googletagmanager.com/gtag/js?id=' + gaId);
7+
$.getScript('https://www.googletagmanager.com/gtag/js?id=' + gaId)
8+
.done(function (script, textStatus){
9+
console.log('Google Analytics enabled: ' + gaId);
10+
11+
window.dataLayer = window.dataLayer || [];
912

10-
window.dataLayer = window.dataLayer || [];
13+
window.gtag = function() {
14+
dataLayer.push(arguments);
15+
}
1116

12-
gtag = function() {
13-
dataLayer.push(arguments);
14-
}
15-
16-
gtag('js', new Date());
17-
gtag('config', gaId);
17+
window.gtag('js', new Date());
18+
window.gtag('config', gaId);
19+
})
20+
.fail(function (jqxhr, settings, exception) {
21+
console.log('Failed to connect to Google Tag Manager. Google ' +
22+
'Analytics will not be enabled.');
23+
});
1824
},
1925
statusCode: {
2026
404: function () {

0 commit comments

Comments
 (0)