Swetrix / swetrix

Cookieless, open source and privacy-first web analytics service
https://swetrix.com
GNU Affero General Public License v3.0
263 stars 29 forks source link

(feature) webhook alerts #244

Open pro1code1hack opened 3 months ago

pro1code1hack commented 3 months ago

Please describe your changes using the checklist below.

Self-hosted support

Database migrations

Documentation

How to test this feature:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;

app.use(bodyParser.json());

app.post('/webhook', (req, res) => {
    console.log('Received webhook:', req.body);

    res.status(200).send('Webhook received');
});

app.listen(port, () => {
    console.log(`Webhook receiver listening at http://localhost:${port}`);
});

You should see the following output in the console:

 {
  event: 'user.alert.metrics',
  data: {
    alertName: 'Test Alert',
    projectName: 'Your awesome project',
    count: 0,
    queryMetric: 'page_views',
    queryCustomEvent: null,
    queryTime: '0'
  }
}