Skip to content

Fix #604 - feat: matomo plugin #1182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/@vuepress/plugin-matomo/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__tests__
__mocks__
.temp
5 changes: 5 additions & 0 deletions packages/@vuepress/plugin-matomo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @vuepress/matomo

> Google analytics plugin for matomo

See [documentation](https://vuepress.vuejs.org/plugin/official/plugin-matomo.html).
16 changes: 16 additions & 0 deletions packages/@vuepress/plugin-matomo/index.js
Original file line number Diff line number Diff line change
@@ -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')
]
})
23 changes: 23 additions & 0 deletions packages/@vuepress/plugin-matomo/inject.js
Original file line number Diff line number Diff line change
@@ -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]);
});
}
}
26 changes: 26 additions & 0 deletions packages/@vuepress/plugin-matomo/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/vuejs/vuepress/issues"
},
"homepage": "https://github.com/vuejs/vuepress/packages/@vuepress/plugin-matomo#readme"
}
48 changes: 48 additions & 0 deletions packages/docs/docs/plugin/official/plugin-matomo.md
Original file line number Diff line number Diff line change
@@ -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