ga4-export-fixer 0.1.0 → 0.1.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/README.md CHANGED
@@ -0,0 +1,109 @@
1
+ # ga4-export-fixer
2
+
3
+ Helpers and table definitions for processing GA4 (Google Analytics 4) BigQuery export data in **Dataform**.
4
+
5
+ ## Installation
6
+
7
+ ### Bash
8
+
9
+ ```bash
10
+ npm install ga4-export-fixer
11
+ ```
12
+
13
+ ### In Google Cloud Dataform
14
+
15
+ Include the package in the package.json file in your Dataform repository.
16
+
17
+ **`package.json`**
18
+ ```json
19
+ {
20
+ "name": "my_dataform_repo",
21
+ "dependencies": {
22
+ "@dataform/core": "3.0.39",
23
+ "ga4-export-fixer": "0.1.0"
24
+ }
25
+ }
26
+ ```
27
+ In Google Cloud Dataform, click "Install Packages" to install it in your development workspace.
28
+
29
+ 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
30
+
31
+ ## Usage
32
+
33
+ ### Create GA4 Events Enhanced Table
34
+
35
+ Creates an **enhanced** version of the GA4 BigQuery export (daily & intraday).
36
+
37
+ The main features include:
38
+
39
+ - **Best available data at any time** – Combines daily (processed) and intraday exports so the most complete, accurate version of the data is always available
40
+ - **Robust incremental updates** – Run on any schedule (daily, hourly, or custom)
41
+ - **Flexible schema, better optimized for analysis** – Keeps the flexible structure of the original export while promoting key fields (e.g. `page_location`, `session_id`) to columns for faster queries; **partitioning and clustering** enabled
42
+ - **Event parameter handling** – Promote event params to columns; include or exclude by name
43
+ - **Session parameters** – Promote selected event parameters as session-level parameters
44
+
45
+ #### JS Deployment (Recommended)
46
+
47
+ Create a new **ga4_events_enhanced** table using a **.js** file in your repository's **definitions** folder.
48
+
49
+ **`definitions/ga4/ga4_events_enhanced.js`**
50
+ ```javascript
51
+ const { ga4EventsEnhanced } = require('ga4-export-fixer');
52
+
53
+ const config = {
54
+ sourceTable: constants.GA4_TABLES.MY_GA4_EXPORT
55
+ };
56
+
57
+ ga4EventsEnhanced.createTable(publish, config);
58
+ ```
59
+
60
+ #### SQLX Deployment
61
+
62
+ Alternatively, you can create the **ga4_events_enhanced** table using a .SQLX file.
63
+
64
+ **`definitions/ga4/ga4_events_enhanced.sqlx`**
65
+ ```javascript
66
+ config {
67
+ type: "incremental",
68
+ description: "GA4 Events Enhanced table",
69
+ schema: "ga4",
70
+ bigquery: {
71
+ partitionBy: "event_date",
72
+ clusterBy: ['event_name', 'session_id', 'page_location', 'data_is_final'],
73
+ },
74
+ tags: ['ga4_export_fixer']
75
+ }
76
+
77
+ js {
78
+ const { ga4EventsEnhanced } = require('ga4-export-fixer');
79
+
80
+ const config = {
81
+ sourceTable: ref(constants.GA4_TABLES.MY_GA4_EXPORT),
82
+ self: self(),
83
+ incremental: incremental()
84
+ };
85
+ }
86
+
87
+ ${ga4EventsEnhanced.generateSql(config)}
88
+
89
+ pre_operations {
90
+ ${ga4EventsEnhanced.setPreOperations(config)}
91
+ }
92
+ ```
93
+
94
+ ### Helpers
95
+
96
+ The helpers contain templates for common SQL expression needed when working with GA4 data.
97
+
98
+ ```javascript
99
+ const { helpers } = require('ga4-export-fixer');
100
+
101
+ // Unnest event parameters, date filters, URL extraction, session aggregation, etc.
102
+ helpers.unnestEventParam('page_location', 'string');
103
+ helpers.ga4ExportDateFilter('daily', 'current_date()-7', 'current_date()');
104
+ helpers.extractPageDetails();
105
+ ```
106
+
107
+ ## License
108
+
109
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ga4-export-fixer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -372,9 +372,13 @@ ${excludedEventsSQL}`,
372
372
  const createEnhancedEventsTable = (dataformPublish, config) => {
373
373
  const mergedConfig = utils.mergeSQLConfigurations(defaultConfig, config);
374
374
 
375
- const tableDescription = `GA4 Events Enhanced
376
-
377
- This table is created by the ga4-export-fixer package.`;
375
+ const tableDescription = `GA4 Events Enhanced
376
+
377
+ - Combines daily (processed) and intraday exports so the best available version of each event is always used.
378
+ - Key fields such as page_location and session_id are promoted to columns for faster queries.
379
+ - Supports incremental updates on any schedule.
380
+
381
+ Created by the ga4-export-fixer package.`;
378
382
 
379
383
  // the defaults for the dataform table config
380
384
  const defaultDataformTableConfig = {
@@ -438,8 +442,15 @@ This table is created by the ga4-export-fixer package.`;
438
442
 
439
443
  };
440
444
 
445
+ // provide a merged config for the pre operations
446
+ // required for the .sqlx deployment
447
+ const setPreOperations = (config) => {
448
+ const mergedConfig = utils.mergeSQLConfigurations(defaultConfig, config);
449
+ return preOperations.setPreOperations(mergedConfig);
450
+ };
451
+
441
452
  module.exports = {
442
453
  generateSql: generateEnhancedEventsSQL,
443
454
  createTable: createEnhancedEventsTable,
444
- setPreOperations: preOperations.setPreOperations
455
+ setPreOperations: setPreOperations
445
456
  }