ga4-export-fixer 0.5.1-dev.0 → 0.5.1-dev.2

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/README.md CHANGED
@@ -204,7 +204,7 @@ const config = {
204
204
  dateRangeStart: 'current_date()-1',
205
205
  dateRangeEnd: 'current_date()',
206
206
  },
207
- schemaLock: '20260101', // prevent possible issues from updates to the export schema
207
+ schemaLock: '20260101', // lock to daily export; also supports 'intraday_20260101' or 'fresh_20260101'
208
208
  customTimestampParam: 'custom_event_timestamp', // custom timestamp collected as an event param
209
209
  timezone: 'Europe/Helsinki',
210
210
  // not needed data
@@ -291,7 +291,7 @@ All fields are optional except `sourceTable`. Default values are applied automat
291
291
  | `self` | Dataform self() | **required for .SQLX deployment** | Reference to the table itself. Use `self()` in Dataform |
292
292
  | `incremental` | Dataform incremental() | **required for .SQLX deployment** | Switch between incremental and full refresh logic. Use `incremental()` in Dataform |
293
293
  | `dataformTableConfig` | object | **In JS deployment only.** [See default](#default-dataformtableconfig) | Override the default Dataform table configuration for JS deployment. See: [ITableConfig reference](https://docs.cloud.google.com/dataform/docs/reference/dataform-core-reference#itableconfig) |
294
- | `schemaLock` | string (YYYYMMDD) | `undefined` | Lock the table schema to a specific date. Must be a valid date >= `"20241009"` |
294
+ | `schemaLock` | string | `undefined` | Lock the table schema to a specific GA4 export table suffix. Accepts `"YYYYMMDD"` (daily), `"intraday_YYYYMMDD"`, or `"fresh_YYYYMMDD"`. Date must be >= `"20241009"` |
295
295
  | `timezone` | string | `'Etc/UTC'` | IANA timezone for event datetime (e.g. `'Europe/Helsinki'`) |
296
296
  | `customTimestampParam` | string | `undefined` | Name of a custom event parameter containing a JS timestamp in milliseconds (e.g. collected via `Date.now()`) |
297
297
  | `bufferDays` | integer | `1` | Extra days to include for sessions that span midnight |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.5.1-dev.0",
3
+ "version": "0.5.1-dev.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
package/preOperations.js CHANGED
@@ -45,11 +45,10 @@ const getDateRangeStart = (config) => {
45
45
  ${constants.DATE_COLUMN}
46
46
  )
47
47
  select
48
- max(${constants.DATE_COLUMN})+1 as ${constants.DATE_RANGE_START_VARIABLE}
49
- from
50
- days
51
- where
52
- data_is_final = true`;
48
+ coalesce(
49
+ (select max(${constants.DATE_COLUMN})+1 from days where data_is_final = true),
50
+ (select min(${constants.DATE_COLUMN}) from days where data_is_final = false)
51
+ ) as ${constants.DATE_RANGE_START_VARIABLE}`;
53
52
  } else {
54
53
  const dateRangeStartFullRefresh = config.test ? config.testConfig.dateRangeStart : config.preOperations.dateRangeStartFullRefresh;
55
54
  return `select ${dateRangeStartFullRefresh}`;
@@ -40,22 +40,23 @@ const validateEnhancedEventsConfig = (config, options = {}) => {
40
40
  throw new Error(`config.sourceTable must be a Dataform table reference object or a string in format '\`project.dataset.table\`'. Received: ${JSON.stringify(config.sourceTable)}`);
41
41
  }
42
42
 
43
- // schemaLock - optional; must be undefined or a string in "YYYYMMDD" format (e.g., "20260101")
43
+ // schemaLock - optional; must be undefined or a GA4 export table suffix: "YYYYMMDD", "intraday_YYYYMMDD", or "fresh_YYYYMMDD"
44
44
  if (typeof config.schemaLock !== 'undefined') {
45
- if (typeof config.schemaLock !== 'string' || !/^\d{8}$/.test(config.schemaLock)) {
46
- throw new Error(`config.schemaLock must be a string in "YYYYMMDD" format (e.g., "20260101"). Received: ${JSON.stringify(config.schemaLock)}`);
45
+ if (typeof config.schemaLock !== 'string' || !/^(?:(?:intraday|fresh)_)?\d{8}$/.test(config.schemaLock)) {
46
+ throw new Error(`config.schemaLock must be a string in "YYYYMMDD", "intraday_YYYYMMDD", or "fresh_YYYYMMDD" format (e.g., "20260101", "intraday_20260101"). Received: ${JSON.stringify(config.schemaLock)}`);
47
47
  }
48
- // Must be a valid date
49
- const year = parseInt(config.schemaLock.slice(0, 4), 10);
50
- const month = parseInt(config.schemaLock.slice(4, 6), 10);
51
- const day = parseInt(config.schemaLock.slice(6, 8), 10);
48
+ // Must be a valid date (extract date portion from the end)
49
+ const datePart = config.schemaLock.slice(-8);
50
+ const year = parseInt(datePart.slice(0, 4), 10);
51
+ const month = parseInt(datePart.slice(4, 6), 10);
52
+ const day = parseInt(datePart.slice(6, 8), 10);
52
53
  const date = new Date(year, month - 1, day);
53
54
  if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
54
- throw new Error(`config.schemaLock must be a valid date. Received: ${JSON.stringify(config.schemaLock)}`);
55
+ throw new Error(`config.schemaLock must contain a valid date. Received: ${JSON.stringify(config.schemaLock)}`);
55
56
  }
56
57
  // Must be at least 20241009
57
- if (config.schemaLock < "20241009") {
58
- throw new Error(`config.schemaLock must be a date string equal to or greater than "20241009". Received: ${JSON.stringify(config.schemaLock)}`);
58
+ if (datePart < "20241009") {
59
+ throw new Error(`config.schemaLock date must be equal to or greater than "20241009". Received: ${JSON.stringify(config.schemaLock)}`);
59
60
  }
60
61
  }
61
62