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

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/helpers.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const constants = require('./constants');
2
+ const { baseConfig } = require('./defaultConfig');
2
3
 
3
4
  /*
4
5
  Unnesting parameters
@@ -248,19 +249,29 @@ const ga4ExportDateFilters = (config) => {
248
249
  * @param {Object} [config.preOperations] - Contains full refresh date range values.
249
250
  * @returns {string} - SQL condition string to filter the query by date range.
250
251
  */
251
- const finalDataFilter = (config) => {
252
+ const incrementalDateFilter = (config) => {
252
253
  const setDateRange = (start, end) => {
253
254
  return `(event_date >= ${start} and event_date <= ${end})`;
254
255
  };
255
256
 
257
+ // test mode
256
258
  if (config.test) {
257
- return setDateRange(config.testConfig.dateRangeStart, config.testConfig.dateRangeEnd);
259
+ const testStart = config.testConfig.dateRangeStart || baseConfig.testConfig.dateRangeStart;
260
+ const testEnd = config.testConfig.dateRangeEnd || baseConfig.testConfig.dateRangeEnd;
261
+
262
+ return setDateRange(testStart, testEnd);
258
263
  }
264
+
265
+ // incremental mode
259
266
  if (config.incremental) {
260
267
  return setDateRange(constants.DATE_RANGE_START_VARIABLE, constants.DATE_RANGE_END_VARIABLE);
261
268
  }
262
-
263
- return setDateRange(config.preOperations.dateRangeStartFullRefresh, config.preOperations.dateRangeEnd);
269
+
270
+ // full refresh mode
271
+ const fullRefreshStart = config.preOperations.dateRangeStartFullRefresh || baseConfig.preOperations.dateRangeStartFullRefresh;
272
+ const fullRefreshEnd = config.preOperations.dateRangeEnd || baseConfig.preOperations.dateRangeEnd;
273
+
274
+ return setDateRange(fullRefreshStart, fullRefreshEnd);
264
275
  };
265
276
 
266
277
  /*
@@ -744,7 +755,7 @@ module.exports = {
744
755
  filterEventParams,
745
756
  aggregateSessionParams,
746
757
  excludeNullSessionParams,
747
- finalDataFilter,
758
+ incrementalDateFilter,
748
759
  extractPageDetails,
749
760
  extractUrlHostname,
750
761
  extractUrlPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.6-dev.2",
3
+ "version": "0.1.6-dev.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -10,7 +10,8 @@
10
10
  "preOperations.js",
11
11
  "constants.js",
12
12
  "tables",
13
- "inputValidation.js"
13
+ "inputValidation.js",
14
+ "config.js"
14
15
  ],
15
16
  "scripts": {
16
17
  "test": "node tests/ga4EventsEnhanced.test.js",
@@ -3,71 +3,11 @@ const utils = require('../utils.js');
3
3
  const inputValidation = require('../inputValidation.js');
4
4
  const constants = require('../constants.js');
5
5
  const preOperations = require('../preOperations.js');
6
+ const { ga4EventsEnhancedConfig } = require('../defaultConfig.js'); // config defaults
6
7
 
7
8
  // default configuration for the GA4 Events Enhanced table
8
9
  const defaultConfig = {
9
- // required
10
- sourceTable: undefined,
11
- sourceTableType: 'GA4_EXPORT', // used with pre operations to detect if ga4 export specific pre operations are needed
12
- self: undefined,
13
- incremental: undefined,
14
- // optional but recommended
15
- schemaLock: undefined,
16
- // only used with js tables
17
- // dataformTableConfig: {},
18
- // optional
19
- includedExportTypes: {
20
- daily: true,
21
- intraday: true,
22
- fresh: false,
23
- },
24
- timezone: 'Etc/UTC',
25
- customTimestampParam: undefined,
26
- dataIsFinal: {
27
- detectionMethod: 'EXPORT_TYPE', // or 'DAY_THRESHOLD'
28
- dayThreshold: 4 // only used if detectionMethod is 'DAY_THRESHOLD'
29
- },
30
- test: false,
31
- testConfig: {
32
- dateRangeStart: 'current_date()-1',
33
- dateRangeEnd: 'current_date()',
34
- },
35
- // number of additional days to take in for taking into account sessions that overlap days
36
- bufferDays: 1,
37
- preOperations: {
38
- dateRangeStartFullRefresh: 'date(2000, 1, 1)',
39
- dateRangeEnd: 'current_date()',
40
- // incrementalStartOverride and incrementalEndOverride are used to override the date range start and end for incremental refresh
41
- // this is useful if you want to re-process only a specific date range
42
- incrementalStartOverride: undefined,
43
- incrementalEndOverride: undefined,
44
- numberOfPreviousDaysToScan: 10,
45
- },
46
- // these parameters are excluded by default because they've been made available in other columns
47
- defaultExcludedEventParams: [
48
- 'page_location',
49
- 'ga_session_id',
50
- //'custom_event_timestamp', // removed if customTimestampParam is used
51
- ],
52
- excludedEventParams: [],
53
- eventParamsToColumns: [
54
- //{name: 'page_location', type: 'string', columnName: 'page_location2'},
55
- ],
56
- sessionParams: [],
57
- defaultExcludedEvents: [],
58
- // session_start and first_visit are excluded via the excludedEvents array
59
- // this allows the user to include them if needed
60
- excludedEvents: [
61
- 'session_start',
62
- 'first_visit'
63
- ],
64
- defaultExcludedColumns: [
65
- 'event_dimensions', // legacy column, not needed
66
- 'traffic_source', // renamed to user_traffic_source
67
- 'session_id'
68
- ],
69
- // exclude these columns when extracting raw data from the export tables
70
- excludedColumns: [],
10
+ ...ga4EventsEnhancedConfig,
71
11
  };
72
12
 
73
13
  // List the columns in the order they should be in the final table
@@ -342,7 +282,7 @@ ${excludedEventsSQL}`,
342
282
  condition: 'using(session_id)'
343
283
  }
344
284
  ],
345
- where: helpers.finalDataFilter(mergedConfig)
285
+ where: helpers.incrementalDateFilter(mergedConfig)
346
286
  };
347
287
 
348
288
  const steps = [