Skip to content
Add Google Analytics Tracking code (while respecting DNT) to Jupyter Notebooks
Python JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Simple Jupyter Notebook extension to inject Google Analytics tracking code into Notebooks. Primarily intended for use with a hosted notebook set up, such as JupyterHub


This extension will not load Google Analytics if the user's browser has Do Not Track enabled. This is by design, since Google Analytics itself does not respect the Do Not Track header. Almost all adblockers & privacy addons will also disable Google Analytics.

If you are providing a hosted service that uses this extension, it is your responsibility to:

  • Ensure that your users know they are being tracked
  • Have a privacy policy that explains to users why they are being tracked, what the data is going to be used for, and how they can opt out.k

Don't just not be evil, try actively to be Good!


A virtualenv is recommended for using this. Inside a virtualenv, you can install this extension easily!

pip install nbgoogleanalytics

jupyter nbextensions install --py --sys-prefix nbgoogleanalytics

You can then enable it with:

jupyter nbextensions enable --py --sys-prefix nbgoogleanalytics
jupyter serverextensions enable --sys-prefix nbgoogleanalytics


There's only one configuration parameter, and that's the Google Analytics Tracking Id. You get it after you set up a Google Analytics property, and it looks something like UA-NNNNNNN-N.

You can easily pass that to the extension by passing it as a commandline parameter.

jupyter notebook --GoogleAnalytics.tracking_id="UA-NNNNN-N"
You can’t perform that action at this time.