My project documentation is hosted on readthedocs.org at
http://nsetools.readthedocs.org
Is it possible to use google analytics with documents hosted on readthedocs? Since html is not generated by me, I am not sure where to apply the google analytics code snippet.
Asked
Active
Viewed 800 times
3

Vivek Jha
- 1,520
- 3
- 16
- 26
-
1Looks like RTD have their own tracking code on the sites (https://github.com/rtfd/readthedocs.org/issues/199), but there doesn't seem to be a way to insert your own code. – nyuen Jan 02 '15 at 21:00
2 Answers
1
I haven't tried this myself but see http://www.drmaciver.com/2015/04/getting-google-analytics-on-readthedocs/
Go to the Admin page for your project, Click on “Advanced settings”, Enter your Google Analytics Tracking ID in the box at the bottom that says 'Analytics ID'

Martijn Pieters
- 1,048,767
- 296
- 4,058
- 3,343

Brighty
- 383
- 2
- 11
-
If you use a custom theme such as alabaster, you may need to add the ID to conf.py. See [alabaster theme options](http://alabaster.readthedocs.io/en/latest/customization.html#theme-options). – bcb Aug 02 '16 at 08:43
0
TL;DR
Put googlea<id>.html
(from Google Search Console) into docs/source
and add
html_extra_path = ["googlea<id>.html"]
somewhere in conf.py
, then verify using Google Search Console.
Steps
- Go to Google Search Console and enter your read the docs URL in the URL prefix box: e.g. https://mat-discover.readthedocs.io/en/latest. Click CONTINUE.
- Download the
googlea<id>.html
file and place it indocs/source
(e.g.mat_discover/docs/source
). Usehtml_extra_path
inside ofconf.py
as follows (i.e. add the following line somewhere inconf.py
):
html_extra_path = ["googlea<id>.html"]
- Inside the
docs
folder, run:
make clean
make html
and check to make sure docs/build/html/googlea<id>.html
exists.
- Commit, push, and wait for your RTD website to update (this could take a few minutes)
- If you have the webpage from step 1 still open, click VERIFY, otherwise navigate back to Google Search Console, and re-enter your URL (e.g. https://mat-discover.readthedocs.io/en/latest). If it worked, it should tell you so, and you can then "Go to property". Notice that https://.readthedocs.io/en/latest/.html brings you to a bland HTML page with only the text from the Google Analytics HTML file
Note: Everywhere mentioned, replace "<id>" with the actual ID that is shown from step 1, and "<my-website>>" with the name of your RTD site.

Sterling
- 344
- 3
- 16
-
This doesn't work because the file has to be at the root of the domain, but RTD puts it behind `/
/ – astrojuanlu Jun 12 '23 at 10:19/`.