mirror of
https://github.com/anotherhadi/default-creds.git
synced 2026-04-02 03:22:10 +02:00
Edit analytics
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -76,7 +76,16 @@
|
||||
totalPages = data.pagination.totalPages;
|
||||
totalResults = data.pagination.totalResults;
|
||||
if (typeof window !== "undefined" && (window as any).umami) {
|
||||
(window as any).umami.track("search", { query: lastQuery, results: totalResults });
|
||||
(window as any).umami.track("search", {
|
||||
query: lastQuery,
|
||||
results: totalResults,
|
||||
hasResults: totalResults > 0,
|
||||
});
|
||||
if (totalResults === 0) {
|
||||
(window as any).umami.track("search_no_results", {
|
||||
query: lastQuery,
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Search error:", e);
|
||||
|
||||
@@ -97,8 +97,8 @@ export const GET: APIRoute = async ({ url, request }) => {
|
||||
Math.max(1, parseInt(url.searchParams.get("size") || "10")),
|
||||
);
|
||||
|
||||
const dnt = request.headers.get("DNT") === "1"
|
||||
|| request.headers.get("Sec-GPC") === "1";
|
||||
const dnt = request.headers.get("DNT") === "1"
|
||||
|| request.headers.get("Sec-GPC") === "1";
|
||||
|
||||
const allEntries = getAllData();
|
||||
|
||||
@@ -112,7 +112,7 @@ export const GET: APIRoute = async ({ url, request }) => {
|
||||
|
||||
// Server-side tracking for search queries, respecting DNT/GPC
|
||||
if (query && dnt) {
|
||||
await trackSearchServerSide(query, filtered.length > 0);
|
||||
await trackSearchServerSide(query, filtered.length);
|
||||
}
|
||||
|
||||
const totalResults = filtered.length;
|
||||
@@ -141,7 +141,7 @@ export const GET: APIRoute = async ({ url, request }) => {
|
||||
);
|
||||
};
|
||||
|
||||
async function trackSearchServerSide(query: string, hasResults: boolean) {
|
||||
async function trackSearchServerSide(query: string, results: number) {
|
||||
const umamiUrl = process.env.UMAMI_URL;
|
||||
const umamiId = process.env.UMAMI_WEBSITE_ID;
|
||||
|
||||
@@ -163,12 +163,35 @@ async function trackSearchServerSide(query: string, hasResults: boolean) {
|
||||
name: "search",
|
||||
data: {
|
||||
query,
|
||||
hasResults,
|
||||
results,
|
||||
hasResults: results > 0,
|
||||
source: "server",
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
if (results === 0) {
|
||||
await fetch(`${umamiUrl}/api/send`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": "Mozilla/5.0 (compatible; default-creds-server/1.0)",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: "event",
|
||||
payload: {
|
||||
website: umamiId,
|
||||
hostname: "default-creds.hadi.diy",
|
||||
url: "/api/search",
|
||||
name: "search_no_results",
|
||||
data: {
|
||||
query,
|
||||
source: "server",
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Umami server-side tracking failed:", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user