ga4-export-fixer 0.6.2-dev.2 → 0.6.2-dev.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/README.md CHANGED
@@ -457,7 +457,7 @@ This creates the table along with the default-enabled assertions, using the same
457
457
 
458
458
  | Assertion | Name | Enabled by default | Description |
459
459
  | --------- | ---- | ------------------ | ----------- |
460
- | `dailyQuality` | `{tableName}_daily_quality` | Yes | Compares session count, event count, and item revenue per day between the enhanced table and raw export. Detects missing days, count mismatches, and non-final data inflation |
460
+ | `dailyQuality` | `{tableName}_daily_quality` | Yes | Compares session count, event count, item revenue, and ecommerce purchase revenue per day between the enhanced table and raw export. Detects missing days, count mismatches, and non-final data inflation |
461
461
  | `itemRevenue` | `{tableName}_item_revenue` | No (opt-in) | Reconciles item_revenue at the (event_date, item_id) grain between the enhanced table and raw export |
462
462
 
463
463
  Assertions inherit the table's schema and tags from `dataformTableConfig`. Each assertion queries the last 5 days of data.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.6.2-dev.2",
3
+ "version": "0.6.2-dev.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -12,15 +12,17 @@ const ASSERTION_LOOKBACK_DAYS = 5;
12
12
  * Generates a SQL assertion query that validates daily data quality between the
13
13
  * enhanced events table and the raw GA4 export data.
14
14
  *
15
- * The query compares session count, event count, and total item_revenue
16
- * aggregated per (event_date, data_is_final) for the last 5 days.
17
- * Returns violating rows -- 0 rows means the assertion passes.
15
+ * The query compares session count, event count, total item_revenue, and total
16
+ * purchase_revenue aggregated per (event_date, data_is_final) for the last 5
17
+ * days. Returns violating rows -- 0 rows means the assertion passes.
18
18
  *
19
- * Five violation types are detected:
19
+ * Six violation types are detected:
20
20
  * - MISSING_DAY: Raw data has events but enhanced table has none for this day
21
21
  * - SESSION_COUNT_MISMATCH: Final data session count differs
22
22
  * - EVENT_COUNT_MISMATCH: Final data event count differs
23
- * - REVENUE_MISMATCH: Final data total item_revenue differs
23
+ * - ITEM_REVENUE_MISMATCH: Final data total item_revenue differs
24
+ * - PURCHASE_REVENUE_MISMATCH: Final data total ecommerce.purchase_revenue differs
25
+ * (raw side applies fixEcommerceStruct() to mirror the enhanced pipeline's fix)
24
26
  * - NON_FINAL_EXCESS_EVENTS: Non-final enhanced data has more events than raw
25
27
  *
26
28
  * @param {string} tableRef - Fully qualified reference to the enhanced table
@@ -46,7 +48,8 @@ const _generateDailyQualityAssertionSql = (tableRef, mergedConfig) => {
46
48
  data_is_final,
47
49
  count(distinct session_id) as session_count,
48
50
  count(*) as event_count,
49
- coalesce(sum((select sum(item.item_revenue) from unnest(items) as item)), 0) as total_item_revenue
51
+ coalesce(sum((select sum(item.item_revenue) from unnest(items) as item)), 0) as total_item_revenue,
52
+ coalesce(sum(ecommerce.purchase_revenue), 0) as total_purchase_revenue
50
53
  from
51
54
  ${tableRef}
52
55
  where
@@ -59,7 +62,8 @@ raw_daily as (
59
62
  ${dataIsFinalCondition} as data_is_final,
60
63
  count(distinct concat(user_pseudo_id, cast((select value.int_value from unnest(event_params) where key = 'ga_session_id') as string))) as session_count,
61
64
  count(*) as event_count,
62
- coalesce(sum((select sum(item.item_revenue) from unnest(items) as item)), 0) as total_item_revenue
65
+ coalesce(sum((select sum(item.item_revenue) from unnest(items) as item)), 0) as total_item_revenue,
66
+ coalesce(sum(${helpers.fixEcommerceStruct()}.purchase_revenue), 0) as total_purchase_revenue
63
67
  from
64
68
  ${dedupedRawSource}
65
69
  where
@@ -74,8 +78,10 @@ daily_comparison as (
74
78
  r.session_count as raw_sessions,
75
79
  e.event_count as enhanced_events,
76
80
  r.event_count as raw_events,
77
- round(e.total_item_revenue, 2) as enhanced_revenue,
78
- round(r.total_item_revenue, 2) as raw_revenue
81
+ round(e.total_item_revenue, 2) as enhanced_item_revenue,
82
+ round(r.total_item_revenue, 2) as raw_item_revenue,
83
+ round(e.total_purchase_revenue, 2) as enhanced_purchase_revenue,
84
+ round(r.total_purchase_revenue, 2) as raw_purchase_revenue
79
85
  from
80
86
  enhanced_daily e
81
87
  full outer join
@@ -88,8 +94,10 @@ select
88
94
  raw_sessions,
89
95
  enhanced_events,
90
96
  raw_events,
91
- enhanced_revenue,
92
- raw_revenue,
97
+ enhanced_item_revenue,
98
+ raw_item_revenue,
99
+ enhanced_purchase_revenue,
100
+ raw_purchase_revenue,
93
101
  violation_type
94
102
  from
95
103
  daily_comparison,
@@ -97,7 +105,8 @@ from
97
105
  if(enhanced_events is null and raw_events > 0, 'MISSING_DAY', null),
98
106
  if(data_is_final = true and enhanced_sessions != raw_sessions, 'SESSION_COUNT_MISMATCH', null),
99
107
  if(data_is_final = true and enhanced_events != raw_events, 'EVENT_COUNT_MISMATCH', null),
100
- if(data_is_final = true and enhanced_revenue != raw_revenue, 'REVENUE_MISMATCH', null),
108
+ if(data_is_final = true and enhanced_item_revenue != raw_item_revenue, 'ITEM_REVENUE_MISMATCH', null),
109
+ if(data_is_final = true and enhanced_purchase_revenue != raw_purchase_revenue, 'PURCHASE_REVENUE_MISMATCH', null),
101
110
  if(data_is_final = false and coalesce(enhanced_events, 0) > coalesce(raw_events, 0), 'NON_FINAL_EXCESS_EVENTS', null)
102
111
  ]) as violation_type
103
112
  where
@@ -108,9 +117,9 @@ where
108
117
  * Generates a daily quality assertion SQL query.
109
118
  *
110
119
  * Merges the provided config with defaults, validates, then generates a SQL
111
- * query comparing daily aggregates (session count, event count, item_revenue)
112
- * between the enhanced table and raw export data, and checks for missing days
113
- * and non-final data inflation.
120
+ * query comparing daily aggregates (session count, event count, item_revenue,
121
+ * ecommerce.purchase_revenue) between the enhanced table and raw export data,
122
+ * and checks for missing days and non-final data inflation.
114
123
  *
115
124
  * @param {string} tableRef - Fully qualified reference to the enhanced table.
116
125
  * @param {Object} config - User-provided table configuration.