@useairfoil/producer-google-analytics 0.0.1 → 0.0.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 ADDED
@@ -0,0 +1,75 @@
1
+ # Google Analytics producer
2
+
3
+ Syncs daily reports from one Google Analytics 4 property: totals, traffic
4
+ sources, user acquisition, pages, landing pages, events, locations, devices, and
5
+ ecommerce items. It backfills each report day by day and reads recent days
6
+ again, because Google keeps updating them.
7
+
8
+ ## Config
9
+
10
+ | Variable | Required | Default |
11
+ | ------------------ | -------- | ----------- |
12
+ | `GA_PROPERTY_ID` | yes | none |
13
+ | `GA_CLIENT_EMAIL` | yes | none |
14
+ | `GA_PRIVATE_KEY` | yes | none |
15
+ | `GA_START_DATE` | no | 2 years ago |
16
+ | `GA_LOOKBACK_DAYS` | no | 14 |
17
+
18
+ ## Setup
19
+
20
+ 1. In Google Cloud, enable the **Google Analytics Data API** for a project.
21
+ 2. Create a service account in that project. It needs no roles. Add a JSON key
22
+ and download it.
23
+ 3. In Google Analytics, go to Admin > Property access management and add the
24
+ service account's email as a **Viewer**.
25
+ 4. Set `GA_CLIENT_EMAIL` and `GA_PRIVATE_KEY` from `client_email` and
26
+ `private_key` in the key file. The property ID is under Admin > Property
27
+ details.
28
+
29
+ ## Data
30
+
31
+ - One row per day and dimension values. The key is a JSON array of the property
32
+ ID, the day, and the dimension values.
33
+ - Days are in the property's time zone. Today is never read, since its numbers
34
+ are partial.
35
+ - Counts are `long`. Key events, revenue, and durations are `double`. Revenue is
36
+ in `currency_code`.
37
+ - User counts are distinct users, so they don't add up across rows or days. Use
38
+ `daily_overview` for a day's users. Sessions, views, events, and revenue do
39
+ add up.
40
+ - `(not set)`, `(other)`, and empty strings are real values. Google groups rare
41
+ values into `(other)` on large properties, and leaves out rows with few users.
42
+ - When a later read of a day drops a row, the old row stays.
43
+ - A change to the attribution model or other property settings changes past
44
+ numbers. Backfill again to pick it up.
45
+ - Page titles and paths can hold personal data if the site puts it there.
46
+
47
+ ## Limits
48
+
49
+ - A standard property gets 200,000 tokens a day and 40,000 an hour, and 10
50
+ requests at once. The connector sends at most 5 at once. A used-up quota waits
51
+ and tries again.
52
+ - Each run reads the last `GA_LOOKBACK_DAYS` again, every 6 hours. Google says
53
+ data can arrive up to 7 days late, and key event credit can change for 12
54
+ days.
55
+
56
+ ## Demo data
57
+
58
+ `pnpm demo --size 8MiB` writes made-up Google Analytics data without Google
59
+ Analytics credentials. See the Connector Kit README for the flags and the
60
+ variables it needs.
61
+
62
+ Each group is one day of every report, counting back from yesterday, for a
63
+ made-up online store. It stops after two years, about 9 MiB. Traffic sources,
64
+ locations, and devices add up to the day's sessions, and traffic dips at
65
+ weekends.
66
+
67
+ ## Local development
68
+
69
+ ```bash
70
+ cd connectors/producer-google-analytics
71
+ pnpm sandbox
72
+ ```
73
+
74
+ `pnpm start` runs the hosted connector. It needs the Wings and PostgreSQL
75
+ variables from the [Connector Kit README](../../packages/connector-kit/README.md).