Skip to main content

Adds Google Analytics to Jupyter notebooks

Project description

Jupyter Analytics

A simple Jupyter Notebook extension to inject Google Analytics tracking code into notebooks and JupyterHub web pages. This extension is based on yuvipanda/nbgoogleanyltics but is extended for larger JupyterHub deployments.

Installation

Install the extension as follows:

$ pip install jupyteranalytics

This should both install and enable the jupyteranalytics extension. Verify with:

$ jupyter nbextension list
$ jupyter serverextension list

There are a couple of reasons why this might not have been installed and enabled automagically. If not, you can manually install and enable as follows:

$ jupyter nbextension install --py --sys-prefix jupyteranalytics
$ jupyter nbextension enable --py --sys-prefix jupyteranalytics
$ jupyter serverextension enable --py --sys-prefix jupyteranalytics

Note that both the automatic and manual methods install jupyteranalytics to your virtualenv using the --sys-prefix flag by default. Alternatively you can omit this flag or specify --user to install the configuration to your user configuration or you can use --system to install the extension systemwide.

Warning: For Google Analytics tracking to appear on every page (including the directory listing), the configuration must be in nbconfig/common.json, the pip installer will copy a new configuration to the virtualenv location; ensure that you make a backup of any existing nbconfig.common.json file. Note that this will not affect user or system installs, which require manual enabling of the extension.

Configuration

The configuration property required by this extension is a Google Analytics Tracking ID, which can be obtained after you set up a Google Analytics property. This ID looks something like UA-#########-#.

To quickly get started you can pass this id as a command line parameter:

$ jupyter notebook --GoogleAnalytics.tracking_id="UA-#########-#"

To permenantly enable tracking on all notebook pages, check the path to your configuration using jupyter nbextension list. Then, in <config_path>/common.json add the following:

{
    "GoogleAnalytics": {
        "tracking_id": "UA-#########-#"
    }
}

Alternatively you can set the Trackig ID by storing it in the GOOGLE_ANALYTICS_TRACKING_ID environment variable, this is particularly useful if you're deploying JupyterHub with Docker or Kubernetes.

Note that the notebook logger will indicate if tracking is enabled if it can find the Tracking ID from the configuration, the environment, or the command line (resolved in that order). It will also indicate if the analytics are disabled because no tracking id could be found. Ensure that you have system logging enabled to check that your deployment is correct.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jupyteranalytics-1.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

jupyteranalytics-1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file jupyteranalytics-1.1.tar.gz.

File metadata

  • Download URL: jupyteranalytics-1.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for jupyteranalytics-1.1.tar.gz
Algorithm Hash digest
SHA256 3186ebe0eb856ebd870a3b036666fc1fec87a537f1d4e549ac40dcf641553960
MD5 fb046e8797872e24a10958f9d16799f4
BLAKE2b-256 988015a9c6a8a165a832074912575ede1d5962e91d17ded62c80d6ba5f720baa

See more details on using hashes here.

File details

Details for the file jupyteranalytics-1.1-py3-none-any.whl.

File metadata

  • Download URL: jupyteranalytics-1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for jupyteranalytics-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cfeea8d8b0a113993418755bdec6bcf9d0e011679abe92aaaa2e4a8757626c6
MD5 9d339ef65fff7cc1abb4c558654afdfd
BLAKE2b-256 a603e48202f9872ed75c3fba5aaf8e1e7f93e236385bf588b82e0f909f561239

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page