diff --git a/packages/@vuepress/plugin-matomo/.npmignore b/packages/@vuepress/plugin-matomo/.npmignore new file mode 100644 index 0000000000..9b95de5f4b --- /dev/null +++ b/packages/@vuepress/plugin-matomo/.npmignore @@ -0,0 +1,3 @@ +__tests__ +__mocks__ +.temp \ No newline at end of file diff --git a/packages/@vuepress/plugin-matomo/README.md b/packages/@vuepress/plugin-matomo/README.md new file mode 100644 index 0000000000..347fa8af12 --- /dev/null +++ b/packages/@vuepress/plugin-matomo/README.md @@ -0,0 +1,5 @@ +# @vuepress/matomo + +> Google analytics plugin for matomo + +See [documentation](https://vuepress.vuejs.org/plugin/official/plugin-matomo.html). diff --git a/packages/@vuepress/plugin-matomo/index.js b/packages/@vuepress/plugin-matomo/index.js new file mode 100644 index 0000000000..440a303465 --- /dev/null +++ b/packages/@vuepress/plugin-matomo/index.js @@ -0,0 +1,16 @@ +const path = require('path') + +module.exports = (options = {}, context) => ({ + + define () { + const { siteConfig = {}} = context + const MATOMO_SITE_ID = options.siteId || siteConfig.siteId || false + const MATOMO_TRACKER_URL = options.trackerUrl || siteConfig.trackerUrl || false + const MATOMO_ENABLE_LINK_TRACKING = options.enableLinkTracking || siteConfig.enableLinkTracking || true + return { MATOMO_SITE_ID, MATOMO_TRACKER_URL, MATOMO_ENABLE_LINK_TRACKING } + }, + + enhanceAppFiles: [ + path.resolve(__dirname, 'inject.js') + ] +}) diff --git a/packages/@vuepress/plugin-matomo/inject.js b/packages/@vuepress/plugin-matomo/inject.js new file mode 100644 index 0000000000..476db7d6f5 --- /dev/null +++ b/packages/@vuepress/plugin-matomo/inject.js @@ -0,0 +1,23 @@ +/* global MATOMO_SITE_ID, MATOMO_TRACKER_URL, MATOMO_ENABLE_LINK_TRACKING */ + +export default ({ router }) => { + // Google analytics integration + if (MATOMO_SITE_ID && MATOMO_TRACKER_URL) { + var _paq = _paq || []; + /* tracker methods like "setCustomDimension" should be called before "trackPageView" */ + _paq.push(['trackPageView']); + if (MATOMO_ENABLE_LINK_TRACKING) { + _paq.push(['enableLinkTracking']); + } + (function() { + var u=MATOMO_TRACKER_URL; + _paq.push(['setTrackerUrl', u+'piwik.php']); + _paq.push(['setSiteId', MATOMO_SITE_ID]); + var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; + g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); + })(); + router.afterEach(function (to) { + _paq.push(['trackPageView', to.fullPath]); + }); + } +} diff --git a/packages/@vuepress/plugin-matomo/package.json b/packages/@vuepress/plugin-matomo/package.json new file mode 100644 index 0000000000..583735d9e1 --- /dev/null +++ b/packages/@vuepress/plugin-matomo/package.json @@ -0,0 +1,26 @@ +{ + "name": "vuepress-plugin-matomo", + "version": "1.0.0-alpha.31", + "description": "matomo plugin for vuepress", + "main": "index.js", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/vuejs/vuepress.git" + }, + "keywords": [ + "documentation", + "vue", + "vuepress", + "generator", + "matomo" + ], + "author": "ULIVZ ", + "license": "MIT", + "bugs": { + "url": "https://github.com/vuejs/vuepress/issues" + }, + "homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-matomo#readme" +} diff --git a/packages/docs/docs/plugin/official/plugin-matomo.md b/packages/docs/docs/plugin/official/plugin-matomo.md new file mode 100644 index 0000000000..3b47df949d --- /dev/null +++ b/packages/docs/docs/plugin/official/plugin-matomo.md @@ -0,0 +1,48 @@ +--- +title: matomo +metaTitle: Matomo Plugin | VuePress +--- + +# [@vuepress/plugin-matomo](https://github.com/vuejs/vuepress/tree/master/packages/%40vuepress/plugin-matomo) + + +> Matomo plugin + +## Install + +```bash +yarn add -D @vuepress/plugin-matomo +# OR npm install -D @vuepress/plugin-matomo +``` + +## Usage + +```javascript +module.exports = { + plugins: [ + '@vuepress/matomo', + { + 'trackerUrl': '', // Replace with tracking domain, i.e. https://your.domain.com/ + 'siteId': 1, // Replace with relevant site ID for tracking + 'enableLinkTracking': true // optional, defaults to true + } + ] +} +``` + +## Options + +### trackerUrl + +- Type: `string` +- Default: `undefined` + +### siteId + +- Type: `number` +- Default: `undefined` + +### enableLinkTracking + +- Type: `boolean` +- Default: true