mirror of
https://github.com/umami-software/umami.git
synced 2026-02-19 03:55:37 +01:00
send events
This commit is contained in:
parent
2d9e899e46
commit
9245fb5d80
1 changed files with 33 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable no-console */
|
||||||
import { EVENT_NAME_LENGTH, URL_LENGTH, EVENT_TYPE, PAGE_TITLE_LENGTH } from 'lib/constants';
|
import { EVENT_NAME_LENGTH, URL_LENGTH, EVENT_TYPE, PAGE_TITLE_LENGTH } from 'lib/constants';
|
||||||
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
import { CLICKHOUSE, PRISMA, runQuery } from 'lib/db';
|
||||||
import clickhouse from 'lib/clickhouse';
|
import clickhouse from 'lib/clickhouse';
|
||||||
|
|
@ -29,7 +30,39 @@ export async function saveEvent(args: {
|
||||||
subdivision2?: string;
|
subdivision2?: string;
|
||||||
city?: string;
|
city?: string;
|
||||||
tag?: string;
|
tag?: string;
|
||||||
|
ip?: string;
|
||||||
}) {
|
}) {
|
||||||
|
// Log the tracking event to console
|
||||||
|
console.log('Tracking event:', args);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('http://localhost:8000/track/', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
fingerprint: args.sessionId,
|
||||||
|
referrer: args.referrerDomain || args.referrerPath,
|
||||||
|
url: args.urlPath,
|
||||||
|
title: args.pageTitle,
|
||||||
|
event_name: args.eventName,
|
||||||
|
event_data: args.eventData,
|
||||||
|
browser: args.browser,
|
||||||
|
os: args.os,
|
||||||
|
device: args.device,
|
||||||
|
screen: args.screen,
|
||||||
|
language: args.language,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
console.error('Failed to send event to Django:', response.statusText);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error sending event to Django:', error);
|
||||||
|
}
|
||||||
|
|
||||||
return runQuery({
|
return runQuery({
|
||||||
[PRISMA]: () => relationalQuery(args),
|
[PRISMA]: () => relationalQuery(args),
|
||||||
[CLICKHOUSE]: () => clickhouseQuery(args),
|
[CLICKHOUSE]: () => clickhouseQuery(args),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue