mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Merge branch 'dev' of https://github.com/umami-software/umami into feat/add-segments
This commit is contained in:
commit
1ccc8a1a86
16 changed files with 360 additions and 272 deletions
|
|
@ -145,7 +145,8 @@ export async function POST(request: Request) {
|
|||
const base = hostname ? `https://${hostname}` : 'https://localhost';
|
||||
const currentUrl = new URL(url, base);
|
||||
|
||||
let urlPath = currentUrl.pathname === '/undefined' ? '' : currentUrl.pathname;
|
||||
let urlPath =
|
||||
currentUrl.pathname === '/undefined' ? '' : currentUrl.pathname + currentUrl.hash;
|
||||
const urlQuery = currentUrl.search.substring(1);
|
||||
const urlDomain = currentUrl.hostname.replace(/^www./, '');
|
||||
|
||||
|
|
@ -169,7 +170,7 @@ export async function POST(request: Request) {
|
|||
const twclid = currentUrl.searchParams.get('twclid');
|
||||
|
||||
if (process.env.REMOVE_TRAILING_SLASH) {
|
||||
urlPath = urlPath.replace(/(.+)\/$/, '$1');
|
||||
urlPath = urlPath.replace(/\/(?=(#.*)?$)/, '');
|
||||
}
|
||||
|
||||
if (referrer) {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@
|
|||
"label.add": "أضِف",
|
||||
"label.add-description": "أضِف وصف",
|
||||
"label.add-member": "أضِف عضو",
|
||||
"label.add-step": "Add step",
|
||||
"label.add-step": "إضافة خطوة",
|
||||
"label.add-website": "إضافة موقع",
|
||||
"label.admin": "مدير",
|
||||
"label.after": "يعد",
|
||||
"label.all": "الكل",
|
||||
"label.all-time": "كل الوقت",
|
||||
"label.analytics": "تحليلات",
|
||||
"label.attribution": "الإسناد",
|
||||
"label.attribution-description": "شاهد كيف يتفاعل المستخدمون مع حملاتك التسويقية وما الذي يحفز التحويلات.",
|
||||
"label.average": "المتوسط",
|
||||
"label.back": "للخلف",
|
||||
"label.before": "قبل",
|
||||
|
|
@ -19,17 +21,17 @@
|
|||
"label.breakdown": "التصنيف",
|
||||
"label.browser": "المتصفح",
|
||||
"label.browsers": "المتصفحات",
|
||||
"label.cancel": "ألغِ",
|
||||
"label.cancel": "إلغاء",
|
||||
"label.change-password": "تغيير كلمة المرور",
|
||||
"label.cities": "المدن",
|
||||
"label.city": "المدينة",
|
||||
"label.clear-all": "مسح الكل",
|
||||
"label.compare": "Compare",
|
||||
"label.compare": "المقارنة",
|
||||
"label.confirm": "تأكيد",
|
||||
"label.confirm-password": "تأكيد كلمة المرور",
|
||||
"label.contains": "يحتوي",
|
||||
"label.contains": "يحتوي على",
|
||||
"label.continue": "تابع",
|
||||
"label.count": "Count",
|
||||
"label.count": "العدد",
|
||||
"label.countries": "الدول",
|
||||
"label.country": "الدولة",
|
||||
"label.create": "أنشِئ",
|
||||
|
|
@ -38,10 +40,10 @@
|
|||
"label.create-user": "أنشِئ مستخدم",
|
||||
"label.created": "أُنشئت",
|
||||
"label.created-by": "أُنشئ من قبل",
|
||||
"label.current": "Current",
|
||||
"label.current": "الحالي",
|
||||
"label.current-password": "كلمة المرور الحالية",
|
||||
"label.custom-range": "فترة مخصّصة",
|
||||
"label.dashboard": "الشاشة الرئيسية",
|
||||
"label.dashboard": "لوحة التحكم",
|
||||
"label.data": "البيانات",
|
||||
"label.date": "التاريخ",
|
||||
"label.date-range": "فترة مخصّصة",
|
||||
|
|
@ -58,19 +60,19 @@
|
|||
"label.device": "الجهاز",
|
||||
"label.devices": "الأجهزة",
|
||||
"label.dismiss": "تجاهل",
|
||||
"label.does-not-contain": "لا يحتوي",
|
||||
"label.does-not-contain": "لا يحتوي على",
|
||||
"label.domain": "النطاق",
|
||||
"label.dropoff": "إنزال",
|
||||
"label.edit": "عدّل",
|
||||
"label.edit": "تعديل",
|
||||
"label.edit-dashboard": "عدّل لوحة التحكم",
|
||||
"label.edit-member": "عدّل العضو",
|
||||
"label.enable-share-url": "فعّل مشاركة الرابط",
|
||||
"label.end-step": "End Step",
|
||||
"label.entry": "Entry URL",
|
||||
"label.end-step": "الخطوة الأخيرة",
|
||||
"label.entry": "رابط الدخول",
|
||||
"label.event": "الحدث",
|
||||
"label.event-data": "تاريخ الحدث",
|
||||
"label.events": "الأحداث",
|
||||
"label.exit": "Exit URL",
|
||||
"label.exit": "رابط المغادرة",
|
||||
"label.false": "خطأ",
|
||||
"label.field": "الحقل",
|
||||
"label.fields": "الحقول",
|
||||
|
|
@ -78,33 +80,33 @@
|
|||
"label.filter-combined": "مُجمّعة",
|
||||
"label.filter-raw": "خام",
|
||||
"label.filters": "التصفيات",
|
||||
"label.first-seen": "First seen",
|
||||
"label.first-seen": "أول ظهور",
|
||||
"label.funnel": "قمع",
|
||||
"label.funnel-description": "فهم معدل التحويل والانقطاع عن المستخدمين.",
|
||||
"label.goal": "Goal",
|
||||
"label.goals": "Goals",
|
||||
"label.goals-description": "Track your goals for pageviews and events.",
|
||||
"label.goal": "الهدف",
|
||||
"label.goals": "الأهداف",
|
||||
"label.goals-description": "تابع تحقق أهدافك المرتبطة بمشاهدات الصفحات والأحداث.",
|
||||
"label.greater-than": "أكبَر مِن",
|
||||
"label.greater-than-equals": "أكبَر مِن أو يساوي",
|
||||
"label.host": "Host",
|
||||
"label.hosts": "Hosts",
|
||||
"label.insights": "نتائج التحليلات",
|
||||
"label.insights-description": "تعمق في بياناتك باستخدام الشرائح والتصفيات.",
|
||||
"label.is": "هو",
|
||||
"label.is-not": "لم",
|
||||
"label.is": "يساوي",
|
||||
"label.is-not": "لا يساوي",
|
||||
"label.is-not-set": "لم ضُبط",
|
||||
"label.is-set": "ضُبط",
|
||||
"label.join": "انضم",
|
||||
"label.join-team": "انضم للفريق",
|
||||
"label.journey": "Journey",
|
||||
"label.journey-description": "Understand how users navigate through your website.",
|
||||
"label.journey": "رحلة المستخدم",
|
||||
"label.journey-description": "تعرّف على كيفية تنقّل المستخدمين داخل موقعك.",
|
||||
"label.language": "اللغة",
|
||||
"label.languages": "اللغات",
|
||||
"label.laptop": "لابتوب",
|
||||
"label.last-days": "آخر {x} يوم/ايام",
|
||||
"label.last-hours": "آخر {x} ساعة",
|
||||
"label.last-months": "Last {x} months",
|
||||
"label.last-seen": "Last seen",
|
||||
"label.last-months": "آخر {x} شهر/أشهر",
|
||||
"label.last-seen": "آخر ظهور",
|
||||
"label.leave": "غادر",
|
||||
"label.leave-team": "مغادرة المجموعة",
|
||||
"label.less-than": "أقل مِن",
|
||||
|
|
@ -112,7 +114,7 @@
|
|||
"label.login": "تسجيل الدخول",
|
||||
"label.logout": "تسجيل الخروج",
|
||||
"label.manage": "التحكم",
|
||||
"label.manager": "Manager",
|
||||
"label.manager": "مدير",
|
||||
"label.max": "الحد الأقصى",
|
||||
"label.member": "عضو",
|
||||
"label.members": "الأعضاء",
|
||||
|
|
@ -134,15 +136,15 @@
|
|||
"label.pageTitle": "عنوان الصفحة",
|
||||
"label.pages": "الصفحات",
|
||||
"label.password": "كلمة المرور",
|
||||
"label.path": "Path",
|
||||
"label.paths": "Paths",
|
||||
"label.path": "المسار",
|
||||
"label.paths": "المسارات",
|
||||
"label.powered-by": "مشغل بواسطة {name}",
|
||||
"label.previous": "Previous",
|
||||
"label.previous-period": "Previous period",
|
||||
"label.previous-year": "Previous year",
|
||||
"label.previous": "السابق",
|
||||
"label.previous-period": "الفترة السابقة",
|
||||
"label.previous-year": "العام السابق",
|
||||
"label.profile": "الملف الشخصي",
|
||||
"label.properties": "Properties",
|
||||
"label.property": "Property",
|
||||
"label.properties": "الخصائص",
|
||||
"label.property": "الخاصية",
|
||||
"label.queries": "استعلامات",
|
||||
"label.query": "استعلام",
|
||||
"label.query-parameters": "متغيرات الرابط",
|
||||
|
|
@ -161,9 +163,9 @@
|
|||
"label.reset-website": "اعادة تعيين الإحصائيات",
|
||||
"label.retention": "الاحتفاظ",
|
||||
"label.retention-description": "قس مدى ثبات موقعك على الويب من خلال تتبع عدد مرات عودة المستخدمين.",
|
||||
"label.revenue": "Revenue",
|
||||
"label.revenue-description": "Look into your revenue across time.",
|
||||
"label.revenue-property": "Revenue Property",
|
||||
"label.revenue": "الإيرادات",
|
||||
"label.revenue-description": "قم بإلقاء نظرة على بيانات إيراداتك وكيفية إنفاق المستخدمين.",
|
||||
"label.revenue-property": "خاصية الإيرادات",
|
||||
"label.role": "الصلاحية",
|
||||
"label.run-query": "شغّل الاستعلام",
|
||||
"label.save": "حفظ",
|
||||
|
|
@ -173,22 +175,24 @@
|
|||
"label.select-date": "حدد التاريخ",
|
||||
"label.select-role": "حدد الدور",
|
||||
"label.select-website": "حدد موقع",
|
||||
"label.session": "Session",
|
||||
"label.session": "الزيارة",
|
||||
"label.sessions": "الزيارات",
|
||||
"label.settings": "الإعدادات",
|
||||
"label.share-url": "مشاركة الرابط",
|
||||
"label.single-day": "يوم واحد",
|
||||
"label.start-step": "Start Step",
|
||||
"label.steps": "Steps",
|
||||
"label.start-step": "الخطوة الأولى",
|
||||
"label.steps": "الخطوات",
|
||||
"label.sum": "المجموع",
|
||||
"label.tablet": "تابلت",
|
||||
"label.tag": "الوسم",
|
||||
"label.tags": "الوسوم",
|
||||
"label.team": "الفريق",
|
||||
"label.team-id": "معرّف الفريق",
|
||||
"label.team-manager": "Team manager",
|
||||
"label.team-manager": "مدير الفريق",
|
||||
"label.team-member": "عضو الفريق",
|
||||
"label.team-name": "اسم الفريق",
|
||||
"label.team-owner": "مدير الفريق",
|
||||
"label.team-view-only": "Team view only",
|
||||
"label.team-view-only": "عرض الفريق فقط",
|
||||
"label.team-websites": "مواقع الفريق",
|
||||
"label.teams": "الفرق",
|
||||
"label.theme": "السمة",
|
||||
|
|
@ -202,34 +206,34 @@
|
|||
"label.total": "الإجمالي",
|
||||
"label.total-records": "إجمالي السجلات",
|
||||
"label.tracking-code": "كود التتبع",
|
||||
"label.transactions": "Transactions",
|
||||
"label.transfer": "Transfer",
|
||||
"label.transactions": "المعاملات",
|
||||
"label.transfer": "نقل",
|
||||
"label.transfer-website": "انقل الموقع",
|
||||
"label.true": "حقيقي",
|
||||
"label.type": "النوع",
|
||||
"label.unique": "فريد",
|
||||
"label.unique-visitors": "زائرون فريدون",
|
||||
"label.uniqueCustomers": "Unique Customers",
|
||||
"label.uniqueCustomers": "العملاء الفريدون",
|
||||
"label.unknown": "غير معروف",
|
||||
"label.untitled": "بدون عنوان",
|
||||
"label.update": "Update",
|
||||
"label.url": "URL",
|
||||
"label.urls": "URLs",
|
||||
"label.update": "تحديث",
|
||||
"label.url": "الرابط",
|
||||
"label.urls": "الروابط",
|
||||
"label.user": "المستخدم",
|
||||
"label.user-property": "User Property",
|
||||
"label.user-property": "سمات المستخدم",
|
||||
"label.username": "اسم المستخدم",
|
||||
"label.users": "المستخدمين",
|
||||
"label.utm": "UTM",
|
||||
"label.utm-description": "Track your campaigns through UTM parameters.",
|
||||
"label.utm-description": "تابع حملاتك التسويقية باستخدام معلمات UTM.",
|
||||
"label.value": "القيمة",
|
||||
"label.view": "عرض",
|
||||
"label.view-details": "عرض التفاصيل",
|
||||
"label.view-only": "عرض فقط",
|
||||
"label.views": "المشاهدات",
|
||||
"label.views-per-visit": "Views per visit",
|
||||
"label.views-per-visit": "مشاهدات لكل زيارة",
|
||||
"label.visit-duration": "متوسط وقت الزيارة",
|
||||
"label.visitors": "الزوار",
|
||||
"label.visits": "Visits",
|
||||
"label.visits": "الزيارات",
|
||||
"label.website": "الموقع",
|
||||
"label.website-id": "معرّف الموقع",
|
||||
"label.websites": "المواقع",
|
||||
|
|
@ -237,7 +241,7 @@
|
|||
"label.yesterday": "الأمس",
|
||||
"message.action-confirmation": "اكتب {confirmation} في المربع أدناه للتأكيد.",
|
||||
"message.active-users": "{x} حاليا {x, plural, one {زائر واحد} other {زوار}}",
|
||||
"message.collected-data": "Collected data",
|
||||
"message.collected-data": "البيانات المجمعة",
|
||||
"message.confirm-delete": "هل أنت متأكد من حذف {target}?",
|
||||
"message.confirm-leave": "هل أنت متأكد من مغادرة {target}?",
|
||||
"message.confirm-remove": "هل انت متأكد من حذف {target}?",
|
||||
|
|
@ -261,9 +265,9 @@
|
|||
"message.no-websites-configured": "لم تقم بإعداد اي موقع.",
|
||||
"message.page-not-found": "الصفحة غير موجودة.",
|
||||
"message.reset-website": "لإعادة ضبط موقع الويب هذا، اكتب {confirmation} في المربع أدناه للتأكيد.",
|
||||
"message.reset-website-warning": "سيتم اعادة تعيين كافة الإحصائيات لهذا الموقع، لكن لن يتم تعيير كود التتبع",
|
||||
"message.reset-website-warning": "سيتم اعادة تعيين كافة الإحصائيات لهذا الموقع، لكن لن يتم تغيير كود التتبع",
|
||||
"message.saved": "تم الحفظ بنجاح.",
|
||||
"message.share-url": "هذا الرابط الذي تم مشاركته بشكل عام لـ {target}.",
|
||||
"message.share-url": "إحصائيات موقعك متاحة للجميع على الرابط التالي:",
|
||||
"message.team-already-member": "أنت عضو في الفريق",
|
||||
"message.team-not-found": "لم يتم العثور على الفريق",
|
||||
"message.team-websites-info": "يمكن مشاهدة الموقع من اي عضو في الفريق.",
|
||||
|
|
|
|||
|
|
@ -124,7 +124,9 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
|
|||
if (!global[MAXMIND]) {
|
||||
const dir = path.join(process.cwd(), 'geo');
|
||||
|
||||
global[MAXMIND] = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
|
||||
global[MAXMIND] = await maxmind.open(
|
||||
process.env.GEOLITE_DB_PATH || path.resolve(dir, 'GeoLite2-City.mmdb'),
|
||||
);
|
||||
}
|
||||
|
||||
const result = global[MAXMIND].get(ip);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import kafka from '@/lib/kafka';
|
|||
import prisma from '@/lib/prisma';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
import { saveEventData } from './saveEventData';
|
||||
import { saveRevenue } from './saveRevenue';
|
||||
|
||||
export interface SaveEventArgs {
|
||||
websiteId: string;
|
||||
|
|
@ -130,6 +131,20 @@ async function relationalQuery({
|
|||
eventData,
|
||||
createdAt,
|
||||
});
|
||||
|
||||
const { revenue, currency } = eventData;
|
||||
|
||||
if (revenue > 0 && currency) {
|
||||
await saveRevenue({
|
||||
websiteId,
|
||||
sessionId,
|
||||
eventId: websiteEventId,
|
||||
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
|
||||
currency,
|
||||
revenue,
|
||||
createdAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
36
src/queries/sql/events/saveRevenue.ts
Normal file
36
src/queries/sql/events/saveRevenue.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { uuid } from '@/lib/crypto';
|
||||
import { PRISMA, runQuery } from '@/lib/db';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
export interface SaveRevenueArgs {
|
||||
websiteId: string;
|
||||
sessionId: string;
|
||||
eventId: string;
|
||||
eventName: string;
|
||||
currency: string;
|
||||
revenue: number;
|
||||
createdAt: Date;
|
||||
}
|
||||
|
||||
export async function saveRevenue(data: SaveRevenueArgs) {
|
||||
return runQuery({
|
||||
[PRISMA]: () => relationalQuery(data),
|
||||
});
|
||||
}
|
||||
|
||||
async function relationalQuery(data: SaveRevenueArgs) {
|
||||
const { websiteId, sessionId, eventId, eventName, currency, revenue, createdAt } = data;
|
||||
|
||||
await prisma.client.revenue.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
websiteId,
|
||||
sessionId,
|
||||
eventId,
|
||||
eventName,
|
||||
currency,
|
||||
revenue,
|
||||
createdAt,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -78,26 +78,16 @@ async function relationalQuery(
|
|||
group by 1),`;
|
||||
|
||||
const revenueEventQuery = `WITH events AS (
|
||||
select
|
||||
we.session_id,
|
||||
max(ed.created_at) max_dt,
|
||||
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) value
|
||||
from event_data ed
|
||||
join website_event we
|
||||
on we.event_id = ed.website_event_id
|
||||
and we.website_id = ed.website_id
|
||||
join (select website_event_id
|
||||
from event_data
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and data_key ${like} '%currency%'
|
||||
and string_value = {{currency}}) currency
|
||||
on currency.website_event_id = ed.website_event_id
|
||||
where ed.website_id = {{websiteId::uuid}}
|
||||
and ed.created_at between {{startDate}} and {{endDate}}
|
||||
and ${column} = {{conversionStep}}
|
||||
and ed.data_key ${like} '%revenue%'
|
||||
group by 1),`;
|
||||
select
|
||||
session_id,
|
||||
max(created_at) max_dt,
|
||||
sum(revenue) value
|
||||
from revenue
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and ${column} = {{conversionStep}}
|
||||
and currency ${like} {{currency}}
|
||||
group by 1),`;
|
||||
|
||||
function getModelQuery(model: string) {
|
||||
return model === 'firstClick'
|
||||
|
|
@ -311,21 +301,14 @@ async function clickhouseQuery(
|
|||
|
||||
const revenueEventQuery = `WITH events AS (
|
||||
select
|
||||
ed.session_id,
|
||||
max(ed.created_at) max_dt,
|
||||
sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as value
|
||||
from event_data ed
|
||||
join (select event_id
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'currency') > 0
|
||||
and string_value = {currency:String}) c
|
||||
on c.event_id = ed.event_id
|
||||
session_id,
|
||||
max(created_at) max_dt,
|
||||
sum(revenue) as value
|
||||
from website_revenue
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and ${column} = {conversionStep:String}
|
||||
and positionCaseInsensitive(ed.data_key, 'revenue') > 0
|
||||
and ${column} = {conversionStep:String}
|
||||
and currency = {currency:String}
|
||||
group by 1),`;
|
||||
|
||||
function getModelQuery(model: string) {
|
||||
|
|
|
|||
|
|
@ -48,22 +48,13 @@ async function relationalQuery(
|
|||
const chartRes = await rawQuery(
|
||||
`
|
||||
select
|
||||
we.event_name x,
|
||||
${getDateSQL('ed.created_at', unit, timezone)} t,
|
||||
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) y
|
||||
from event_data ed
|
||||
join website_event we
|
||||
on we.event_id = ed.website_event_id
|
||||
join (select website_event_id
|
||||
from event_data
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and data_key ${like} '%currency%'
|
||||
and string_value = {{currency}}) currency
|
||||
on currency.website_event_id = ed.website_event_id
|
||||
where ed.website_id = {{websiteId::uuid}}
|
||||
and ed.created_at between {{startDate}} and {{endDate}}
|
||||
and ed.data_key ${like} '%revenue%'
|
||||
event_name x,
|
||||
${getDateSQL('created_at', unit, timezone)} t,
|
||||
sum(revenue) y
|
||||
from revenue
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and currency ${like} {{currency}}
|
||||
group by x, t
|
||||
order by t
|
||||
`,
|
||||
|
|
@ -74,22 +65,13 @@ async function relationalQuery(
|
|||
`
|
||||
select
|
||||
s.country as name,
|
||||
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) value
|
||||
from event_data ed
|
||||
join website_event we
|
||||
on we.event_id = ed.website_event_id
|
||||
sum(r.revenue) value
|
||||
from revenue r
|
||||
join session s
|
||||
on s.session_id = we.session_id
|
||||
join (select website_event_id
|
||||
from event_data
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and data_key ${like} '%currency%'
|
||||
and string_value = {{currency}}) currency
|
||||
on currency.website_event_id = ed.website_event_id
|
||||
where ed.website_id = {{websiteId::uuid}}
|
||||
and ed.created_at between {{startDate}} and {{endDate}}
|
||||
and ed.data_key ${like} '%revenue%'
|
||||
on s.session_id = r.session_id
|
||||
where r.website_id = {{websiteId::uuid}}
|
||||
and r.created_at between {{startDate}} and {{endDate}}
|
||||
and r.currency ${like} {{currency}}
|
||||
group by s.country
|
||||
`,
|
||||
{ websiteId, startDate, endDate, currency },
|
||||
|
|
@ -98,22 +80,13 @@ async function relationalQuery(
|
|||
const totalRes = await rawQuery(
|
||||
`
|
||||
select
|
||||
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,
|
||||
sum(revenue) as sum,
|
||||
count(distinct event_id) as count,
|
||||
count(distinct session_id) as unique_count
|
||||
from event_data ed
|
||||
join website_event we
|
||||
on we.event_id = ed.website_event_id
|
||||
join (select website_event_id
|
||||
from event_data
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and data_key ${like} '%currency%'
|
||||
and string_value = {{currency}}) currency
|
||||
on currency.website_event_id = ed.website_event_id
|
||||
where ed.website_id = {{websiteId::uuid}}
|
||||
and ed.created_at between {{startDate}} and {{endDate}}
|
||||
and ed.data_key ${like} '%revenue%'
|
||||
from revenue r
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and currency ${like} {{currency}}
|
||||
`,
|
||||
{ websiteId, startDate, endDate, currency },
|
||||
).then(result => result?.[0]);
|
||||
|
|
@ -121,24 +94,15 @@ async function relationalQuery(
|
|||
const tableRes = await rawQuery(
|
||||
`
|
||||
select
|
||||
c.currency,
|
||||
sum(coalesce(cast(number_value as decimal(10,2)), cast(string_value as decimal(10,2)))) as sum,
|
||||
count(distinct ed.website_event_id) as count,
|
||||
count(distinct we.session_id) as unique_count
|
||||
from event_data ed
|
||||
join website_event we
|
||||
on we.event_id = ed.website_event_id
|
||||
join (select website_event_id, string_value as currency
|
||||
from event_data
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
and data_key ${like} '%currency%') c
|
||||
on c.website_event_id = ed.website_event_id
|
||||
where ed.website_id = {{websiteId::uuid}}
|
||||
and ed.created_at between {{startDate}} and {{endDate}}
|
||||
and ed.data_key ${like} '%revenue%'
|
||||
group by c.currency
|
||||
order by sum desc;
|
||||
currency,
|
||||
sum(revenue) as sum,
|
||||
count(distinct event_id) as count,
|
||||
count(distinct session_id) as unique_count
|
||||
from revenue r
|
||||
where website_id = {{websiteId::uuid}}
|
||||
and created_at between {{startDate}} and {{endDate}}
|
||||
group by currency
|
||||
order by sum desc
|
||||
`,
|
||||
{ websiteId, startDate, endDate, unit, timezone, currency },
|
||||
);
|
||||
|
|
@ -180,18 +144,11 @@ async function clickhouseQuery(
|
|||
select
|
||||
event_name x,
|
||||
${getDateSQL('created_at', unit, timezone)} t,
|
||||
sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) y
|
||||
from event_data
|
||||
join (select event_id
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'currency') > 0
|
||||
and string_value = {currency:String}) currency
|
||||
on currency.event_id = event_data.event_id
|
||||
sum(revenue) y
|
||||
from website_revenue
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'revenue') > 0
|
||||
and currency = {currency:String}
|
||||
group by x, t
|
||||
order by t
|
||||
`,
|
||||
|
|
@ -207,23 +164,16 @@ async function clickhouseQuery(
|
|||
`
|
||||
select
|
||||
s.country as name,
|
||||
sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as value
|
||||
from event_data ed
|
||||
join (select event_id
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'currency') > 0
|
||||
and string_value = {currency:String}) c
|
||||
on c.event_id = ed.event_id
|
||||
sum(w.revenue) as value
|
||||
from website_revenue w
|
||||
join (select distinct website_id, session_id, country
|
||||
from website_event_stats_hourly
|
||||
where website_id = {websiteId:UUID}) s
|
||||
on ed.website_id = s.website_id
|
||||
and ed.session_id = s.session_id
|
||||
where ed.website_id = {websiteId:UUID}
|
||||
and ed.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(ed.data_key, 'revenue') > 0
|
||||
on w.website_id = s.website_id
|
||||
and w.session_id = s.session_id
|
||||
where w.website_id = {websiteId:UUID}
|
||||
and w.created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and w.currency = {currency:String}
|
||||
group by s.country
|
||||
`,
|
||||
{ websiteId, startDate, endDate, currency },
|
||||
|
|
@ -237,20 +187,13 @@ async function clickhouseQuery(
|
|||
}>(
|
||||
`
|
||||
select
|
||||
sum(coalesce(toDecimal64(number_value, 2), toDecimal64(string_value, 2))) as sum,
|
||||
sum(revenue) as sum,
|
||||
uniqExact(event_id) as count,
|
||||
uniqExact(session_id) as unique_count
|
||||
from event_data
|
||||
join (select event_id
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'currency') > 0
|
||||
and string_value = {currency:String}) currency
|
||||
on currency.event_id = event_data.event_id
|
||||
from website_revenue
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'revenue') > 0
|
||||
and currency = {currency:String}
|
||||
`,
|
||||
{ websiteId, startDate, endDate, currency },
|
||||
).then(result => result?.[0]);
|
||||
|
|
@ -266,22 +209,15 @@ async function clickhouseQuery(
|
|||
>(
|
||||
`
|
||||
select
|
||||
c.currency,
|
||||
sum(coalesce(toDecimal64(ed.number_value, 2), toDecimal64(ed.string_value, 2))) as sum,
|
||||
uniqExact(ed.event_id) as count,
|
||||
uniqExact(ed.session_id) as unique_count
|
||||
from event_data ed
|
||||
join (select event_id, string_value as currency
|
||||
from event_data
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'currency') > 0) c
|
||||
on c.event_id = ed.event_id
|
||||
currency,
|
||||
sum(revenue) as sum,
|
||||
uniqExact(event_id) as count,
|
||||
uniqExact(session_id) as unique_count
|
||||
from website_revenue
|
||||
where website_id = {websiteId:UUID}
|
||||
and created_at between {startDate:DateTime64} and {endDate:DateTime64}
|
||||
and positionCaseInsensitive(data_key, 'revenue') > 0
|
||||
group by c.currency
|
||||
order by sum desc;
|
||||
group by currency
|
||||
order by sum desc
|
||||
`,
|
||||
{ websiteId, startDate, endDate, unit, timezone, currency },
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue