ga4-export-fixer 0.1.2 → 0.1.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.
Files changed (3) hide show
  1. package/README.md +11 -4
  2. package/package.json +1 -1
  3. package/utils.js +29 -7
package/README.md CHANGED
@@ -17,13 +17,15 @@ Include the package in the package.json file in your Dataform repository.
17
17
  **`package.json`**
18
18
  ```json
19
19
  {
20
- "name": "my_dataform_repo",
21
20
  "dependencies": {
22
- "@dataform/core": "3.0.39",
23
- "ga4-export-fixer": "0.1.1"
21
+ "@dataform/core": "3.0.42",
22
+ "ga4-export-fixer": "0.1.2"
24
23
  }
25
24
  }
26
25
  ```
26
+
27
+ **Note:** The best practice is to specify the package version explicitly (e.g. `"0.1.2"`) rather than using `"latest"` or `"*"`, to avoid unexpected breaking changes when the package is updated.
28
+
27
29
  In Google Cloud Dataform, click "Install Packages" to install it in your development workspace.
28
30
 
29
31
  If your Dataform repository does not have a package.json file, see this guide: https://docs.cloud.google.com/dataform/docs/manage-repository#move-to-package-json
@@ -95,7 +97,12 @@ const config = {
95
97
  'ga_session_number',
96
98
  'page_type',
97
99
  'user_agent'
98
- ]
100
+ ],
101
+ // use day threshold for data_is_final
102
+ dataIsFinal: {
103
+ detectionMethod: 'DAY_THRESHOLD',
104
+ dayThreshold: 4
105
+ },
99
106
  };
100
107
 
101
108
  ga4EventsEnhanced.createTable(publish, config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.2",
3
+ "version": "0.1.3-dev.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
package/utils.js CHANGED
@@ -105,6 +105,7 @@ const mergeSQLConfigurations = (defaultConfig, inputConfig = {}) => {
105
105
  return defaultConfig;
106
106
  }
107
107
 
108
+ // the merged configuration object
108
109
  const result = { ...defaultConfig };
109
110
 
110
111
  for (const key in inputConfig) {
@@ -170,6 +171,27 @@ const mergeSQLConfigurations = (defaultConfig, inputConfig = {}) => {
170
171
  }
171
172
  }
172
173
 
174
+ // support different formats for passing the sourceTable path
175
+ const fixSourceTable = (sourceTable) => {
176
+ if (isDataformTableReferenceObject(sourceTable)) {
177
+ return sourceTable;
178
+ }
179
+ if (typeof sourceTable === 'string') {
180
+ const tablePath = sourceTable.replace(/[`"']/g, '').trim();
181
+ if (/^[a-zA-Z0-9-]+\.[a-zA-Z0-9_]+(\.[^\.]+)?$/.test(tablePath)) {
182
+ const project = tablePath.split('.')[0];
183
+ const dataset = tablePath.split('.')[1];
184
+ return `\`${project}.${dataset}.events_*\``;
185
+ }
186
+ }
187
+ throw new Error(`sourceTable must be a Dataform table reference or a string in the format '\`project.dataset.table\`'. Received: ${JSON.stringify(sourceTable)}`);
188
+ };
189
+
190
+ // process the sourceTable to support different formats
191
+ if (result.sourceTable) {
192
+ result.sourceTable = fixSourceTable(result.sourceTable);
193
+ }
194
+
173
195
  return result;
174
196
  };
175
197
 
@@ -178,15 +200,15 @@ const mergeSQLConfigurations = (defaultConfig, inputConfig = {}) => {
178
200
  *
179
201
  * A Dataform table reference object is expected to have the properties: 'name', 'project', and 'dataset'.
180
202
  *
181
- * @param {Object} table - The object to check.
203
+ * @param {Object} obj - The object to check.
182
204
  * @returns {boolean} True if the object is a Dataform table reference, false otherwise.
183
205
  */
184
- const isDataformTableReferenceObject = (table) => {
185
- return table &&
186
- typeof table === 'object' &&
187
- Object.hasOwn(table, 'name') &&
188
- Object.hasOwn(table, 'project') &&
189
- Object.hasOwn(table, 'dataset');
206
+ const isDataformTableReferenceObject = (obj) => {
207
+ return obj &&
208
+ typeof obj === 'object' &&
209
+ Object.hasOwn(obj, 'name') &&
210
+ Object.hasOwn(obj, 'project') &&
211
+ Object.hasOwn(obj, 'dataset');
190
212
  };
191
213
 
192
214