Skip to content

Commit

Permalink
Fix Web GUI breaking with ad blockers (Ericsson#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
andocz authored Mar 7, 2022
1 parent 959f63f commit 4c9f38a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 30 deletions.
4 changes: 2 additions & 2 deletions plugins/cpp/webgui/js/cppMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function (topic, Menu, MenuItem, PopupMenuItem, astHelper, model, urlHandler, vi
elementInfo : nodeInfo
});

if (gtag) {
gtag ('event', 'documentation', {
if (window.gtag) {
window.gtag ('event', 'documentation', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
+ ': '
Expand Down
8 changes: 4 additions & 4 deletions plugins/cpp_reparse/webgui/js/cppReparseFileAST.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ function (on, topic, declare, Color, Deferred, dom, ContentPane, Tooltip,
}
);

if (gtag) {
gtag ('event', 'cpp_reparse_file', {
if (window.gtag) {
window.gtag ('event', 'cpp_reparse_file', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
});
Expand All @@ -80,8 +80,8 @@ function (on, topic, declare, Color, Deferred, dom, ContentPane, Tooltip,
}
);

if (gtag) {
gtag ('event', 'cpp_reparse_node', {
if (window.gtag) {
window.gtag ('event', 'cpp_reparse_node', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
+ ': '
Expand Down
4 changes: 2 additions & 2 deletions plugins/git/webgui/js/gitBlame.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ function (on, topic, declare, Color, dom, Tooltip, Text, model, viewHandler,
blameForLines.push(blameForLine);
});

if (gtag) {
gtag ('event', 'git_blame', {
if (window.gtag) {
window.gtag ('event', 'git_blame', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
});
Expand Down
4 changes: 2 additions & 2 deletions plugins/metrics/webgui/js/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ function (declare, dom, topic, style, MenuItem, Button, CheckBox, Select,
});
});

if (gtag) {
gtag ('event', 'metrics', {
if (window.gtag) {
window.gtag ('event', 'metrics', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
});
Expand Down
4 changes: 2 additions & 2 deletions plugins/search/webgui/js/searchResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ function (ObjectStoreModel, BorderContainer, declare, Memory, Observable, topic,
params.range = range;
params.filter = filter;

if (gtag) {
if (window.gtag) {
var type = this._searchTypes.find(t => t.id === data.searchType);
gtag('event', 'search: ' + type.name, {
window.gtag('event', 'search: ' + type.name, {
'event_category': urlHandler.getState('wsid'),
'event_label': params.query
});
Expand Down
4 changes: 2 additions & 2 deletions webgui/scripts/codecompass/view/codeBites.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ function (declare, array, dom, style, topic, on, ContentPane, ResizeHandle,
}]]
});

if (gtag) {
gtag ('event', 'code_bites', {
if (window.gtag) {
window.gtag ('event', 'code_bites', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
+ ': '
Expand Down
8 changes: 4 additions & 4 deletions webgui/scripts/codecompass/view/component/Text.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ function (declare, domClass, dom, style, query, topic, ContentPane, Dialog,

this._getSyntaxHighlight(this._fileInfo);

if (gtag) {
gtag('event', 'page_view', {
if (window.gtag) {
window.gtag('event', 'page_view', {
page_location: window.location.href,
page_path: window.location.pathname + window.location.hash,
page_title: urlFileInfo.path
Expand Down Expand Up @@ -485,8 +485,8 @@ function (declare, domClass, dom, style, query, topic, ContentPane, Dialog,
astHelper.jumpToDef(astNodeInfo.id, service);
}

if (gtag) {
gtag('event', 'click_on_word', {
if (window.gtag) {
window.gtag('event', 'click_on_word', {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
+ ': '
Expand Down
4 changes: 2 additions & 2 deletions webgui/scripts/codecompass/view/diagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ function (declare, attr, dom, query, topic, BorderContainer, ContentPane,
this._handlerId = handlerId;
this._diagramType = diagramType;

if (gtag) {
gtag ('event', 'load_diagram: ' + diagramType.toString(), {
if (window.gtag) {
window.gtag ('event', 'load_diagram: ' + diagramType.toString(), {
'event_category' : urlHandler.getState('wsid'),
'event_label' : urlHandler.getFileInfo().name
});
Expand Down
26 changes: 16 additions & 10 deletions webgui/scripts/ga.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
var gtag = null;
window.gtag = null;
$(document).ready(function() {
$.ajax({
url: 'ga.txt',
dataType: 'text',
success: function (gaId) {
console.log('Google Analytics enabled: ' + gaId);
$.getScript('https://www.googletagmanager.com/gtag/js?id=' + gaId);
$.getScript('https://www.googletagmanager.com/gtag/js?id=' + gaId)
.done(function (script, textStatus){
console.log('Google Analytics enabled: ' + gaId);

window.dataLayer = window.dataLayer || [];

window.dataLayer = window.dataLayer || [];
window.gtag = function() {
dataLayer.push(arguments);
}

gtag = function() {
dataLayer.push(arguments);
}

gtag('js', new Date());
gtag('config', gaId);
window.gtag('js', new Date());
window.gtag('config', gaId);
})
.fail(function (jqxhr, settings, exception) {
console.log('Failed to connect to Google Tag Manager. Google ' +
'Analytics will not be enabled.');
});
},
statusCode: {
404: function () {
Expand Down

0 comments on commit 4c9f38a

Please sign in to comment.