Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Add documentation for the pushInstruction() function
Browse files Browse the repository at this point in the history
And also list all the functions exposed by the 'useMatomo()' hook.
  • Loading branch information
Guruprasad Lakshmi Narayanan authored and jonkoops committed Sep 4, 2020
1 parent b56ca50 commit b85bc1e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ const MyPage = () => {
}
```

The `useMatomo` hook also exposes the following methods:
* `trackEvents()`
* `trackSiteSearch()`
* `trackLink()`
* `pushInstruction()`

For example, the `pushInstruction()` function can be used to push instructions to Matomo for execution. This
is equivalent to pushing entries into the `_paq` array.


```javascript
const { pushInstruction } = useMatomo();
pushInstruction('setUserId', 'USER_ID_HERE');
```

## SPA Link Tracking

Matomo provides the option to track outbound link, however, this implementation is flaky for a SPA (Single Page Application) **without** SSR (Server Side Rendering) across different versions of Matomo. Therefore you can use the `enableLinkTracking` method to listen to outbound clicks on anchor elements. This method should be placed on a component directly below your `MatomoProvider` on a component that's rendered on every page view. Also, make sure to disable the `enableLinkTracking` option on the instance passed to the provider to prevent Matomo from catching some link clicks:
Expand Down

0 comments on commit b85bc1e

Please sign in to comment.