Google Analytics tracking for GitBook

You can use install it via NPM:

  1. $ npm install gitbook-plugin-ga

And use it for your book with in the book.json:

  1. {
  2. "plugins": ["ga"]
  3. }

You can set the Google Analytics tracking ID using the plugins configuration in the book.json:

  1. {
  2. "plugins": ["ga"],
  3. "pluginsConfig": {
  4. "ga": {
  5. "token": "UA-XXXX-Y"
  6. }
  7. }
  8. }

You can customize the tracker object by passing additional configuration options. You can either pass in auto, none or an object:

  1. {
  2. "plugins": ["ga"],
  3. "pluginsConfig": {
  4. "ga": {
  5. "token": "UA-XXXX-Y",
  6. "configuration": {
  7. "cookieName": "new_cookie_name",
  8. "cookieDomain": "mynew.domain.com"
  9. }
  10. }
  11. }
  12. }

For an overview of all available configuration parameters, please refer to the analytics.js field reference.