Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

(feature) Error tracking docs (#18)

Andrii Romasiunfccf6fdfe131
diff --git a/docs/error-tracking.md b/docs/error-tracking.md
new file mode 100644
index 000000000..a0bb4acb7
--- /dev/null
+++ b/docs/error-tracking.md
@@ -0,0 +1,9 @@
+---
+title: Error tracking
+slug: /error-tracking
+---
+
+As well as providing you with regular data insights such as traffic or site speed, Swetrix also offers client-side error tracking.
+This allows you to track when, on which pages and what kind of errors your users are experiencing. The error tracking script is included in swetrix.js by default and can be easily enabled with a [one line of code](/swetrix-js-reference#trackerrors).
+
+Error tracking is included in all plans and is charged as 1 error event = 1 regular event (like a pageview or custom event).
diff --git a/docs/script-reference.md b/docs/script-reference.md
index 4f40f30d0..2aad5967b 100644
--- a/docs/script-reference.md
+++ b/docs/script-reference.md
@@ -121,3 +121,58 @@ swetrix.trackPageview('/hello')
// Track a page view with a path '/hello' and previous page '/world'.
swetrix.trackPageview('/hello', '/world')
```
+
+## trackErrors()
+This function is used to enable automatic client-side error monitoring. It adds an `error` event listener on your site and when an error happens - send it to our APIs.
+
+The data we collect includes the following params if available:
+1. `pid` - the unique Project ID request is related to.
+2. `lc` - users locale (e.g. en_US or uk_UA).
+3. `tz` - users timezone (e.g. Europe/Helsinki).
+4. `pg` - the page user currently views (e.g. /hello).
+5. `name` - error name (e.g. ParseError)
+6. `message` - error message (e.g. Malformed input)
+7. `lineno` / `colno` - on what line and column in your code did the error occur
+8. `filename` - in what file did the error occur
+
+Here's an example of how to use this function with all the available options:
+```javascript
+swetrix.trackErrors({
+ sampleRate: 1,
+ callback: undefined,
+})
+```
+
+| Name | Description | Default value |
+| --- | --- | --- |
+| sampleRate | A number that indicates how many errors should be sent to the server. Accepts values between 0 and 1. For example, if set to 0.5 - only ~50% of errors will be sent to Swetrix. For testing, we recommend setting this value to 1. For production, you should configure it depending on your needs as each error event counts towards your plan. | `1` |
+| callback | A callback used to edit / prevent sending errors. It accepts an object which contains some information about the error (`name`, `message`, `lineno`, `colno`, `filename`), as well as some regular analytics info (`lc`, `tz`, `pg`).<br />The callback is supposed to return the edited payload or `false` to prevent sending the pageview. If `true` is returned, the payload will be sent as-is. | `undefined` |
+
+The `trackErrors` function returns an object with some methods allowing you to alter the behaviour of page tracking:
+```javascript
+{
+ // This function stops the tracking of errors.
+ stop() {},
+}
+```
+
+## trackError()
+This function is used to manually track an error event.
+
+This function takes the following arguments:
+1. `name` - the error name (e.g. ParseError)
+2. (optional) `message` - error message (e.g. Malformed input)
+3. (optional) `lineno` - on what line in your code did the error occur (e.g. 1520)
+4. (optional) `colno` - on what column in your code did the error occur (e.g. 26)
+5. (optional) `filename` - in what file did the error occur (e.g. https://example.com/broken.js)
+
+Here is an example of how to use this function:
+```javascript
+swetrix.trackError({
+ name: 'ParseError',
+ message: 'Malformed input',
+ lineno: 1520,
+ colno: 26,
+ filename: 'https://example.com/broken.js',
+})
+```
diff --git a/sidebars.js b/sidebars.js
index b4b38ca33..9ae09bea5 100644
--- a/sidebars.js
+++ b/sidebars.js
@@ -4,6 +4,7 @@ module.exports = {
'introduction',
'add-script',
'script-reference',
+ 'error-tracking',
'integration-guides',
{
type: 'category',