mirror of
https://github.com/anotherhadi/default-creds.git
synced 2026-04-02 11:32:11 +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;
|
totalPages = data.pagination.totalPages;
|
||||||
totalResults = data.pagination.totalResults;
|
totalResults = data.pagination.totalResults;
|
||||||
if (typeof window !== "undefined" && (window as any).umami) {
|
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) {
|
} catch (e) {
|
||||||
console.error("Search error:", 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")),
|
Math.max(1, parseInt(url.searchParams.get("size") || "10")),
|
||||||
);
|
);
|
||||||
|
|
||||||
const dnt = request.headers.get("DNT") === "1"
|
const dnt = request.headers.get("DNT") === "1"
|
||||||
|| request.headers.get("Sec-GPC") === "1";
|
|| request.headers.get("Sec-GPC") === "1";
|
||||||
|
|
||||||
const allEntries = getAllData();
|
const allEntries = getAllData();
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ export const GET: APIRoute = async ({ url, request }) => {
|
|||||||
|
|
||||||
// Server-side tracking for search queries, respecting DNT/GPC
|
// Server-side tracking for search queries, respecting DNT/GPC
|
||||||
if (query && dnt) {
|
if (query && dnt) {
|
||||||
await trackSearchServerSide(query, filtered.length > 0);
|
await trackSearchServerSide(query, filtered.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
const totalResults = 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 umamiUrl = process.env.UMAMI_URL;
|
||||||
const umamiId = process.env.UMAMI_WEBSITE_ID;
|
const umamiId = process.env.UMAMI_WEBSITE_ID;
|
||||||
|
|
||||||
@@ -163,12 +163,35 @@ async function trackSearchServerSide(query: string, hasResults: boolean) {
|
|||||||
name: "search",
|
name: "search",
|
||||||
data: {
|
data: {
|
||||||
query,
|
query,
|
||||||
hasResults,
|
results,
|
||||||
|
hasResults: results > 0,
|
||||||
source: "server",
|
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) {
|
} catch (e) {
|
||||||
console.error("Umami server-side tracking failed:", e);
|
console.error("Umami server-side tracking failed:", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user