Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/cdn-logs-report/sql/agentic-hits-for-urls.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT
url,
SUM(number_of_hits) AS number_of_hits
FROM {{databaseName}}.{{tableName}}
{{whereClause}}
AND url IN ({{urlList}})
GROUP BY url;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as there can be so many urls,
use limit 200 and orderby number_of_hits DESC here

Copy link
Contributor Author

@anuj-adobe anuj-adobe Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query is required to find the agentic traffic for URLs that are added over top 200 agentic URLs (by updating site config for prerender handler using "includedURLs"). The extra added URLs might not be present in top 200 URLs. I don't think limit 200 will help in this case and we need to scan all the URLs


32 changes: 32 additions & 0 deletions src/cdn-logs-report/utils/query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,40 @@ async function createTopUrlsQuery(options) {
});
}

/**
* Build an Athena query to fetch agentic hits for a specific set of URL paths.
* The passed urlPaths should be path-only (e.g., "/foo/bar"), matching the "url" field in logs.
*/
export async function createAgenticHitsForUrlsQuery(options) {
const {
periods, databaseName, tableName, site, urlPaths,
} = options;

const filters = site.getConfig().getLlmoCdnlogsFilter();
const siteFilters = buildSiteFilters(filters, site);
const lastWeek = periods.weeks[periods.weeks.length - 1];
const whereClause = buildWhereClause(
[buildDateFilter(lastWeek.startDate, lastWeek.endDate)],
siteFilters,
);

// Escape single quotes inside paths for SQL safety
const escapeSql = (s) => String(s).replace(/'/g, "''");
const urlList = urlPaths && urlPaths.length > 0
? urlPaths.map((p) => `'${escapeSql(p)}'`).join(', ')
: ''; // will produce empty IN() which returns no results

return loadSql('agentic-hits-for-urls', {
databaseName,
tableName,
whereClause,
urlList,
});
}

export const weeklyBreakdownQueries = {
createAgenticReportQuery,
createReferralReportQuery,
createTopUrlsQuery,
createAgenticHitsForUrlsQuery,
};
Loading