feat: add userAgent to web vitals

This commit is contained in:
TheClashFruit 2024-05-04 16:26:45 +02:00
parent 0bdf3b4555
commit 8fdaf75c45
Signed by: TheClashFruit
GPG key ID: 09BB24C34C2F3204
4 changed files with 10 additions and 3 deletions

View file

@ -266,9 +266,10 @@ class Database {
}
async storeVital(metric) {
await this.mysqlPool.execute('INSERT INTO vitals (id, name, navigation_type, rating, entries, delta, value) VALUES (?, ?, ?, ?, ?, ?, ?)', [
await this.mysqlPool.execute('INSERT INTO vitals (id, name, user_agent, navigation_type, rating, entries, delta, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [
metric.id,
metric.name,
metric.userAgent,
metric.navigationType,
metric.rating,
JSON.stringify(metric.entries),
@ -285,6 +286,7 @@ class Database {
id: row.id,
time: new Date(row.time).getTime(),
name: row.name,
user_agent: row.user_agent,
navigation_type: row.navigation_type,
rating: row.rating,
entries: JSON.parse(row.entries),

View file

@ -11,7 +11,7 @@ const nextConfig = {
remotePatterns: [
{
protocol: 'https',
hostname: 'cdn-new.theclashfruit.me',
hostname: 'cdn.theclashfruit.me',
port: '',
pathname: '/**',
},

View file

@ -17,7 +17,11 @@ export default async function handler(req, res) {
});
try {
await db.storeVital(JSON.parse(body));
let b = JSON.parse(body);
b.userAgent = headers['user-agent'];
await db.storeVital(b);
res.status(200).json({
tracked: true,

View file

@ -104,6 +104,7 @@ CREATE TABLE `vitals` (
`id` varchar(255) NOT NULL,
`time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`name` varchar(255) NOT NULL,
`user_agent` VARCHAR(2048) NOT NULL,
`navigation_type` varchar(255) NOT NULL,
`rating` varchar(255) NOT NULL,
`entries` JSON NOT NULL,