ga4-export-fixer 0.4.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/defaultConfig.js +12 -1
- package/package.json +1 -1
- package/tables/ga4EventsEnhanced.js +30 -36
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
|
-
|
|
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
|
@@ -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
|
-
|
|
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
|
-
//
|
|
327
|
-
const
|
|
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
|
-
//
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
346
|
+
const dataset = getDatasetName(mergedConfig.sourceTable);
|
|
357
347
|
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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 => {
|