@riebeckite/plugin-analytics 0.0.31 → 0.0.33
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 +3 -3
- package/README_ja.md +11 -11
- package/dist/client.js +18 -10
- package/dist/index.d.ts +0 -1
- package/dist/index.js +21 -13
- package/dist/src/init.d.ts +5 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -60,8 +60,8 @@ In a browser, the initializer sends exactly one event per document:
|
|
|
60
60
|
|
|
61
61
|
`path` and `lang` are contextual metadata, not identity. Content without a
|
|
62
62
|
stable ID is not tracked. The initializer is a no-op during builds/SSR and is
|
|
63
|
-
idempotent in a document.
|
|
64
|
-
|
|
63
|
+
idempotent in a document. With SPA navigation enabled, the plugin sends another
|
|
64
|
+
event after each successful route transition.
|
|
65
65
|
|
|
66
66
|
Content IDs are an authoring responsibility. Duplicate `id` declarations across
|
|
67
67
|
published notes are reported by
|
|
@@ -92,7 +92,7 @@ diagnostics.
|
|
|
92
92
|
|
|
93
93
|
## Exports
|
|
94
94
|
|
|
95
|
-
- `analytics()` / `
|
|
95
|
+
- `analytics()` / `analytics()`
|
|
96
96
|
- `initAnalytics` (`@riebeckite/plugin-analytics/client`)
|
|
97
97
|
- `MemoryAnalyticsProvider`
|
|
98
98
|
- Event, query/result, provider/capability, and public-config types
|
package/README_ja.md
CHANGED
|
@@ -8,10 +8,10 @@ Riebeckite 向けの、ストレージや実行環境に依存しないアクセ
|
|
|
8
8
|
|
|
9
9
|
## 設計
|
|
10
10
|
|
|
11
|
-
- `AnalyticsEvent` は型付きの `page_view`
|
|
12
|
-
- `AnalyticsProvider`
|
|
13
|
-
-
|
|
14
|
-
-
|
|
11
|
+
- `AnalyticsEvent` は型付きの `page_view` を持ち、プロバイダ固有のイベント型を加えた union 型へ拡張できます。
|
|
12
|
+
- `AnalyticsProvider` は対応する機能(capability)を明示し、`capture` と `query` を提供します。クエリはコンテンツ別のページビューと人気コンテンツを対象にし、ISO 8601 形式の期間を任意で指定できます。
|
|
13
|
+
- 未対応のクエリは `UnsupportedAnalyticsQueryError` で明示されます。テストやローカル用途には `MemoryAnalyticsProvider` を用意しています。
|
|
14
|
+
- 認証情報・ストレージ・ランタイムバインディングなどのプロバイダ設定は、プロバイダの内部に留まります。ブラウザへ渡すのは `AnalyticsPublicConfig` だけです。
|
|
15
15
|
|
|
16
16
|
## 使い方
|
|
17
17
|
|
|
@@ -28,11 +28,11 @@ export default {
|
|
|
28
28
|
};
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
`collectorUrl` は公開してよい収集先 URL です。相対パスまたは HTTP(S) URL を指定し、JSON の `POST`
|
|
31
|
+
`collectorUrl` は公開してよい収集先 URL です。相対パスまたは HTTP(S) URL を指定し、JSON の `POST` を受け付けるコレクターを用意します。将来のプロバイダパッケージは、非公開のランタイム設定を使ってこのコレクターを提供できます。
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## ブラウザでの計測
|
|
34
34
|
|
|
35
|
-
Core の安定コンテンツ ID(frontmatter の `id
|
|
35
|
+
Core の安定コンテンツ ID(frontmatter の `id`)を持つ公開コンテンツにだけ、コンテンツ ID を示すマーカーを出力します。汎用の `publicConfig` 経由で登録された `initAnalytics` は、ブラウザでドキュメントごとに一度だけ次のようなイベントを送ります。
|
|
36
36
|
|
|
37
37
|
```json
|
|
38
38
|
{
|
|
@@ -44,9 +44,9 @@ Core の安定コンテンツ ID(frontmatter の `id`)がある公開コン
|
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
`path` と `lang`
|
|
47
|
+
`path` と `lang` は補助的なメタデータであり、ID ではありません。安定 ID を持たないコンテンツは計測しません。ビルド時と SSR 時は何もせず、同じドキュメント内での初期化も冪等です。SPA ナビゲーションを有効にすると、ルート遷移が成功するたびに追加のイベントを送信します。
|
|
48
48
|
|
|
49
|
-
コンテンツ ID
|
|
49
|
+
コンテンツ ID は執筆側の責務です。公開ノート間で `id` が重複している場合は [`@riebeckite/plugin-diagnostics`](../diagnostics/README_ja.md) が報告し(`duplicate-content-id` / `invalid-content-id`)、プラグイン自身の `validateAnalyticsOptions` が `check` 時に検証します。
|
|
50
50
|
|
|
51
51
|
## プロバイダの取り決め
|
|
52
52
|
|
|
@@ -62,11 +62,11 @@ const result = await provider.query({
|
|
|
62
62
|
|
|
63
63
|
## 診断
|
|
64
64
|
|
|
65
|
-
`@riebeckite/plugin-diagnostics`
|
|
65
|
+
`@riebeckite/plugin-diagnostics` は、サイトで本プラグインが有効なとき、安定コンテンツ ID を持たない公開コンテンツを `analytics-untracked` として報告します。計測の抜けは `check` / `doctor` / ビルドの診断で確認できます。
|
|
66
66
|
|
|
67
67
|
## 主なエクスポート
|
|
68
68
|
|
|
69
|
-
- `analytics()` / `
|
|
69
|
+
- `analytics()` / `analytics()`
|
|
70
70
|
- `initAnalytics`(`@riebeckite/plugin-analytics/client`)
|
|
71
71
|
- `MemoryAnalyticsProvider`
|
|
72
72
|
- イベント、クエリ/結果、プロバイダ/機能、公開設定の型
|
package/dist/client.js
CHANGED
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
// src/init.ts
|
|
2
2
|
var ANALYTICS_CONTENT_ID_ATTRIBUTE = "data-riebeckite-content-id";
|
|
3
3
|
var INITIALIZED_ATTRIBUTE = "data-riebeckite-analytics-initialized";
|
|
4
|
-
function initAnalytics(
|
|
4
|
+
function initAnalytics({
|
|
5
|
+
config
|
|
6
|
+
}) {
|
|
5
7
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
6
8
|
if (document.documentElement.hasAttribute(INITIALIZED_ATTRIBUTE)) return;
|
|
7
9
|
document.documentElement.setAttribute(INITIALIZED_ATTRIBUTE, "");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const sendPageView = () => {
|
|
11
|
+
const contentId = document.querySelector(`[${ANALYTICS_CONTENT_ID_ATTRIBUTE}]`)?.getAttribute(ANALYTICS_CONTENT_ID_ATTRIBUTE);
|
|
12
|
+
if (!contentId) return;
|
|
13
|
+
const event = {
|
|
14
|
+
type: "page_view",
|
|
15
|
+
contentId,
|
|
16
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17
|
+
path: window.location.pathname,
|
|
18
|
+
...document.documentElement.lang ? { lang: document.documentElement.lang } : {}
|
|
19
|
+
};
|
|
20
|
+
void sendAnalyticsEvent(config.collectorUrl, event);
|
|
16
21
|
};
|
|
17
|
-
|
|
22
|
+
sendPageView();
|
|
23
|
+
if (typeof document.addEventListener !== "function") return;
|
|
24
|
+
document.addEventListener("riebeckite:navigation", sendPageView);
|
|
25
|
+
return () => document.removeEventListener("riebeckite:navigation", sendPageView);
|
|
18
26
|
}
|
|
19
27
|
async function sendAnalyticsEvent(collectorUrl, event) {
|
|
20
28
|
await fetch(collectorUrl, {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -8,20 +8,28 @@ import {
|
|
|
8
8
|
// src/init.ts
|
|
9
9
|
var ANALYTICS_CONTENT_ID_ATTRIBUTE = "data-riebeckite-content-id";
|
|
10
10
|
var INITIALIZED_ATTRIBUTE = "data-riebeckite-analytics-initialized";
|
|
11
|
-
function initAnalytics(
|
|
11
|
+
function initAnalytics({
|
|
12
|
+
config
|
|
13
|
+
}) {
|
|
12
14
|
if (typeof window === "undefined" || typeof document === "undefined") return;
|
|
13
15
|
if (document.documentElement.hasAttribute(INITIALIZED_ATTRIBUTE)) return;
|
|
14
16
|
document.documentElement.setAttribute(INITIALIZED_ATTRIBUTE, "");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const sendPageView = () => {
|
|
18
|
+
const contentId = document.querySelector(`[${ANALYTICS_CONTENT_ID_ATTRIBUTE}]`)?.getAttribute(ANALYTICS_CONTENT_ID_ATTRIBUTE);
|
|
19
|
+
if (!contentId) return;
|
|
20
|
+
const event = {
|
|
21
|
+
type: "page_view",
|
|
22
|
+
contentId,
|
|
23
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
24
|
+
path: window.location.pathname,
|
|
25
|
+
...document.documentElement.lang ? { lang: document.documentElement.lang } : {}
|
|
26
|
+
};
|
|
27
|
+
void sendAnalyticsEvent(config.collectorUrl, event);
|
|
23
28
|
};
|
|
24
|
-
|
|
29
|
+
sendPageView();
|
|
30
|
+
if (typeof document.addEventListener !== "function") return;
|
|
31
|
+
document.addEventListener("riebeckite:navigation", sendPageView);
|
|
32
|
+
return () => document.removeEventListener("riebeckite:navigation", sendPageView);
|
|
25
33
|
}
|
|
26
34
|
async function sendAnalyticsEvent(collectorUrl, event) {
|
|
27
35
|
await fetch(collectorUrl, {
|
|
@@ -146,7 +154,9 @@ function analytics(options) {
|
|
|
146
154
|
"analytics",
|
|
147
155
|
"@riebeckite/plugin-analytics/client",
|
|
148
156
|
"initAnalytics",
|
|
149
|
-
options.publicConfig
|
|
157
|
+
options.publicConfig,
|
|
158
|
+
"app",
|
|
159
|
+
"context"
|
|
150
160
|
)
|
|
151
161
|
],
|
|
152
162
|
onManifestCreated: ({ manifest }) => {
|
|
@@ -156,7 +166,6 @@ function analytics(options) {
|
|
|
156
166
|
}
|
|
157
167
|
});
|
|
158
168
|
}
|
|
159
|
-
var analyticsPlugin = analytics;
|
|
160
169
|
function appendContentIdentity(entry) {
|
|
161
170
|
if (!entry.contentId) return;
|
|
162
171
|
const marker = `<span hidden ${ANALYTICS_CONTENT_ID_ATTRIBUTE}="${escapeHtmlAttribute(entry.contentId)}"></span>`;
|
|
@@ -171,7 +180,6 @@ export {
|
|
|
171
180
|
MemoryAnalyticsProvider,
|
|
172
181
|
UnsupportedAnalyticsQueryError,
|
|
173
182
|
analytics,
|
|
174
|
-
analyticsPlugin,
|
|
175
183
|
assertAnalyticsQuerySupported,
|
|
176
184
|
initAnalytics,
|
|
177
185
|
requiredCapabilityForQuery,
|
package/dist/src/init.d.ts
CHANGED
|
@@ -4,4 +4,8 @@ export declare const ANALYTICS_CONTENT_ID_ATTRIBUTE = "data-riebeckite-content-i
|
|
|
4
4
|
* Sends one document-level page view. Static Riebeckite sites reload documents
|
|
5
5
|
* on navigation; SPA history hooks are intentionally not installed.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type ClientContext = {
|
|
8
|
+
config: AnalyticsPublicConfig;
|
|
9
|
+
};
|
|
10
|
+
export declare function initAnalytics({ config, }: ClientContext): (() => void) | undefined;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-analytics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@riebeckite/core": "0.0.
|
|
23
|
+
"@riebeckite/core": "0.0.33"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"tsx": "^4.22.4"
|