Skip to content
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

Single analytics file for all builders #3896

Merged
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
50 changes: 50 additions & 0 deletions media/javascript/readthedocs-analytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Google Analytics is a contentious issue inside Read the Docs and in our community.
// Some users are very sensitive and privacy conscious to usage of GA.
// Other users want their own GA tracker on their docs to see the usage their docs get.
// The developers at Read the Docs understand that different users have different priorities
// and we try to respect the different viewpoints as much as possible while also accomplishing
// our own goals.

// Read the Docs largely funds our operations and development through advertising and
// advertisers ask us questions that are easily answered with an analytics solution like
// "how many users do you have in Switzerland browsing Python docs?". We need to be able
// to easily get this data. We also use data from GA for some development decisions such
// as what browsers to support (or not) or how much usage a particular page/feature gets.

// We have taken steps with GA to address some of the privacy issues.
// Read the Docs instructs Google to anonymize IPs sent to them before they are stored (see below).

// We are always exploring our options with respect to analytics and if you would like
// to discuss further, feel free to open an issue on github.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍



// RTD Analytics Code

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

if (typeof READTHEDOCS_DATA !== 'undefined') {
if (READTHEDOCS_DATA.global_analytics_code) {
ga('create', READTHEDOCS_DATA.global_analytics_code, 'auto', 'rtfd');
ga('rtfd.set', 'dimension1', READTHEDOCS_DATA.project);
ga('rtfd.set', 'dimension2', READTHEDOCS_DATA.version);
ga('rtfd.set', 'dimension3', READTHEDOCS_DATA.language);
ga('rtfd.set', 'dimension4', READTHEDOCS_DATA.theme);
ga('rtfd.set', 'dimension5', READTHEDOCS_DATA.programming_language);
ga('rtfd.set', 'dimension6', READTHEDOCS_DATA.builder);
ga('rtfd.set', 'anonymizeIp', true);
ga('rtfd.send', 'pageview');
}

// User Analytics Code
if (READTHEDOCS_DATA.user_analytics_code) {
ga('create', READTHEDOCS_DATA.user_analytics_code, 'auto', 'user');
ga('user.set', 'anonymizeIp', true);
ga('user.send', 'pageview');
}
// End User Analytics Code
}

// end RTD Analytics Code
18 changes: 4 additions & 14 deletions readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def append_conf(self, **__):
media_url = get_absolute_media_url()
user_config.setdefault('extra_javascript', []).extend([
'readthedocs-data.js',
'readthedocs-dynamic-include.js',
'%sstatic/core/js/readthedocs-doc-embed.js' % media_url
'%sstatic/core/js/readthedocs-doc-embed.js' % media_url,
'%sjavascript/readthedocs-analytics.js' % media_url,
])
user_config.setdefault('extra_css', []).extend([
'%scss/badge_only.css' % media_url,
Expand All @@ -112,10 +112,6 @@ def append_conf(self, **__):
with open(os.path.join(docs_path, 'readthedocs-data.js'), 'w') as f:
f.write(rtd_data)

dynamic_include = self.generate_dynamic_include()
with open(os.path.join(docs_path, 'readthedocs-dynamic-include.js'), 'w') as f:
f.write(dynamic_include)

def generate_rtd_data(self, docs_dir):
"""Generate template properties and render readthedocs-data.js."""
# Will be available in the JavaScript as READTHEDOCS_DATA.
Expand All @@ -131,6 +127,8 @@ def generate_rtd_data(self, docs_dir):
'source_suffix': ".md",
'api_host': getattr(settings, 'PUBLIC_API_URL', 'https://readthedocs.org'),
'commit': self.version.project.vcs_repo(self.version.slug).commit,
'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),
'user_analytics_code': self.version.project.analytics_code,
}
data_json = json.dumps(readthedocs_data, indent=4)
data_ctx = {
Expand All @@ -143,14 +141,6 @@ def generate_rtd_data(self, docs_dir):
tmpl = template_loader.get_template('doc_builder/data.js.tmpl')
return tmpl.render(data_ctx)

def generate_dynamic_include(self):
include_ctx = {
'global_analytics_code': getattr(settings, 'GLOBAL_ANALYTICS_CODE', 'UA-17997319-1'),
'user_analytics_code': self.version.project.analytics_code,
}
tmpl = template_loader.get_template('doc_builder/include.js.tmpl')
return tmpl.render(include_ctx)

def build(self):
checkout_path = self.project.checkout_path(self.version.slug)
build_command = [
Expand Down
27 changes: 0 additions & 27 deletions readthedocs/doc_builder/templates/doc_builder/include.js.tmpl

This file was deleted.