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

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,16 @@
1
+ ## [@adobe/spacecat-shared-athena-client-v1.9.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-athena-client-v1.9.2...@adobe/spacecat-shared-athena-client-v1.9.3) (2026-02-25)
2
+
3
+ ### Bug Fixes
4
+
5
+ * temporal series month/week wrap-around and add year to query pipeline ([#1376](https://github.com/adobe/spacecat-shared/issues/1376)) ([b15cfd7](https://github.com/adobe/spacecat-shared/commit/b15cfd705809612c4ad69bbdc09d87c06687dcb6))
6
+
7
+ # [@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)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * added function getTrafficTypeAnalysisTemplate to athena client ([#1266](https://github.com/adobe/spacecat-shared/issues/1266)) ([1103cbb](https://github.com/adobe/spacecat-shared/commit/1103cbbc7893fc209d4dc3e07feb64372d8e77e8))
13
+
1
14
  # [@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
15
 
3
16
 
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.3",
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';
@@ -102,9 +102,9 @@ export function getTrafficAnalysisQueryPlaceholdersFilled({
102
102
  }
103
103
 
104
104
  if (numTemporalSeries > 1 && week && week > 0) {
105
- dimensions.push('week');
105
+ dimensions.push('year', 'week');
106
106
  } else if (numTemporalSeries > 1 && month && month > 0) {
107
- dimensions.push('month');
107
+ dimensions.push('year', 'month');
108
108
  }
109
109
  const dimensionColumns = dimensions.join(', ');
110
110
  const dimensionColumnsPrefixed = dimensions.map((col) => `a.${col}`).join(', ');
@@ -179,6 +179,7 @@ WITH min_totals AS (
179
179
  ),
180
180
  raw AS (
181
181
  SELECT
182
+ year,
182
183
  week,
183
184
  month,
184
185
  path,
@@ -242,3 +243,104 @@ ORDER BY traffic_loss DESC
242
243
  ${limit ? `LIMIT ${limit}` : ''}
243
244
  `.trim();
244
245
  }
246
+
247
+ /**
248
+ * Generates the top 3 pages with traffic lost SQL query with consent and referrer parameters.
249
+ * @param {Object} params - Template parameters
250
+ * @param {string} params.siteId - Site ID
251
+ * @param {string} params.tableName - Table name
252
+ * @param {string} params.temporalCondition - Temporal condition
253
+ * @param {string} params.dimensionColumns - Dimension columns
254
+ * @param {string} params.groupBy - Group by clause
255
+ * @param {string} params.dimensionColumnsPrefixed - Prefixed dimension columns
256
+ * @param {number} params.pageViewThreshold - Minimum total pageviews for path to include
257
+ * @param {number} params.limit - Limit the number of results
258
+ * @returns {string} The SQL query string
259
+ */
260
+ export function getTrafficTypeAnalysisTemplate({
261
+ siteId,
262
+ tableName,
263
+ temporalCondition,
264
+ dimensionColumns,
265
+ groupBy,
266
+ dimensionColumnsPrefixed,
267
+ pageViewThreshold,
268
+ limit,
269
+ }) {
270
+ return `
271
+ WITH min_totals AS (
272
+ SELECT
273
+ path AS min_key,
274
+ CAST(SUM(pageviews) AS BIGINT) AS total_pageviews
275
+ FROM ${tableName}
276
+ WHERE siteid = '${siteId}'
277
+ AND (${temporalCondition})
278
+ GROUP BY path
279
+ HAVING SUM(pageviews) >= ${pageViewThreshold}
280
+ ),
281
+ raw AS (
282
+ SELECT
283
+ year,
284
+ week,
285
+ month,
286
+ path,
287
+ trf_type,
288
+ trf_channel,
289
+ trf_platform,
290
+ device,
291
+ utm_source,
292
+ utm_medium,
293
+ utm_campaign,
294
+ referrer,
295
+ consent,
296
+ notfound,
297
+ pageviews,
298
+ clicked,
299
+ engaged,
300
+ latest_scroll,
301
+ CASE WHEN latest_scroll >= 10000 THEN 1 ELSE 0 END AS engaged_scroll,
302
+ lcp,
303
+ cls,
304
+ inp
305
+ FROM ${tableName} m
306
+ JOIN min_totals t ON m.path = t.min_key
307
+ WHERE m.siteid = '${siteId}'
308
+ AND (${temporalCondition})
309
+ ),
310
+ agg AS (
311
+ SELECT
312
+ ${dimensionColumns},
313
+ COUNT(*) AS row_count,
314
+ CAST(SUM(pageviews) AS BIGINT) AS pageviews,
315
+ CAST(SUM(clicked) AS BIGINT) AS clicks,
316
+ CAST(SUM(engaged) AS BIGINT) AS engagements,
317
+ CAST(SUM(engaged_scroll) AS BIGINT) AS engaged_scroll,
318
+ approx_percentile(latest_scroll, 0.70) AS p70_scroll,
319
+ approx_percentile(lcp, 0.70) AS p70_lcp,
320
+ approx_percentile(cls, 0.70) AS p70_cls,
321
+ approx_percentile(inp, 0.70) AS p70_inp
322
+ FROM raw
323
+ GROUP BY ${groupBy}
324
+ ),
325
+ grand_total AS (
326
+ SELECT CAST(SUM(pageviews) AS BIGINT) AS total_pv FROM agg
327
+ )
328
+ SELECT
329
+ ${dimensionColumnsPrefixed},
330
+ CAST(a.pageviews AS DOUBLE) * (1 - CAST(a.engagements AS DOUBLE) / NULLIF(a.row_count, 0)) AS traffic_loss,
331
+ 1 - CAST(a.engagements AS DOUBLE) / NULLIF(a.row_count, 0) AS bounce_rate,
332
+ a.pageviews,
333
+ CAST(a.pageviews AS DOUBLE) / NULLIF(t.total_pv, 0) AS pct_pageviews,
334
+ CAST(a.clicks AS DOUBLE) / NULLIF(a.row_count, 0) AS click_rate,
335
+ CAST(a.engagements AS DOUBLE) / NULLIF(a.row_count, 0) AS engagement_rate,
336
+ CAST(a.engaged_scroll AS DOUBLE) / NULLIF(a.row_count, 0) AS engaged_scroll_rate,
337
+ a.p70_scroll,
338
+ a.p70_lcp,
339
+ a.p70_cls,
340
+ a.p70_inp
341
+ FROM agg a
342
+ CROSS JOIN grand_total t
343
+ ORDER BY traffic_loss DESC
344
+ ${limit ? `LIMIT ${limit}` : ''}
345
+ `.trim();
346
+ }
@@ -48,6 +48,7 @@ WITH min_totals AS (
48
48
  ),
49
49
  raw AS (
50
50
  SELECT
51
+ year,
51
52
  week,
52
53
  month,
53
54
  path,
@@ -18,6 +18,7 @@ export const TrafficDataResponseDto = {
18
18
  * Converts a traffic data object into a JSON object.
19
19
  * @param {object} data - traffic data object.
20
20
  * @returns {{
21
+ * year: number,
21
22
  * type: string,
22
23
  * channel: string,
23
24
  * platform: string,
@@ -33,6 +34,7 @@ export const TrafficDataResponseDto = {
33
34
  * }} JSON object.
34
35
  */
35
36
  toJSON: (data) => ({
37
+ year: data.year,
36
38
  week: data.week,
37
39
  month: data.month,
38
40
  type: data.trf_type,