ga4-export-fixer 0.4.2 → 0.4.3-dev.1

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/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/documentation.js CHANGED
@@ -282,13 +282,15 @@ const getTableDescription = (config) => {
282
282
  sections.push(`${constants.TABLE_DESCRIPTION_SUFFIX}\n${constants.TABLE_DESCRIPTION_DOCUMENTATION_LINK}`);
283
283
 
284
284
  // 8. Config JSON dump
285
- const configJson = JSON.stringify(
286
- Object.fromEntries(
287
- Object.entries(config).filter(([key]) => !key.startsWith('default') && key !== 'dataformTableConfig')
288
- ),
289
- null,
290
- 2
285
+ const configForDump = Object.fromEntries(
286
+ Object.entries(config).filter(([key]) => !key.startsWith('default'))
291
287
  );
288
+ // Strip description and columns from dataformTableConfig to avoid circular reference and bloat
289
+ if (configForDump.dataformTableConfig) {
290
+ const { description, columns, ...rest } = configForDump.dataformTableConfig;
291
+ configForDump.dataformTableConfig = rest;
292
+ }
293
+ const configJson = JSON.stringify(configForDump, null, 2);
292
294
  sections.push(`The last full table refresh was done using this configuration:\n${configJson}`);
293
295
 
294
296
  return sections.join('\n\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.4.2",
3
+ "version": "0.4.3-dev.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -319,50 +319,49 @@ ${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;
323
327
 
324
- const tableDescription = documentation.getTableDescription(mergedConfig);
328
+ const mergedConfig = utils.mergeSQLConfigurations(defaultConfig, sqlConfig);
325
329
 
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
- };
330
+ // Static defaults from defaultConfig.js (via mergedConfig, without user overrides)
331
+ const staticDefaults = mergedConfig.dataformTableConfig || {};
343
332
 
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
- };
333
+ // Compute dynamic fields from merged SQL config
334
+ const getDatasetName = (sourceTable) => {
335
+ if (utils.isDataformTableReferenceObject(sourceTable)) {
336
+ return sourceTable.dataset || sourceTable.schema;
337
+ }
338
+ if (typeof sourceTable === 'string' && /^`[^\.]+\.[^\.]+\.[^\.]+`$/.test(sourceTable)) {
339
+ return sourceTable.split('.')[1];
340
+ }
341
+ throw new Error(`Unable to extract the dataset name from sourceTable, received: ${JSON.stringify(sourceTable)}`);
342
+ };
355
343
 
356
- const dataset = getDatasetName(mergedConfig.sourceTable);
344
+ const dataset = getDatasetName(mergedConfig.sourceTable);
357
345
 
358
- defaultDataformTableConfig.name = `${constants.DEFAULT_EVENTS_TABLE_NAME}_${dataset.replace('analytics_', '')}`;
359
- defaultDataformTableConfig.schema = dataset;
360
- };
346
+ // Merge: static defaults → dynamic fields (except description) → user overrides
347
+ const dataformTableConfig = utils.mergeDataformTableConfigurations(
348
+ {
349
+ ...staticDefaults,
350
+ name: `${constants.DEFAULT_EVENTS_TABLE_NAME}_${dataset.replace('analytics_', '')}`,
351
+ schema: dataset,
352
+ columns: documentation.getColumnDescriptions(mergedConfig),
353
+ },
354
+ userDataformTableConfig
355
+ );
361
356
 
362
- setDefaults();
357
+ // Include the final dataformTableConfig in mergedConfig for the description's config dump
358
+ mergedConfig.dataformTableConfig = dataformTableConfig;
359
+ const tableDescription = documentation.getTableDescription(mergedConfig);
363
360
 
364
- // merge the dataform table config with the default dataform table config
365
- const dataformTableConfig = utils.mergeDataformTableConfigurations(defaultDataformTableConfig, mergedConfig.dataformTableConfig);
361
+ // Set description (user override from the merge wins if provided)
362
+ if (!dataformTableConfig.description) {
363
+ dataformTableConfig.description = tableDescription;
364
+ }
366
365
 
367
366
  // create the table using Dataform publish()
368
367
  return dataformPublish(dataformTableConfig.name, dataformTableConfig).preOps(ctx => {