Skip to content

Only call analytics tracking of flyout when analytics are enabled #8398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions readthedocs/core/static-src/core/js/doc-embed/sphinx.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ function init() {
$(document).on('click', "[data-toggle='rst-current-version']", function () {
var flyout_state = $("[data-toggle='rst-versions']").hasClass('shift-up') ? 'was_open' : 'was_closed';

// This needs to handle old style legacy analytics for previously built docs
// as well as the newer universal analytics and Google Site Tag
if (typeof gtag !== 'undefined') {
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
gtag('event', 'Click', {
'event_category': 'Flyout',
'event_label': flyout_state,
'send_to': 'rtfd'
});
} else if (typeof ga !== 'undefined') {
ga('rtfd.send', 'event', 'Flyout', 'Click', flyout_state);
} else if (typeof _gaq !== 'undefined') {
_gaq.push(
['rtfd._setAccount', 'UA-17997319-1'],
['rtfd._trackEvent', 'Flyout', 'Click', flyout_state]
);
// Only report back if analytics is enabled
if (typeof READTHEDOCS_DATA !== 'undefined' && READTHEDOCS_DATA.global_analytics_code) {
// This needs to handle old style legacy analytics for previously built docs
// as well as the newer universal analytics and Google Site Tag
if (typeof gtag !== 'undefined') {
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
gtag('event', 'Click', {
'event_category': 'Flyout',
'event_label': flyout_state,
'send_to': 'rtfd'
});
} else if (typeof ga !== 'undefined') {
ga('rtfd.send', 'event', 'Flyout', 'Click', flyout_state);
} else if (typeof _gaq !== 'undefined') {
_gaq.push(
['rtfd._setAccount', 'UA-17997319-1'],
['rtfd._trackEvent', 'Flyout', 'Click', flyout_state]
);
}
}
});

Expand Down
Loading