ga4-export-fixer 0.1.6-dev.3 → 0.1.6-dev.5

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.
@@ -0,0 +1,85 @@
1
+ /*
2
+ These are the configuration defaults that can be extended.
3
+
4
+ For example, load the defaults in ga4EventsEnhanced.js and then extend them with whatever is psecific to the table.
5
+ After that, extend the configuration further with the user's configuration.
6
+ */
7
+
8
+ /*
9
+ The base configuration. Input config validation should always check these fields.
10
+ */
11
+ const baseConfig = {
12
+ self: undefined,
13
+ incremental: undefined,
14
+ test: false,
15
+ testConfig: {
16
+ dateRangeStart: 'current_date()-1',
17
+ dateRangeEnd: 'current_date()',
18
+ },
19
+ preOperations: {
20
+ dateRangeStartFullRefresh: 'date(2000, 1, 1)',
21
+ dateRangeEnd: 'current_date()',
22
+ // incrementalStartOverride and incrementalEndOverride are used to override the date range start and end for incremental refresh
23
+ // this is useful if you want to re-process only a specific date range
24
+ incrementalStartOverride: undefined,
25
+ incrementalEndOverride: undefined,
26
+ numberOfPreviousDaysToScan: 10,
27
+ },
28
+ };
29
+
30
+ /*
31
+ The default configuration for the GA4 Events Enhanced table.
32
+ */
33
+ const ga4EventsEnhancedConfig = {
34
+ ...baseConfig,
35
+ sourceTable: undefined,
36
+ sourceTableType: 'GA4_EXPORT', // used with pre operations to detect if ga4 export specific pre operations are needed
37
+ // optional but recommended
38
+ schemaLock: undefined,
39
+ // only used with js tables
40
+ // dataformTableConfig: {},
41
+ // optional
42
+ includedExportTypes: {
43
+ daily: true,
44
+ intraday: true,
45
+ fresh: false,
46
+ },
47
+ timezone: 'Etc/UTC',
48
+ customTimestampParam: undefined,
49
+ dataIsFinal: {
50
+ detectionMethod: 'EXPORT_TYPE', // or 'DAY_THRESHOLD'
51
+ dayThreshold: 4 // only used if detectionMethod is 'DAY_THRESHOLD'
52
+ },
53
+ // number of additional days to take in for taking into account sessions that overlap days
54
+ bufferDays: 1,
55
+ // these parameters are excluded by default because they've been made available in other columns
56
+ defaultExcludedEventParams: [
57
+ 'page_location',
58
+ 'ga_session_id',
59
+ //'custom_event_timestamp', // removed if customTimestampParam is used
60
+ ],
61
+ excludedEventParams: [],
62
+ eventParamsToColumns: [
63
+ //{name: 'page_location', type: 'string', columnName: 'page_location2'},
64
+ ],
65
+ sessionParams: [],
66
+ defaultExcludedEvents: [],
67
+ // session_start and first_visit are excluded via the excludedEvents array
68
+ // this allows the user to include them if needed
69
+ excludedEvents: [
70
+ 'session_start',
71
+ 'first_visit'
72
+ ],
73
+ defaultExcludedColumns: [
74
+ 'event_dimensions', // legacy column, not needed
75
+ 'traffic_source', // renamed to user_traffic_source
76
+ 'session_id'
77
+ ],
78
+ // exclude these columns when extracting raw data from the export tables
79
+ excludedColumns: [],
80
+ };
81
+
82
+ module.exports = {
83
+ baseConfig,
84
+ ga4EventsEnhancedConfig,
85
+ };
package/helpers.js CHANGED
@@ -256,8 +256,8 @@ const incrementalDateFilter = (config) => {
256
256
 
257
257
  // test mode
258
258
  if (config.test) {
259
- const testStart = config.testConfig.dateRangeStart || baseConfig.testConfig.dateRangeStart;
260
- const testEnd = config.testConfig.dateRangeEnd || baseConfig.testConfig.dateRangeEnd;
259
+ const testStart = config?.testConfig?.dateRangeStart || baseConfig.testConfig.dateRangeStart;
260
+ const testEnd = config?.testConfig?.dateRangeEnd || baseConfig.testConfig.dateRangeEnd;
261
261
 
262
262
  return setDateRange(testStart, testEnd);
263
263
  }
@@ -268,8 +268,8 @@ const incrementalDateFilter = (config) => {
268
268
  }
269
269
 
270
270
  // full refresh mode
271
- const fullRefreshStart = config.preOperations.dateRangeStartFullRefresh || baseConfig.preOperations.dateRangeStartFullRefresh;
272
- const fullRefreshEnd = config.preOperations.dateRangeEnd || baseConfig.preOperations.dateRangeEnd;
271
+ const fullRefreshStart = config?.preOperations?.dateRangeStartFullRefresh || baseConfig.preOperations.dateRangeStartFullRefresh;
272
+ const fullRefreshEnd = config?.preOperations?.dateRangeEnd || baseConfig.preOperations.dateRangeEnd;
273
273
 
274
274
  return setDateRange(fullRefreshStart, fullRefreshEnd);
275
275
  };
package/index.js CHANGED
@@ -3,36 +3,25 @@ const ga4EventsEnhanced = require('./tables/ga4EventsEnhanced.js');
3
3
  const preOperations = require('./preOperations.js');
4
4
  const { validateConfig } = require('./inputValidation.js');
5
5
  const { mergeSQLConfigurations } = require('./utils.js');
6
+ const { baseConfig } = require('./defaultConfig.js');
6
7
 
7
8
  // export setPreOperations with default configuration for usage with downstream tables
8
9
  const setPreOperations = (config) => {
9
10
  if (!config || !config.self) {
10
11
  throw new Error('setPreOperations: config.self is required. Pass the table\'s "self()" reference in the config object.');
11
12
  }
12
- if (config.incremental === undefined || config.incremental === null) {
13
+ if (typeof config.incremental !== 'boolean') {
13
14
  throw new Error('setPreOperations: config.incremental is required. Pass a boolean indicating whether the table uses incremental mode.');
14
15
  }
15
16
 
16
17
  /*
17
- Todo: consider improving the validateConfig function to cover this use case as well
18
+ Todo:
19
+ - validation for baseConfig -> include in this function
20
+ - separate config merge into another function
21
+ - don't create a full ga4EnhancedEvents config for this case
18
22
  */
19
23
 
20
- const defaultConfig = {
21
- self: undefined,
22
- incremental: undefined,
23
- test: false,
24
- testConfig: {
25
- dateRangeStart: 'current_date()-1',
26
- dateRangeEnd: 'current_date()',
27
- },
28
- preOperations: {
29
- dateRangeStartFullRefresh: 'date(2000, 1, 1)',
30
- dateRangeEnd: 'current_date()',
31
- numberOfPreviousDaysToScan: 10,
32
- },
33
- };
34
-
35
- const mergedConfig = mergeSQLConfigurations(defaultConfig, config);
24
+ const mergedConfig = mergeSQLConfigurations(baseConfig, config);
36
25
 
37
26
  return preOperations.setPreOperations(mergedConfig);
38
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.6-dev.3",
3
+ "version": "0.1.6-dev.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -11,6 +11,7 @@
11
11
  "constants.js",
12
12
  "tables",
13
13
  "inputValidation.js",
14
+ "defaultConfig.js",
14
15
  "config.js"
15
16
  ],
16
17
  "scripts": {