@adobe/spacecat-shared-athena-client 1.3.7 → 1.4.0
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 +14 -0
- package/package.json +2 -2
- package/src/index.js +2 -0
- package/src/pta2/queries.js +76 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-athena-client-v1.4.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-athena-client-v1.3.8...@adobe/spacecat-shared-athena-client-v1.4.0) (2025-11-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* PTA2 Summary query ([#1102](https://github.com/adobe/spacecat-shared/issues/1102)) ([06e902a](https://github.com/adobe/spacecat-shared/commit/06e902a5487c2fc2e79a3f15d7acf1072900fab4))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-athena-client-v1.3.8](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-athena-client-v1.3.7...@adobe/spacecat-shared-athena-client-v1.3.8) (2025-11-01)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update external fixes ([#1081](https://github.com/adobe/spacecat-shared/issues/1081)) ([4476494](https://github.com/adobe/spacecat-shared/commit/44764944350f9344d0ca5e2af5a2161cc7470899))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-athena-client-v1.3.7](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-athena-client-v1.3.6...@adobe/spacecat-shared-athena-client-v1.3.7) (2025-10-28)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-athena-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - AWS Athena Client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@aws-sdk/client-athena": "3.
|
|
38
|
+
"@aws-sdk/client-athena": "3.922.0",
|
|
39
39
|
"@adobe/spacecat-shared-utils": "1.66.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
package/src/index.js
CHANGED
|
@@ -264,3 +264,5 @@ export {
|
|
|
264
264
|
} from './traffic-analysis/queries.js';
|
|
265
265
|
export { TrafficDataResponseDto } from './traffic-analysis/traffic-data-base-response.js';
|
|
266
266
|
export { TrafficDataWithCWVDto } from './traffic-analysis/traffic-data-with-cwv.js';
|
|
267
|
+
|
|
268
|
+
export { getPTASummaryQuery, PTASummaryResponseDto } from './pta2/queries.js';
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { getTemporalCondition } from '@adobe/spacecat-shared-utils';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Generates the PTA summary query template using template literals.
|
|
17
|
+
* @param {Object} params - Template parameters
|
|
18
|
+
* @param {string} params.siteId - Site ID
|
|
19
|
+
* @param {string} params.tableName - Table name
|
|
20
|
+
* @param {string} params.temporalCondition - Temporal condition
|
|
21
|
+
* @param {number} params.week - Week number (either week or month must be provided)
|
|
22
|
+
* @param {number} params.month - Month number (either week or month year must be provided)
|
|
23
|
+
* @param {number} params.year - Year number
|
|
24
|
+
* @returns {string} The SQL query string
|
|
25
|
+
*/
|
|
26
|
+
export function getPTASummaryQuery({
|
|
27
|
+
siteId,
|
|
28
|
+
tableName,
|
|
29
|
+
week,
|
|
30
|
+
month,
|
|
31
|
+
year,
|
|
32
|
+
}) {
|
|
33
|
+
if (!siteId || !tableName) {
|
|
34
|
+
throw new Error('Missing required parameters: siteId, or tableName');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ((!week && !month) || !year) {
|
|
38
|
+
throw new Error('Missing required parameters: week, month or year');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const temporalCondition = getTemporalCondition({ week, month, year });
|
|
42
|
+
|
|
43
|
+
return `
|
|
44
|
+
SELECT
|
|
45
|
+
CAST(SUM(pageviews) AS BIGINT) AS total_pageviews,
|
|
46
|
+
CAST(SUM(clicked) AS BIGINT) AS total_clicks,
|
|
47
|
+
CAST(SUM(engaged) AS BIGINT) AS total_engaged,
|
|
48
|
+
COUNT(*) AS total_rows,
|
|
49
|
+
CAST(SUM(clicked) AS DOUBLE) / NULLIF(COUNT(*), 0) AS click_rate,
|
|
50
|
+
CAST(SUM(engaged) AS DOUBLE) / NULLIF(COUNT(*), 0) AS engagement_rate,
|
|
51
|
+
1 - CAST(SUM(engaged) AS DOUBLE) / NULLIF(COUNT(*), 0) AS bounce_rate
|
|
52
|
+
FROM ${tableName}
|
|
53
|
+
WHERE siteid = '${siteId}'
|
|
54
|
+
AND (${temporalCondition})
|
|
55
|
+
AND trf_type = 'paid'
|
|
56
|
+
`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const PTASummaryResponseDto = {
|
|
60
|
+
/**
|
|
61
|
+
* Converts a traffic data object into a JSON object.
|
|
62
|
+
* @param {object} data - traffic data object.
|
|
63
|
+
* @returns {{
|
|
64
|
+
* pageviews: number,
|
|
65
|
+
* click_rate: number,
|
|
66
|
+
* engagement_rate: number,
|
|
67
|
+
* bounce_rate: number
|
|
68
|
+
* }} JSON object.
|
|
69
|
+
*/
|
|
70
|
+
toJSON: (data) => ({
|
|
71
|
+
pageviews: data.total_pageviews,
|
|
72
|
+
click_rate: data.click_rate,
|
|
73
|
+
engagement_rate: data.engagement_rate,
|
|
74
|
+
bounce_rate: data.bounce_rate,
|
|
75
|
+
}),
|
|
76
|
+
};
|