@@ -100,18 +100,23 @@ def append_conf(self, **__):
100
100
if 'theme_dir' not in user_config and self .use_theme :
101
101
user_config ['theme_dir' ] = TEMPLATE_DIR
102
102
103
- yaml .safe_dump (
104
- user_config ,
105
- open (os .path .join (self .root_path , 'mkdocs.yml' ), 'w' )
106
- )
107
-
108
103
docs_path = os .path .join (self .root_path , docs_dir )
109
104
110
105
# RTD javascript writing
111
106
rtd_data = self .generate_rtd_data (docs_dir = docs_dir , mkdocs_config = user_config )
112
107
with open (os .path .join (docs_path , 'readthedocs-data.js' ), 'w' ) as f :
113
108
f .write (rtd_data )
114
109
110
+ # Use Read the Docs' analytics setup rather than mkdocs'
111
+ # This supports using RTD's privacy improvements around analytics
112
+ user_config ['google_analytics' ] = None
113
+
114
+ # Write the mkdocs configuration
115
+ yaml .safe_dump (
116
+ user_config ,
117
+ open (os .path .join (self .root_path , 'mkdocs.yml' ), 'w' )
118
+ )
119
+
115
120
def generate_rtd_data (self , docs_dir , mkdocs_config ):
116
121
"""Generate template properties and render readthedocs-data.js."""
117
122
# Get the theme name
@@ -120,6 +125,12 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
120
125
if theme_dir :
121
126
theme_name = theme_dir .rstrip ('/' ).split ('/' )[- 1 ]
122
127
128
+ # Use the analytics code from mkdocs.yml if it isn't set already by Read the Docs
129
+ analytics_code = self .version .project .analytics_code
130
+ if not analytics_code and mkdocs_config .get ('google_analytics' ):
131
+ # http://www.mkdocs.org/user-guide/configuration/#google_analytics
132
+ analytics_code = mkdocs_config ['google_analytics' ][0 ]
133
+
123
134
# Will be available in the JavaScript as READTHEDOCS_DATA.
124
135
readthedocs_data = {
125
136
'project' : self .version .project .slug ,
@@ -134,7 +145,7 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
134
145
'api_host' : getattr (settings , 'PUBLIC_API_URL' , 'https://readthedocs.org' ),
135
146
'commit' : self .version .project .vcs_repo (self .version .slug ).commit ,
136
147
'global_analytics_code' : getattr (settings , 'GLOBAL_ANALYTICS_CODE' , 'UA-17997319-1' ),
137
- 'user_analytics_code' : self . version . project . analytics_code ,
148
+ 'user_analytics_code' : analytics_code ,
138
149
}
139
150
data_json = json .dumps (readthedocs_data , indent = 4 )
140
151
data_ctx = {
0 commit comments