ga4-export-fixer 0.1.6-dev.7 → 0.1.6-dev.9

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 +12 -0
  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
@@ -604,6 +604,17 @@ const aggregateValue = (column, aggregateType, timestampColumn) => {
604
604
  throw new Error(`aggregateValue: Unsupported aggregateType '${aggregateType}'. Supported values are 'max', 'min', 'first', 'last', and 'any'.`);
605
605
  };
606
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
+
607
618
  /*
608
619
  Ecommerce
609
620
  */
@@ -754,6 +765,7 @@ module.exports = {
754
765
  unnestEventParam,
755
766
  sessionId,
756
767
  aggregateValue,
768
+ aggregateValues,
757
769
  fixEcommerceStruct,
758
770
  isFinalData,
759
771
  ga4ExportDateFilter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.6-dev.7",
3
+ "version": "0.1.6-dev.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [