@adobe/spacecat-shared-athena-client 1.9.1 → 1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [@adobe/spacecat-shared-athena-client-v1.9.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-athena-client-v1.9.1...@adobe/spacecat-shared-athena-client-v1.9.2) (2026-01-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * added function getTrafficTypeAnalysisTemplate to athena client ([#1266](https://github.com/adobe/spacecat-shared/issues/1266)) ([1103cbb](https://github.com/adobe/spacecat-shared/commit/1103cbbc7893fc209d4dc3e07feb64372d8e77e8))
7
+
1
8
  # [@adobe/spacecat-shared-athena-client-v1.9.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-athena-client-v1.9.0...@adobe/spacecat-shared-athena-client-v1.9.1) (2025-12-08)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-athena-client",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "Shared modules of the Spacecat Services - AWS Athena Client",
5
5
  "type": "module",
6
6
  "engines": {
package/src/index.js CHANGED
@@ -262,6 +262,7 @@ export {
262
262
  buildPageTypeCase,
263
263
  getTrafficAnalysisQueryPlaceholdersFilled,
264
264
  getTop3PagesWithTrafficLostTemplate,
265
+ getTrafficTypeAnalysisTemplate,
265
266
  } from './traffic-analysis/queries.js';
266
267
  export { TrafficDataResponseDto } from './traffic-analysis/traffic-data-base-response.js';
267
268
  export { TrafficDataWithCWVDto } from './traffic-analysis/traffic-data-with-cwv.js';
@@ -242,3 +242,103 @@ ORDER BY traffic_loss DESC
242
242
  ${limit ? `LIMIT ${limit}` : ''}
243
243
  `.trim();
244
244
  }
245
+
246
+ /**
247
+ * Generates the top 3 pages with traffic lost SQL query with consent and referrer parameters.
248
+ * @param {Object} params - Template parameters
249
+ * @param {string} params.siteId - Site ID
250
+ * @param {string} params.tableName - Table name
251
+ * @param {string} params.temporalCondition - Temporal condition
252
+ * @param {string} params.dimensionColumns - Dimension columns
253
+ * @param {string} params.groupBy - Group by clause
254
+ * @param {string} params.dimensionColumnsPrefixed - Prefixed dimension columns
255
+ * @param {number} params.pageViewThreshold - Minimum total pageviews for path to include
256
+ * @param {number} params.limit - Limit the number of results
257
+ * @returns {string} The SQL query string
258
+ */
259
+ export function getTrafficTypeAnalysisTemplate({
260
+ siteId,
261
+ tableName,
262
+ temporalCondition,
263
+ dimensionColumns,
264
+ groupBy,
265
+ dimensionColumnsPrefixed,
266
+ pageViewThreshold,
267
+ limit,
268
+ }) {
269
+ return `
270
+ WITH min_totals AS (
271
+ SELECT
272
+ path AS min_key,
273
+ CAST(SUM(pageviews) AS BIGINT) AS total_pageviews
274
+ FROM ${tableName}
275
+ WHERE siteid = '${siteId}'
276
+ AND (${temporalCondition})
277
+ GROUP BY path
278
+ HAVING SUM(pageviews) >= ${pageViewThreshold}
279
+ ),
280
+ raw AS (
281
+ SELECT
282
+ week,
283
+ month,
284
+ path,
285
+ trf_type,
286
+ trf_channel,
287
+ trf_platform,
288
+ device,
289
+ utm_source,
290
+ utm_medium,
291
+ utm_campaign,
292
+ referrer,
293
+ consent,
294
+ notfound,
295
+ pageviews,
296
+ clicked,
297
+ engaged,
298
+ latest_scroll,
299
+ CASE WHEN latest_scroll >= 10000 THEN 1 ELSE 0 END AS engaged_scroll,
300
+ lcp,
301
+ cls,
302
+ inp
303
+ FROM ${tableName} m
304
+ JOIN min_totals t ON m.path = t.min_key
305
+ WHERE m.siteid = '${siteId}'
306
+ AND (${temporalCondition})
307
+ ),
308
+ agg AS (
309
+ SELECT
310
+ ${dimensionColumns},
311
+ COUNT(*) AS row_count,
312
+ CAST(SUM(pageviews) AS BIGINT) AS pageviews,
313
+ CAST(SUM(clicked) AS BIGINT) AS clicks,
314
+ CAST(SUM(engaged) AS BIGINT) AS engagements,
315
+ CAST(SUM(engaged_scroll) AS BIGINT) AS engaged_scroll,
316
+ approx_percentile(latest_scroll, 0.70) AS p70_scroll,
317
+ approx_percentile(lcp, 0.70) AS p70_lcp,
318
+ approx_percentile(cls, 0.70) AS p70_cls,
319
+ approx_percentile(inp, 0.70) AS p70_inp
320
+ FROM raw
321
+ GROUP BY ${groupBy}
322
+ ),
323
+ grand_total AS (
324
+ SELECT CAST(SUM(pageviews) AS BIGINT) AS total_pv FROM agg
325
+ )
326
+ SELECT
327
+ ${dimensionColumnsPrefixed},
328
+ CAST(a.pageviews AS DOUBLE) * (1 - CAST(a.engagements AS DOUBLE) / NULLIF(a.row_count, 0)) AS traffic_loss,
329
+ 1 - CAST(a.engagements AS DOUBLE) / NULLIF(a.row_count, 0) AS bounce_rate,
330
+ a.pageviews,
331
+ CAST(a.pageviews AS DOUBLE) / NULLIF(t.total_pv, 0) AS pct_pageviews,
332
+ CAST(a.clicks AS DOUBLE) / NULLIF(a.row_count, 0) AS click_rate,
333
+ CAST(a.engagements AS DOUBLE) / NULLIF(a.row_count, 0) AS engagement_rate,
334
+ CAST(a.engaged_scroll AS DOUBLE) / NULLIF(a.row_count, 0) AS engaged_scroll_rate,
335
+ a.p70_scroll,
336
+ a.p70_lcp,
337
+ a.p70_cls,
338
+ a.p70_inp
339
+ FROM agg a
340
+ CROSS JOIN grand_total t
341
+ ORDER BY traffic_loss DESC
342
+ ${limit ? `LIMIT ${limit}` : ''}
343
+ `.trim();
344
+ }