Vivek Jha
Vivek Jha

Reputation: 1590

Using Google Analytics in readthedocs.org

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.

Upvotes: 3

Views: 975

Answers (2)

Sterling
Sterling

Reputation: 456

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

  1. 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.
  2. Download the googlea<id>.html file and place it in docs/source (e.g. mat_discover/docs/source). Use html_extra_path inside of conf.py as follows (i.e. add the following line somewhere in conf.py):
html_extra_path = ["googlea<id>.html"]
  1. Inside the docs folder, run:
make clean
make html

and check to make sure docs/build/html/googlea<id>.html exists.

  1. Commit, push, and wait for your RTD website to update (this could take a few minutes)
  2. 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.

Upvotes: 1

Brighty
Brighty

Reputation: 393

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'

Upvotes: 1

Related Questions