add pagetitle to queries

This commit is contained in:
Francis Cao 2023-03-01 10:53:57 -08:00
parent 6c302a7325
commit 93650a2f66
9 changed files with 36 additions and 7 deletions

View File

@ -121,3 +121,6 @@ CREATE TABLE `team_website` (
INDEX `team_website_website_id_idx`(`website_id`),
PRIMARY KEY (`team_website_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- AddSystemUser
INSERT INTO "user" (user_id, username, role, password) VALUES ('41e2b680-648e-4b09-bcd7-3e2b10c06264' , 'admin', 'admin', '$2b$10$BUli0c.muyCW1ErNJc3jL.vFRFtFJWrT8/GcR4A.sUdCznaXiqFXa');

View File

@ -112,6 +112,7 @@ function getFilterQuery(filters = {}, params = {}) {
switch (key) {
case 'url':
case 'pageTitle':
case 'os':
case 'browser':
case 'device':
@ -155,6 +156,7 @@ function parseFilters(filters: any = {}, params: any = {}) {
url,
eventUrl,
referrer,
pageTitle,
os,
browser,
device,
@ -166,7 +168,7 @@ function parseFilters(filters: any = {}, params: any = {}) {
query,
} = filters;
const pageviewFilters = { domain, url, referrer, query };
const pageviewFilters = { domain, url, referrer, query, pageTitle };
const sessionFilters = { os, browser, device, country, subdivision1, subdivision2, city };
const eventFilters = { url: eventUrl, eventName };

View File

@ -133,6 +133,7 @@ function getFilterQuery(filters = {}, params = []): string {
switch (key) {
case 'url':
case 'os':
case 'pageTitle':
case 'browser':
case 'device':
case 'subdivision1':
@ -179,6 +180,7 @@ function parseFilters(
url,
eventUrl,
referrer,
pageTitle,
os,
browser,
device,
@ -190,7 +192,7 @@ function parseFilters(
query,
} = filters;
const pageviewFilters = { domain, url, referrer, query };
const pageviewFilters = { domain, url, referrer, query, pageTitle };
const sessionFilters = { os, browser, device, country, subdivision1, subdivision2, city };
const eventFilters = { url: eventUrl, eventName };

View File

@ -34,7 +34,7 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
const { type, payload } = getJsonBody(req);
const { referrer, eventName, eventData } = payload;
const { referrer, eventName, eventData, pageTitle } = payload;
let { url } = payload;
// Validate eventData is JSON
@ -98,12 +98,13 @@ export default async (req: NextApiRequestCollect, res: NextApiResponse) => {
}
if (type === 'pageview') {
await savePageView({ ...session, url, referrer });
await savePageView({ ...session, url, referrer, pageTitle });
} else if (type === 'event') {
await saveEvent({
...session,
url,
referrer,
pageTitle,
eventName,
eventData,
});

View File

@ -7,7 +7,7 @@ import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
import { getPageviewMetrics, getSessionMetrics, getWebsite } from 'queries';
const sessionColumns = ['browser', 'os', 'device', 'screen', 'country', 'language'];
const pageviewColumns = ['url', 'referrer', 'query'];
const pageviewColumns = ['url', 'referrer', 'query', 'pageTitle'];
function getTable(type) {
if (type === 'event') {
@ -42,6 +42,7 @@ export interface WebsiteMetricsRequestQuery {
endAt: number;
url: string;
referrer: string;
pageTitle: string;
os: string;
browser: string;
device: string;
@ -65,6 +66,7 @@ export default async (
endAt,
url,
referrer,
pageTitle,
os,
browser,
device,
@ -136,6 +138,7 @@ export default async (
domain,
url: type !== 'url' && table !== 'event' ? url : undefined,
referrer: type !== 'referrer' && table !== 'event' ? referrer : FILTER_IGNORED,
pageTitle: type !== 'pageTitle' && table !== 'event' ? pageTitle : undefined,
os: type !== 'os' ? os : undefined,
browser: type !== 'browser' ? browser : undefined,
device: type !== 'device' ? device : undefined,

View File

@ -17,6 +17,7 @@ export interface WebsitePageviewRequestQuery {
timezone: string;
url?: string;
referrer?: string;
pageTitle?: string;
os?: string;
browser?: string;
device?: string;
@ -41,6 +42,7 @@ export default async (
timezone,
url,
referrer,
pageTitle,
os,
browser,
device,
@ -72,6 +74,7 @@ export default async (
filters: {
url,
referrer,
pageTitle,
os,
browser,
device,
@ -89,6 +92,7 @@ export default async (
count: 'distinct website_event.',
filters: {
url,
pageTitle,
os,
browser,
device,

View File

@ -13,6 +13,7 @@ export interface WebsiteStatsRequestQuery {
endAt: number;
url: string;
referrer: string;
pageTitle: string;
os: string;
browser: string;
device: string;
@ -35,6 +36,7 @@ export default async (
endAt,
url,
referrer,
pageTitle,
os,
browser,
device,
@ -62,6 +64,7 @@ export default async (
filters: {
url,
referrer,
pageTitle,
os,
browser,
device,
@ -77,6 +80,7 @@ export default async (
filters: {
url,
referrer,
pageTitle,
os,
browser,
device,

View File

@ -10,6 +10,7 @@ export async function saveEvent(args: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
eventName?: string;
eventData?: any;
hostname?: string;
@ -34,10 +35,11 @@ async function relationalQuery(data: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
eventName?: string;
eventData?: any;
}) {
const { websiteId, id: sessionId, url, eventName, eventData, referrer } = data;
const { websiteId, id: sessionId, url, eventName, eventData, referrer, pageTitle } = data;
return prisma.client.websiteEvent.create({
data: {
@ -46,6 +48,7 @@ async function relationalQuery(data: {
sessionId,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
pageTitle: pageTitle,
eventType: EVENT_TYPE.customEvent,
eventName: eventName?.substring(0, EVENT_NAME_LENGTH),
eventData,
@ -58,6 +61,7 @@ async function clickhouseQuery(data) {
websiteId,
id: sessionId,
url,
pageTitle,
eventName,
eventData,
country,
@ -79,6 +83,7 @@ async function clickhouseQuery(data) {
subdivision2: subdivision2 ? subdivision2 : null,
city: city ? city : null,
url: url?.substring(0, URL_LENGTH),
page_title: pageTitle,
event_type: EVENT_TYPE.customEvent,
event_name: eventName?.substring(0, EVENT_NAME_LENGTH),
event_data: eventData ? JSON.stringify(eventData) : null,

View File

@ -10,6 +10,7 @@ export async function savePageView(args: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
hostname?: string;
browser?: string;
os?: string;
@ -32,8 +33,9 @@ async function relationalQuery(data: {
websiteId: string;
url: string;
referrer?: string;
pageTitle?: string;
}) {
const { websiteId, id: sessionId, url, referrer } = data;
const { websiteId, id: sessionId, url, referrer, pageTitle } = data;
return prisma.client.websiteEvent.create({
data: {
@ -42,6 +44,7 @@ async function relationalQuery(data: {
sessionId,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
pageTitle: pageTitle,
eventType: EVENT_TYPE.pageView,
},
});
@ -53,6 +56,7 @@ async function clickhouseQuery(data) {
id: sessionId,
url,
referrer,
pageTitle,
country,
subdivision1,
subdivision2,
@ -72,6 +76,7 @@ async function clickhouseQuery(data) {
city: city ? city : null,
url: url?.substring(0, URL_LENGTH),
referrer: referrer?.substring(0, URL_LENGTH),
page_title: pageTitle,
event_type: EVENT_TYPE.pageView,
created_at: getDateFormat(new Date()),
...args,