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 +12 -1
- package/documentation.js +8 -6
- package/package.json +1 -1
- package/tables/ga4EventsEnhanced.js +36 -37
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/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
|
|
286
|
-
Object.
|
|
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
|
@@ -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
|
-
|
|
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
|
|
328
|
+
const mergedConfig = utils.mergeSQLConfigurations(defaultConfig, sqlConfig);
|
|
325
329
|
|
|
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
|
-
};
|
|
330
|
+
// Static defaults from defaultConfig.js (via mergedConfig, without user overrides)
|
|
331
|
+
const staticDefaults = mergedConfig.dataformTableConfig || {};
|
|
343
332
|
|
|
344
|
-
//
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
344
|
+
const dataset = getDatasetName(mergedConfig.sourceTable);
|
|
357
345
|
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
365
|
-
|
|
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 => {
|