@reforma/site 0.0.3 → 0.0.5
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/dist/analytics.d.ts +13 -6
- package/dist/analytics.d.ts.map +1 -1
- package/dist/analytics.js +33 -20
- package/dist/metadata.d.ts +7 -2
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +7 -7
- package/package.json +1 -1
package/dist/analytics.d.ts
CHANGED
|
@@ -4,17 +4,24 @@ type AnalyticsOptions = {
|
|
|
4
4
|
/** Default false — skip localhost / 127.0.0.1. */
|
|
5
5
|
captureOnLocalhost?: boolean;
|
|
6
6
|
};
|
|
7
|
-
type
|
|
7
|
+
type TrackOptions = {
|
|
8
8
|
url?: string;
|
|
9
9
|
referrer?: string;
|
|
10
|
+
props?: Record<string, string>;
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
13
|
* Start first-party pageview collection for a published Reforma site.
|
|
13
|
-
* Reads
|
|
14
|
-
* multiple times — only the first call installs history hooks.
|
|
14
|
+
* Reads the project site config. Only the first call installs history hooks.
|
|
15
15
|
*/
|
|
16
|
-
export declare function initAnalytics(
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
export declare function initAnalytics(config: {
|
|
17
|
+
analyticsEnabled: boolean;
|
|
18
|
+
analyticsWriteKey: string;
|
|
19
|
+
analyticsEndpoint: string;
|
|
20
|
+
}, options?: AnalyticsOptions): void;
|
|
21
|
+
/**
|
|
22
|
+
* Send a named event. `pageview` is traffic (deduped by path); any other name
|
|
23
|
+
* is a custom event / goal conversion. Optional `props` are string key/values.
|
|
24
|
+
*/
|
|
25
|
+
export declare function track(name: string, options?: TrackOptions): void;
|
|
19
26
|
export {};
|
|
20
27
|
//# sourceMappingURL=analytics.d.ts.map
|
package/dist/analytics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACpB,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,
|
|
1
|
+
{"version":3,"file":"analytics.d.ts","sourceRoot":"","sources":["../src/analytics.ts"],"names":[],"mappings":"AAAA,KAAK,gBAAgB,GAAG;IACpB,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,kDAAkD;IAClD,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,KAAK,YAAY,GAAG;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC,CAAC;AASF;;;GAGG;AACH,wBAAgB,aAAa,CACzB,MAAM,EAAE;IAAE,gBAAgB,EAAE,OAAO,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,EAC3F,OAAO,GAAE,gBAAqB,GAC/B,IAAI,CAqCN;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CA6DpE"}
|
package/dist/analytics.js
CHANGED
|
@@ -6,10 +6,9 @@ let lastPath = '';
|
|
|
6
6
|
let unhook = null;
|
|
7
7
|
/**
|
|
8
8
|
* Start first-party pageview collection for a published Reforma site.
|
|
9
|
-
* Reads
|
|
10
|
-
* multiple times — only the first call installs history hooks.
|
|
9
|
+
* Reads the project site config. Only the first call installs history hooks.
|
|
11
10
|
*/
|
|
12
|
-
export function initAnalytics(options = {}) {
|
|
11
|
+
export function initAnalytics(config, options = {}) {
|
|
13
12
|
if (typeof window === 'undefined') {
|
|
14
13
|
return;
|
|
15
14
|
}
|
|
@@ -23,9 +22,9 @@ export function initAnalytics(options = {}) {
|
|
|
23
22
|
return;
|
|
24
23
|
}
|
|
25
24
|
started = true;
|
|
26
|
-
enabled =
|
|
27
|
-
writeKey =
|
|
28
|
-
endpoint =
|
|
25
|
+
enabled = config.analyticsEnabled;
|
|
26
|
+
writeKey = config.analyticsWriteKey.trim();
|
|
27
|
+
endpoint = config.analyticsEndpoint.trim();
|
|
29
28
|
if (!enabled || !writeKey || !endpoint) {
|
|
30
29
|
enabled = false;
|
|
31
30
|
return;
|
|
@@ -39,25 +38,39 @@ export function initAnalytics(options = {}) {
|
|
|
39
38
|
track('pageview');
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Send a named event. `pageview` is traffic (deduped by path); any other name
|
|
43
|
+
* is a custom event / goal conversion. Optional `props` are string key/values.
|
|
44
|
+
*/
|
|
45
|
+
export function track(name, options = {}) {
|
|
46
|
+
if (!enabled || typeof window === 'undefined') {
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
if (path === lastPath) {
|
|
49
|
+
const eventName = name.trim();
|
|
50
|
+
if (!eventName) {
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
|
-
|
|
53
|
-
const
|
|
53
|
+
const url = options.url ?? window.location.href;
|
|
54
|
+
const path = pathOf(url);
|
|
55
|
+
if (eventName === 'pageview') {
|
|
56
|
+
if (path === lastPath) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
lastPath = path;
|
|
60
|
+
}
|
|
61
|
+
const payload = {
|
|
54
62
|
key: writeKey,
|
|
63
|
+
name: eventName,
|
|
55
64
|
url,
|
|
56
|
-
referrer:
|
|
57
|
-
}
|
|
65
|
+
referrer: options.referrer ?? (document.referrer || undefined),
|
|
66
|
+
};
|
|
67
|
+
if (eventName !== 'pageview' && options.props && typeof options.props === 'object') {
|
|
68
|
+
payload.props = options.props;
|
|
69
|
+
}
|
|
70
|
+
const bodyText = JSON.stringify(payload);
|
|
58
71
|
const body = typeof Blob === 'undefined'
|
|
59
|
-
?
|
|
60
|
-
: new Blob([
|
|
72
|
+
? bodyText
|
|
73
|
+
: new Blob([bodyText], { type: 'application/json' });
|
|
61
74
|
try {
|
|
62
75
|
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
|
63
76
|
const ok = navigator.sendBeacon(endpoint, body);
|
|
@@ -67,7 +80,7 @@ export function track(name, props = {}) {
|
|
|
67
80
|
}
|
|
68
81
|
void fetch(endpoint, {
|
|
69
82
|
method: 'POST',
|
|
70
|
-
body:
|
|
83
|
+
body: bodyText,
|
|
71
84
|
headers: { 'Content-Type': 'application/json' },
|
|
72
85
|
keepalive: true,
|
|
73
86
|
mode: 'cors',
|
|
@@ -113,6 +126,6 @@ function pathOf(url) {
|
|
|
113
126
|
return new URL(url, window.location.origin).pathname;
|
|
114
127
|
}
|
|
115
128
|
catch {
|
|
116
|
-
return
|
|
129
|
+
return '/';
|
|
117
130
|
}
|
|
118
131
|
}
|
package/dist/metadata.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export declare function projectMetadata(
|
|
1
|
+
export declare function projectMetadata(defaults: {
|
|
2
2
|
title: string;
|
|
3
3
|
description: string;
|
|
4
|
+
}, config: {
|
|
5
|
+
faviconUrl: string;
|
|
6
|
+
indexingEnabled: boolean;
|
|
4
7
|
}): {
|
|
5
8
|
title: {
|
|
6
9
|
template: string;
|
|
@@ -18,7 +21,9 @@ export declare function projectMetadata(fallback: {
|
|
|
18
21
|
follow: boolean;
|
|
19
22
|
};
|
|
20
23
|
};
|
|
21
|
-
export declare function projectRobots(
|
|
24
|
+
export declare function projectRobots(config: {
|
|
25
|
+
indexingEnabled: boolean;
|
|
26
|
+
}): {
|
|
22
27
|
rules: {
|
|
23
28
|
userAgent: string;
|
|
24
29
|
disallow: string;
|
package/dist/metadata.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe,CAC3B,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EAChD,MAAM,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,OAAO,CAAA;CAAE;;QAOhD,QAAQ;QACR,OAAO;;;;QAIP,IAAI;;;;;;;;;EAQf;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE;IAAE,eAAe,EAAE,OAAO,CAAA;CAAE;IAI1D,KAAK;;;;;;;EAKZ"}
|
package/dist/metadata.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export function projectMetadata(
|
|
2
|
-
const faviconUrl =
|
|
3
|
-
const indexingOn =
|
|
1
|
+
export function projectMetadata(defaults, config) {
|
|
2
|
+
const faviconUrl = config.faviconUrl || '/favicon.svg';
|
|
3
|
+
const indexingOn = config.indexingEnabled;
|
|
4
4
|
return {
|
|
5
5
|
title: {
|
|
6
6
|
template: '%s',
|
|
7
|
-
default:
|
|
7
|
+
default: defaults.title,
|
|
8
8
|
},
|
|
9
|
-
description:
|
|
9
|
+
description: defaults.description,
|
|
10
10
|
icons: {
|
|
11
11
|
icon: faviconUrl.endsWith('.svg')
|
|
12
12
|
? { url: faviconUrl, type: 'image/svg+xml' }
|
|
@@ -17,8 +17,8 @@ export function projectMetadata(fallback) {
|
|
|
17
17
|
: { index: false, follow: false },
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
export function projectRobots() {
|
|
21
|
-
const blocked =
|
|
20
|
+
export function projectRobots(config) {
|
|
21
|
+
const blocked = !config.indexingEnabled;
|
|
22
22
|
return {
|
|
23
23
|
rules: {
|
|
24
24
|
userAgent: '*',
|