@yourbright/emdash-analytics-plugin 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 +151 -0
- package/package.json +57 -0
- package/src/admin.tsx +1138 -0
- package/src/config-validation.ts +153 -0
- package/src/config.ts +90 -0
- package/src/constants.ts +55 -0
- package/src/content.ts +133 -0
- package/src/google.ts +518 -0
- package/src/index.ts +270 -0
- package/src/scoring.ts +83 -0
- package/src/sync.ts +749 -0
- package/src/types.ts +193 -0
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# EmDash Analytics Plugin
|
|
2
|
+
|
|
3
|
+
Google Search Console and GA4 analytics plugin for EmDash.
|
|
4
|
+
|
|
5
|
+
This plugin provides:
|
|
6
|
+
|
|
7
|
+
- site-wide analytics sync for public pages
|
|
8
|
+
- opportunity scoring for managed content
|
|
9
|
+
- admin dashboard pages and widgets inside EmDash
|
|
10
|
+
- read-only agent endpoints protected by plugin-scoped API keys
|
|
11
|
+
|
|
12
|
+
## What It Adds
|
|
13
|
+
|
|
14
|
+
The plugin registers:
|
|
15
|
+
|
|
16
|
+
- admin pages: `Overview`, `Pages`, `Analytics`
|
|
17
|
+
- one dashboard widget: `Content Opportunities`
|
|
18
|
+
- background sync jobs for base metrics and managed query enrichment
|
|
19
|
+
- public agent endpoints under `agent/v1/*`
|
|
20
|
+
|
|
21
|
+
The plugin reads Google Search Console and GA4 data with a Google service account, stores aggregated page metrics in plugin storage, and exposes the scored results in the EmDash admin.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
Install from npm:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@yourbright/emdash-analytics-plugin": "0.1.1"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Then register it in your EmDash integration:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { contentInsightsPlugin } from "@yourbright/emdash-analytics-plugin";
|
|
39
|
+
|
|
40
|
+
emdash({
|
|
41
|
+
database,
|
|
42
|
+
storage,
|
|
43
|
+
plugins: [contentInsightsPlugin()],
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Runtime Requirements
|
|
48
|
+
|
|
49
|
+
This plugin needs:
|
|
50
|
+
|
|
51
|
+
- EmDash plugin capabilities: `network:fetch`, `read:content`
|
|
52
|
+
- outbound access to:
|
|
53
|
+
- `oauth2.googleapis.com`
|
|
54
|
+
- `analyticsdata.googleapis.com`
|
|
55
|
+
- `www.googleapis.com`
|
|
56
|
+
- a worker/runtime secret named `EMDASH_AUTH_SECRET`
|
|
57
|
+
|
|
58
|
+
`EMDASH_AUTH_SECRET` is required because the plugin encrypts the stored Google service account credential before saving it. Without that secret, `Save Settings` fails at runtime.
|
|
59
|
+
|
|
60
|
+
Examples:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
bunx wrangler secret put EMDASH_AUTH_SECRET --config wrangler.staging.jsonc
|
|
64
|
+
bunx wrangler secret put EMDASH_AUTH_SECRET --config wrangler.jsonc
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Use a different secret per environment unless you intentionally need encrypted settings to be portable across environments.
|
|
68
|
+
|
|
69
|
+
## Admin Setup
|
|
70
|
+
|
|
71
|
+
Open the plugin settings page in EmDash and configure:
|
|
72
|
+
|
|
73
|
+
- `Canonical Site Origin`
|
|
74
|
+
- `GA4 Property ID`
|
|
75
|
+
- `Search Console Property`
|
|
76
|
+
- `Service Account JSON`
|
|
77
|
+
|
|
78
|
+
Notes:
|
|
79
|
+
|
|
80
|
+
- `Service Account JSON` is required on the first save.
|
|
81
|
+
- After the first successful save, leaving `Service Account JSON` blank keeps the currently stored credential.
|
|
82
|
+
- If non-secret fields are left blank during an update, the plugin keeps the previously saved values.
|
|
83
|
+
|
|
84
|
+
After saving:
|
|
85
|
+
|
|
86
|
+
1. Run `Test Connection`
|
|
87
|
+
2. Run `Run Manual Sync`
|
|
88
|
+
3. Check `Overview` and `Pages`
|
|
89
|
+
|
|
90
|
+
## Authentication Model
|
|
91
|
+
|
|
92
|
+
This plugin intentionally uses its own API keys for `agent/v1/*`.
|
|
93
|
+
|
|
94
|
+
- Plugin keys are created in the Analytics settings page
|
|
95
|
+
- Raw tokens use the prefix `yb_ins_`
|
|
96
|
+
- They are independent from EmDash core PAT/OAuth tokens
|
|
97
|
+
|
|
98
|
+
This means:
|
|
99
|
+
|
|
100
|
+
- EmDash admin/private plugin routes use EmDash auth
|
|
101
|
+
- public analytics agent routes use plugin-scoped tokens
|
|
102
|
+
|
|
103
|
+
## Agent API
|
|
104
|
+
|
|
105
|
+
Public read-only endpoints:
|
|
106
|
+
|
|
107
|
+
- `GET /_emdash/api/plugins/emdash-google-analytics-dashboard/agent/v1/site-summary`
|
|
108
|
+
- `GET /_emdash/api/plugins/emdash-google-analytics-dashboard/agent/v1/opportunities?limit=50`
|
|
109
|
+
- `GET /_emdash/api/plugins/emdash-google-analytics-dashboard/agent/v1/content-context?collection=posts&id=<id>`
|
|
110
|
+
|
|
111
|
+
Send either:
|
|
112
|
+
|
|
113
|
+
```http
|
|
114
|
+
Authorization: AgentKey yb_ins_...
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
or:
|
|
118
|
+
|
|
119
|
+
```http
|
|
120
|
+
X-Emdash-Agent-Key: yb_ins_...
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Development
|
|
124
|
+
|
|
125
|
+
From this package directory:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
npm test
|
|
129
|
+
npm run typecheck
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## YourBright Integration Notes
|
|
133
|
+
|
|
134
|
+
In this repo, the plugin is consumed from `landing-page/apps/blog-site/astro.config.mjs`.
|
|
135
|
+
|
|
136
|
+
Operational details for this repo:
|
|
137
|
+
|
|
138
|
+
- the blog app should depend on the published npm version of this plugin
|
|
139
|
+
- local plugin edits are not picked up by a normal blog deploy unless the dependency ref is updated or the package is locally overridden during build
|
|
140
|
+
- staging and production workers both need `EMDASH_AUTH_SECRET`
|
|
141
|
+
|
|
142
|
+
Blog deploy commands live in `landing-page/package.json`:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
bun run deploy:blog:staging
|
|
146
|
+
bun run deploy:blog
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Status
|
|
150
|
+
|
|
151
|
+
Initial implementation for YourBright. The package metadata is ready for public npm release, but npm credentials still need to be configured on this machine before publish.
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yourbright/emdash-analytics-plugin",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Google Search Console and GA4 analytics plugin for EmDash",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./admin": "./src/admin.tsx"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"keywords": [
|
|
16
|
+
"emdash",
|
|
17
|
+
"plugin",
|
|
18
|
+
"analytics",
|
|
19
|
+
"google-search-console",
|
|
20
|
+
"ga4"
|
|
21
|
+
],
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/yourbright-jp/emdash-analytics-plugin.git"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@cloudflare/kumo": "^1.0.0",
|
|
32
|
+
"@phosphor-icons/react": "^2.1.10",
|
|
33
|
+
"astro": ">=6.0.0",
|
|
34
|
+
"emdash": "0.1.0",
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@emdash-cms/auth": "^0.1.0",
|
|
39
|
+
"ulidx": "^2.4.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@cloudflare/kumo": "^1.0.0",
|
|
43
|
+
"@phosphor-icons/react": "^2.1.10",
|
|
44
|
+
"@types/node": "^24.6.0",
|
|
45
|
+
"@types/react": "^19.2.13",
|
|
46
|
+
"astro": "^6.0.1",
|
|
47
|
+
"emdash": "^0.1.0",
|
|
48
|
+
"react": "^19.2.0",
|
|
49
|
+
"react-dom": "^19.2.0",
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"vitest": "^3.2.4"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"test": "vitest run",
|
|
55
|
+
"typecheck": "tsc --noEmit"
|
|
56
|
+
}
|
|
57
|
+
}
|