ga4-export-fixer 0.1.6-dev.6 → 0.1.6-dev.8

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.
Files changed (3) hide show
  1. package/README.md +32 -0
  2. package/helpers.js +20 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -220,6 +220,38 @@ All fields are optional except `sourceTable`. Default values are applied automat
220
220
 
221
221
  Date fields (`dateRangeStart`, `dateRangeEnd`, etc.) accept string dates in `YYYYMMDD` or `YYYY-MM-DD` format, or BigQuery SQL expressions (e.g. `'current_date()'`, `'date(2026, 1, 1)'`).
222
222
 
223
+ ### Build on top of the ga4_events_enhanced table
224
+
225
+ **`definitions/ga4/ga4_sessions.sqlx`**
226
+ ```javascript
227
+ config {
228
+ type: "incremental",
229
+ description: "GA4 Events Enhanced table",
230
+ schema: "ga4",
231
+ bigquery: {
232
+ partitionBy: "event_date",
233
+ clusterBy: ['event_name', 'session_id', 'page_location', 'data_is_final'],
234
+ },
235
+ tags: ['ga4_export_fixer']
236
+ }
237
+
238
+ js {
239
+ const { ga4EventsEnhanced } = require('ga4-export-fixer');
240
+
241
+ const config = {
242
+ sourceTable: ref(constants.GA4_TABLES.MY_GA4_EXPORT),
243
+ self: self(),
244
+ incremental: incremental()
245
+ };
246
+ }
247
+
248
+ ${ga4EventsEnhanced.generateSql(config)}
249
+
250
+ pre_operations {
251
+ ${ga4EventsEnhanced.setPreOperations(config)}
252
+ }
253
+ ```
254
+
223
255
  ### Helpers
224
256
 
225
257
  The helpers contain templates for common SQL expressions. The functions are referenced by **ga4EventsEnhanced** but can also be imported as utility functions for working with GA4 data.
package/helpers.js CHANGED
@@ -563,8 +563,14 @@ Aggregation
563
563
  * // => SQL expression for the last user_id by event_timestamp.
564
564
  */
565
565
  const aggregateValue = (column, aggregateType, timestampColumn) => {
566
- if (typeof column === 'undefined' || typeof timestampColumn === 'undefined') {
567
- throw new Error("aggregateValue: 'column' and 'timestampColumn' are required parameters and must be defined.");
566
+ if (typeof column === 'undefined') {
567
+ throw new Error("aggregateValue: 'column' is a required parameter and must be defined.");
568
+ }
569
+ if (typeof aggregateType === 'undefined') {
570
+ throw new Error("aggregateValue: 'aggregateType' is a required parameter and must be defined.");
571
+ }
572
+ if ((aggregateType === 'first' || aggregateType === 'last') && typeof timestampColumn === 'undefined') {
573
+ throw new Error(`aggregateValue: 'timestampColumn' is required when aggregateType is '${aggregateType}'.`);
568
574
  }
569
575
 
570
576
  if (aggregateType === 'max') {
@@ -598,6 +604,17 @@ const aggregateValue = (column, aggregateType, timestampColumn) => {
598
604
  throw new Error(`aggregateValue: Unsupported aggregateType '${aggregateType}'. Supported values are 'max', 'min', 'first', 'last', and 'any'.`);
599
605
  };
600
606
 
607
+ // perform aggregations on an array of values
608
+ const aggregateValues = (values) => {
609
+ if (Array.isArray(values)) {
610
+ return values.map(value => {
611
+ const sqlExpression = aggregateValue(value.column, value.aggregateType, value.timestampColumn)
612
+ return `${sqlExpression}${value.alias ? ` as ${value.alias}` : ''}`;
613
+ }).join('\n, ');
614
+ }
615
+ throw new Error("aggregateValues: 'values' must be an array of objects with 'column', 'aggregateType', and 'timestampColumn' properties.");
616
+ };
617
+
601
618
  /*
602
619
  Ecommerce
603
620
  */
@@ -748,6 +765,7 @@ module.exports = {
748
765
  unnestEventParam,
749
766
  sessionId,
750
767
  aggregateValue,
768
+ aggregateValues,
751
769
  fixEcommerceStruct,
752
770
  isFinalData,
753
771
  ga4ExportDateFilter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.6-dev.6",
3
+ "version": "0.1.6-dev.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [