ga4-export-fixer 0.4.2-dev.2 → 0.4.3-dev.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
@@ -150,7 +150,7 @@ Include the package in the package.json file in your Dataform repository.
150
150
  {
151
151
  "dependencies": {
152
152
  "@dataform/core": "3.0.42",
153
- "ga4-export-fixer": "0.4.1"
153
+ "ga4-export-fixer": "0.4.2"
154
154
  }
155
155
  }
156
156
  ```
package/defaultConfig.js CHANGED
@@ -38,7 +38,18 @@ const ga4EventsEnhancedConfig = {
38
38
  // optional but recommended
39
39
  schemaLock: undefined,
40
40
  // only used with js tables
41
- // dataformTableConfig: {},
41
+ dataformTableConfig: {
42
+ type: 'incremental',
43
+ bigquery: {
44
+ partitionBy: 'event_date',
45
+ clusterBy: ['event_name', 'session_id', 'page_location', 'data_is_final'],
46
+ labels: {
47
+ 'ga4_export_fixer': 'true'
48
+ }
49
+ },
50
+ onSchemaChange: 'EXTEND',
51
+ tags: ['ga4_export_fixer'],
52
+ },
42
53
  // optional
43
54
  includedExportTypes: {
44
55
  daily: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.4.2-dev.2",
3
+ "version": "0.4.3-dev.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -319,50 +319,44 @@ ${excludedEventsSQL}`,
319
319
  * @returns {Object} The Dataform publish() object for the enhanced events table, supporting chaining (e.g. .preOps, .query).
320
320
  */
321
321
  const createEnhancedEventsTable = (dataformPublish, config) => {
322
- const mergedConfig = utils.mergeSQLConfigurations(defaultConfig, config);
322
+ // Extract user dataformTableConfig before SQL merge to prevent double-merge.
323
+ // mergeSQLConfigurations overwrites arrays (tags), so passing user overrides through it
324
+ // would lose the default tags. By stripping it here, user overrides are applied exactly
325
+ // once via mergeDataformTableConfigurations.
326
+ const { dataformTableConfig: userDataformTableConfig, ...sqlConfig } = config;
327
+
328
+ const mergedConfig = utils.mergeSQLConfigurations(defaultConfig, sqlConfig);
323
329
 
324
330
  const tableDescription = documentation.getTableDescription(mergedConfig);
325
331
 
326
- // the defaults for the dataform table config
327
- const defaultDataformTableConfig = {
328
- name: constants.DEFAULT_EVENTS_TABLE_NAME,
329
- type: 'incremental',
330
- schema: 'ga4_export_fixer',
331
- description: tableDescription,
332
- bigquery: {
333
- partitionBy: 'event_date',
334
- clusterBy: ['event_name', 'session_id', 'page_location', 'data_is_final'],
335
- labels: {
336
- 'ga4_export_fixer': 'true'
337
- }
338
- },
339
- onSchemaChange: 'EXTEND',
340
- tags: ['ga4_export_fixer'],
341
- columns: documentation.getColumnDescriptions(mergedConfig)
342
- };
332
+ // Static defaults from defaultConfig.js (via mergedConfig, without user overrides)
333
+ const staticDefaults = mergedConfig.dataformTableConfig || {};
343
334
 
344
- // set the default values for table name and dataset, if not provided in the config
345
- const setDefaults = () => {
346
- const getDatasetName = (sourceTable) => {
347
- if (utils.isDataformTableReferenceObject(sourceTable)) {
348
- return sourceTable.dataset || sourceTable.schema;
349
- }
350
- if (typeof sourceTable === 'string' && /^`[^\.]+\.[^\.]+\.[^\.]+`$/.test(sourceTable)) {
351
- return sourceTable.split('.')[1];
352
- }
353
- throw new Error(`Unable to extract the dataset name from sourceTable, received: ${JSON.stringify(sourceTable)}`);
354
- };
335
+ // Compute dynamic fields from merged SQL config
336
+ const getDatasetName = (sourceTable) => {
337
+ if (utils.isDataformTableReferenceObject(sourceTable)) {
338
+ return sourceTable.dataset || sourceTable.schema;
339
+ }
340
+ if (typeof sourceTable === 'string' && /^`[^\.]+\.[^\.]+\.[^\.]+`$/.test(sourceTable)) {
341
+ return sourceTable.split('.')[1];
342
+ }
343
+ throw new Error(`Unable to extract the dataset name from sourceTable, received: ${JSON.stringify(sourceTable)}`);
344
+ };
355
345
 
356
- const dataset = getDatasetName(mergedConfig.sourceTable);
346
+ const dataset = getDatasetName(mergedConfig.sourceTable);
357
347
 
358
- defaultDataformTableConfig.name = `${constants.DEFAULT_EVENTS_TABLE_NAME}_${dataset.replace('analytics_', '')}`;
359
- defaultDataformTableConfig.schema = dataset;
348
+ const dynamicFields = {
349
+ name: `${constants.DEFAULT_EVENTS_TABLE_NAME}_${dataset.replace('analytics_', '')}`,
350
+ schema: dataset,
351
+ description: tableDescription,
352
+ columns: documentation.getColumnDescriptions(mergedConfig),
360
353
  };
361
354
 
362
- setDefaults();
363
-
364
- // merge the dataform table config with the default dataform table config
365
- const dataformTableConfig = utils.mergeDataformTableConfigurations(defaultDataformTableConfig, mergedConfig.dataformTableConfig);
355
+ // Merge: static defaults → dynamic fields → user overrides
356
+ const dataformTableConfig = utils.mergeDataformTableConfigurations(
357
+ { ...staticDefaults, ...dynamicFields },
358
+ userDataformTableConfig
359
+ );
366
360
 
367
361
  // create the table using Dataform publish()
368
362
  return dataformPublish(dataformTableConfig.name, dataformTableConfig).preOps(ctx => {