@riebeckite/plugin-analytics 0.0.31 → 0.0.32

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
@@ -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. Riebeckite's current static document navigation needs
64
- no SPA route hooks; SPA navigation is not tracked automatically.
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
package/README_ja.md CHANGED
@@ -44,7 +44,7 @@ Core の安定コンテンツ ID(frontmatter の `id`)がある公開コン
44
44
  }
45
45
  ```
46
46
 
47
- `path` と `lang` は補助情報であり、ID ではありません。安定 ID のないコンテンツは誤って計測しません。ビルド時・SSR 時は何もせず、同じドキュメント内での初期化も冪等です。現行リポジトリは静的なドキュメント遷移のため SPA フックは追加しておらず、SPA 遷移は自動計測しません。
47
+ `path` と `lang` は補助情報であり、ID ではありません。安定 ID のないコンテンツは誤って計測しません。ビルド時・SSR 時は何もせず、同じドキュメント内での初期化も冪等です。SPA ナビゲーションを有効にした場合は、成功した Route Transition ごとに追加で Event を送信します。
48
48
 
49
49
  コンテンツ ID は執筆側の責務です。公開ノート間での `id` の重複は [`@riebeckite/plugin-diagnostics`](../diagnostics/README_ja.md) が報告し(`duplicate-content-id` / `invalid-content-id`)、プラグイン自身の `validateAnalyticsOptions` が `check` 時に検証します。
50
50
 
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(config) {
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 contentId = document.querySelector(`[${ANALYTICS_CONTENT_ID_ATTRIBUTE}]`)?.getAttribute(ANALYTICS_CONTENT_ID_ATTRIBUTE);
9
- if (!contentId) return;
10
- const event = {
11
- type: "page_view",
12
- contentId,
13
- occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
14
- path: window.location.pathname,
15
- ...document.documentElement.lang ? { lang: document.documentElement.lang } : {}
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
- void sendAnalyticsEvent(config.collectorUrl, event);
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.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(config) {
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 contentId = document.querySelector(`[${ANALYTICS_CONTENT_ID_ATTRIBUTE}]`)?.getAttribute(ANALYTICS_CONTENT_ID_ATTRIBUTE);
16
- if (!contentId) return;
17
- const event = {
18
- type: "page_view",
19
- contentId,
20
- occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
21
- path: window.location.pathname,
22
- ...document.documentElement.lang ? { lang: document.documentElement.lang } : {}
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
- void sendAnalyticsEvent(config.collectorUrl, event);
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 }) => {
@@ -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
- export declare function initAnalytics(config: AnalyticsPublicConfig): void;
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.31",
3
+ "version": "0.0.32",
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.31"
23
+ "@riebeckite/core": "0.0.32"
24
24
  },
25
25
  "devDependencies": {
26
26
  "tsx": "^4.22.4"