gitbook-plugin-ga
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -1,12 +0,4 @@ | ||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
require(["gitbook"], function(gitbook) { | ||
gitbook.events.bind("start", function(e, config) { | ||
config.ga = config.ga || {}; | ||
ga('create', config.ga.token, 'auto'); | ||
ga('send', 'pageview'); | ||
}); | ||
@@ -19,4 +11,4 @@ | ||
gitbook.events.bind("exercise.submit", function(e, data) { | ||
}); | ||
}); |
15
index.js
@@ -6,4 +6,17 @@ module.exports = { | ||
"plugin.js" | ||
] | ||
], | ||
html: { | ||
"body:end": function() { | ||
var config = this.options.pluginsConfig.ga || {}; | ||
if (!config.token) throw "Need to option 'token' for Google Analytics plugin"; | ||
return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){" | ||
+ "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o)," | ||
+ "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)" | ||
+ "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');" | ||
+ "ga('create', '"+config.token+"', 'auto');" | ||
+ "ga('send', 'pageview');</script>"; | ||
} | ||
} | ||
} | ||
}; |
@@ -5,5 +5,5 @@ { | ||
"main": "index.js", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"engines": { | ||
"gitbook": "*" | ||
"gitbook": ">=0.4.6" | ||
}, | ||
@@ -13,8 +13,8 @@ "homepage": "https://github.com/GitbookIO/plugin-ga", | ||
"type": "git", | ||
"url": "https://github.com/GitbookIO/plugin-mixpanel.git" | ||
"url": "https://github.com/GitbookIO/plugin-ga.git" | ||
}, | ||
"license": "Apache 2", | ||
"bugs": { | ||
"url": "https://github.com/GitbookIO/plugin-mixpanel/issues" | ||
"url": "https://github.com/GitbookIO/plugin-ga/issues" | ||
} | ||
} |
Google Analytics tracking for GitBook | ||
============== | ||
You can set the Google Analytics token using the plugins configuration (command line option: `--pluginsConfig`) with the following content: | ||
You can use install it via **NPM**: | ||
``` | ||
$ npm install gitbook-plugin-ga | ||
``` | ||
And use it for your book with in the book.json: | ||
``` | ||
{ | ||
"ga": { | ||
"token": "UA-XXXX-Y" | ||
"plugins": ["ga"] | ||
} | ||
``` | ||
You can set the Google Analytics tracking ID using the plugins configuration in the book.json: | ||
``` | ||
{ | ||
"plugins": ["ga"], | ||
"pluginsConfig": { | ||
"ga": { | ||
"token": "UA-XXXX-Y" | ||
} | ||
} | ||
} | ||
``` | ||
13958
28
30