ga4-export-fixer 0.1.0 → 0.1.1-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.
package/README.md CHANGED
@@ -0,0 +1,107 @@
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
+ ```json
18
+ {
19
+ "name": "my_dataform_repo",
20
+ "dependencies": {
21
+ "@dataform/core": "3.0.39",
22
+ "ga4-export-fixer": "0.1.0"
23
+ }
24
+ }
25
+ ```
26
+ In Google Cloud Dataform, click "Install Packages" to install it in your development workspace.
27
+
28
+ 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
29
+
30
+ ## Usage
31
+
32
+ ### Create GA4 Events Enhanced Table
33
+
34
+ Creates an **enhanced** version of the GA4 BigQuery export (daily & intraday).
35
+
36
+ The main features include:
37
+
38
+ - **Best available data at any time** – Combines daily (processed) and intraday exports so the most complete, accurate version of the data is always available
39
+ - **Robust incremental updates** – Run on any schedule (daily, hourly, or custom)
40
+ - **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
41
+ - **Event parameter handling** – Promote event params to columns; include or exclude by name
42
+ - **Session parameters** – Promote selected event parameters as session-level parameters
43
+
44
+ #### JS Deployment (Recommended)
45
+
46
+ Create a new **ga4_events_enhanced** table using a **.js** file in your repository's **definitions** folder.
47
+
48
+ ```javascript:definitions/ga4/ga4_events_enhanced.js
49
+ const { ga4EventsEnhanced } = require('ga4-export-fixer');
50
+
51
+ const config = {
52
+ sourceTable: constants.GA4_TABLES.MY_GA4_EXPORT
53
+ };
54
+
55
+ // Create a Dataform table (inside a JS file)
56
+ ga4EventsEnhanced.createTable(publish, config);
57
+ ```
58
+
59
+ #### SQLX Deployment
60
+
61
+ Alternatively, you can create the **ga4_events_enhanced** table using a .SQLX file.
62
+
63
+ ```javascript:definitions/ga4/ga4_events_enhanced.sqlx
64
+ config {
65
+ type: "incremental",
66
+ description: "GA4 Events Enhanced table",
67
+ schema: "ga4",
68
+ bigquery: {
69
+ partitionBy: "event_date",
70
+ clusterBy: ['event_name', 'session_id', 'page_location', 'data_is_final'],
71
+ },
72
+ tags: ['ga4_export_fixer']
73
+ }
74
+
75
+ js {
76
+ const { ga4EventsEnhanced } = require('ga4-export-fixer');
77
+
78
+ const config = {
79
+ sourceTable: ref(constants.GA4_TABLES.TANELYTICS_GA4),
80
+ self: self(),
81
+ incremental: incremental()
82
+ };
83
+ }
84
+
85
+ ${ga4EventsEnhanced.generateSql(config)}
86
+
87
+ pre_operations {
88
+ ${ga4EventsEnhanced.setPreOperations(config)}
89
+ }
90
+ ```
91
+
92
+ ### Helpers
93
+
94
+ The helpers contain templates for common SQL expression needed when working with GA4 data.
95
+
96
+ ```javascript
97
+ const { helpers } = require('ga4-export-fixer');
98
+
99
+ // Unnest event parameters, date filters, URL extraction, session aggregation, etc.
100
+ helpers.unnestEventParam('page_location', 'string');
101
+ helpers.ga4ExportDateFilter('daily', 'current_date()-7', 'current_date()');
102
+ helpers.extractPageDetails();
103
+ ```
104
+
105
+ ## License
106
+
107
+ 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-dev.0",
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
  }