ga4-export-fixer 0.1.6-dev.9 → 0.2.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/README.md CHANGED
@@ -32,7 +32,7 @@ Include the package in the package.json file in your Dataform repository.
32
32
  {
33
33
  "dependencies": {
34
34
  "@dataform/core": "3.0.42",
35
- "ga4-export-fixer": "0.1.5"
35
+ "ga4-export-fixer": "0.2.0"
36
36
  }
37
37
  }
38
38
  ```
@@ -220,35 +220,72 @@ 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
223
+ ### Building on top of the ga4_events_enhanced table
224
+
225
+ Setting up incremental updates is easy using the **setPreOperations()** function. Just ensure that your result table includes the **data_is_final** flag from the **ga4_enhanced_events** table.
226
+
227
+ The **incrementalDateFilter()** function applies the same date filtering used by **ga4_events_enhanced**, based on the **config** options and the variables declared by **setPreOperations()**.
228
+
229
+ Key fields such as session_id, user_id, and session_traffic_source_last_click are available as clean, sessionized versions that handle edge cases like sessions spanning midnight.
224
230
 
225
231
  **`definitions/ga4/ga4_sessions.sqlx`**
226
232
  ```javascript
227
233
  config {
228
234
  type: "incremental",
229
- description: "GA4 Events Enhanced table",
230
- schema: "ga4",
235
+ description: "GA4 sessions table",
236
+ schema: "ga4_export_fixer",
231
237
  bigquery: {
232
238
  partitionBy: "event_date",
233
- clusterBy: ['event_name', 'session_id', 'page_location', 'data_is_final'],
239
+ clusterBy: ['session_id', 'data_is_final'],
234
240
  },
235
241
  tags: ['ga4_export_fixer']
236
242
  }
237
243
 
238
244
  js {
239
- const { ga4EventsEnhanced } = require('ga4-export-fixer');
245
+ const { setPreOperations, helpers } = require('ga4-export-fixer');
240
246
 
241
247
  const config = {
242
- sourceTable: ref(constants.GA4_TABLES.MY_GA4_EXPORT),
243
248
  self: self(),
244
- incremental: incremental()
249
+ incremental: incremental(),
250
+ /*
251
+ Default options that can be overriden:
252
+ test: false,
253
+ testConfig: {
254
+ dateRangeStart: 'current_date()-1',
255
+ dateRangeEnd: 'current_date()',
256
+ },
257
+ preOperations: {
258
+ dateRangeStartFullRefresh: 'date(2000, 1, 1)',
259
+ dateRangeEnd: 'current_date()',
260
+ // incremental date range overrides allow re-processing only a subset of the data:
261
+ //incrementalStartOverride: undefined,
262
+ //incrementalEndOverride: undefined,
263
+ },
264
+ */
245
265
  };
246
266
  }
247
267
 
248
- ${ga4EventsEnhanced.generateSql(config)}
268
+ select
269
+ event_date,
270
+ session_id,
271
+ user_pseudo_id,
272
+ user_id,
273
+ any_value(session_traffic_source_last_click.cross_channel_campaign) as session_traffic_source,
274
+ any_value(landing_page) as landing_page,
275
+ current_datetime() as row_inserted_timestamp,
276
+ min(data_is_final) as data_is_final
277
+ from
278
+ ${ref('ga4_events_enhanced_298233330')}
279
+ where
280
+ ${helpers.incrementalDateFilter(config)}
281
+ group by
282
+ event_date,
283
+ session_id,
284
+ user_pseudo_id,
285
+ user_id
249
286
 
250
287
  pre_operations {
251
- ${ga4EventsEnhanced.setPreOperations(config)}
288
+ ${setPreOperations(config)}
252
289
  }
253
290
  ```
254
291
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.6-dev.9",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
package/preOperations.js CHANGED
@@ -85,7 +85,7 @@ const getDateRangeStartIntraday = (config) => {
85
85
  date
86
86
  )
87
87
  select
88
- max(
88
+ min(
89
89
  if(
90
90
  intraday = true and daily = false,
91
91
  date,