Skip to content

Commit d4fe8ce

Browse files
authored
Merge pull request #8398 from readthedocs/fix-analytics-gtag
Only call analytics tracking of flyout when analytics are enabled
2 parents 5c51074 + 3ca5e32 commit d4fe8ce

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

readthedocs/core/static-src/core/js/doc-embed/sphinx.js

+19-16
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,25 @@ function init() {
1414
$(document).on('click', "[data-toggle='rst-current-version']", function () {
1515
var flyout_state = $("[data-toggle='rst-versions']").hasClass('shift-up') ? 'was_open' : 'was_closed';
1616

17-
// This needs to handle old style legacy analytics for previously built docs
18-
// as well as the newer universal analytics and Google Site Tag
19-
if (typeof gtag !== 'undefined') {
20-
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
21-
gtag('event', 'Click', {
22-
'event_category': 'Flyout',
23-
'event_label': flyout_state,
24-
'send_to': 'rtfd'
25-
});
26-
} else if (typeof ga !== 'undefined') {
27-
ga('rtfd.send', 'event', 'Flyout', 'Click', flyout_state);
28-
} else if (typeof _gaq !== 'undefined') {
29-
_gaq.push(
30-
['rtfd._setAccount', 'UA-17997319-1'],
31-
['rtfd._trackEvent', 'Flyout', 'Click', flyout_state]
32-
);
17+
// Only report back if analytics is enabled
18+
if (typeof READTHEDOCS_DATA !== 'undefined' && READTHEDOCS_DATA.global_analytics_code) {
19+
// This needs to handle old style legacy analytics for previously built docs
20+
// as well as the newer universal analytics and Google Site Tag
21+
if (typeof gtag !== 'undefined') {
22+
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
23+
gtag('event', 'Click', {
24+
'event_category': 'Flyout',
25+
'event_label': flyout_state,
26+
'send_to': 'rtfd'
27+
});
28+
} else if (typeof ga !== 'undefined') {
29+
ga('rtfd.send', 'event', 'Flyout', 'Click', flyout_state);
30+
} else if (typeof _gaq !== 'undefined') {
31+
_gaq.push(
32+
['rtfd._setAccount', 'UA-17997319-1'],
33+
['rtfd._trackEvent', 'Flyout', 'Click', flyout_state]
34+
);
35+
}
3336
}
3437
});
3538

0 commit comments

Comments
 (0)