Skip to content

Commit

Permalink
add custom tracking feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pzmosquito committed May 24, 2020
1 parent 429ba73 commit ee4d343
Show file tree
Hide file tree
Showing 5 changed files with 562 additions and 817 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## How does it work?

`matomo-router5-plugin` will send tracking data when router5 triggers `onTransitionSuccess`.
`matomo-router5-plugin` will send tracking data when router5 triggers `onTransitionSuccess`. Custom tracking is also available when needed.


## What does it track?
Expand Down Expand Up @@ -40,6 +40,8 @@ npm install --save matomo-router5-plugin

## Usage

### initialize as router5 plugin

for additional tracking features, see [matomo guide](https://developer.matomo.org/guides/tracking-javascript-guide). These features will be tracked along with default tracking features.
```js
import matomoPlugin from "matomo-router5-plugin";
Expand All @@ -49,17 +51,29 @@ const router = createRouter();
const matomoOptions = {
trackerUrl: "https://matomo.siteurl.com", // Required.
siteId: 1, // Required.
features: [] // Optional. Additional tracking features.
features: [], // Optional. Additional tracking features.
};

router.usePlugin(matomoPlugin(matomoOptions));
```

You can pass in a function as tracking feature (since 0.2.0).
The function will be evaluated at time of tracking.
You can pass in a function as tracking feature. The function will be evaluated at time of tracking.

```js
features: [
["setUserId", () => user ? user.name : "Anonymous User"]
]
```

### custom tracking

```js
import { track } from "matomo-router5-plugin";

track({
customUrl: "custom url", // Optional.
referrerUrl: "custom referrer url", // Optional.
documentTitle: "custom doc title", // Optional.
features: [], // Optional. Additional tracking features.
});
```
2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ee4d343

Please sign in to comment.