@reforma/site 1.0.0 → 1.0.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.
@@ -12,6 +12,7 @@ type TrackOptions = {
12
12
  /**
13
13
  * Start first-party pageview collection for a published Reforma site.
14
14
  * Reads the project site config. Only the first call installs history hooks.
15
+ * In the Reforma editor's canvas it reports the address to the editor and counts nothing.
15
16
  */
16
17
  export declare function initAnalytics(config: {
17
18
  analyticsEnabled: boolean;
@@ -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,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"}
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;AAcF;;;;GAIG;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,CAoDN;AAED;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CA6DpE"}
package/dist/analytics.js CHANGED
@@ -1,3 +1,7 @@
1
+ /** The Reforma editor names its canvas iframe this; the site checks it because it cannot see the parent's origin. */
2
+ const EDITOR_FRAME_NAME = 'reforma-editor';
3
+ /** What the editor listens for to follow the site's address. */
4
+ const LOCATION_MESSAGE = 'reforma:location';
1
5
  let started = false;
2
6
  let enabled = false;
3
7
  let writeKey = '';
@@ -7,6 +11,7 @@ let unhook = null;
7
11
  /**
8
12
  * Start first-party pageview collection for a published Reforma site.
9
13
  * Reads the project site config. Only the first call installs history hooks.
14
+ * In the Reforma editor's canvas it reports the address to the editor and counts nothing.
10
15
  */
11
16
  export function initAnalytics(config, options = {}) {
12
17
  if (typeof window === 'undefined') {
@@ -22,6 +27,16 @@ export function initAnalytics(config, options = {}) {
22
27
  return;
23
28
  }
24
29
  started = true;
30
+ if (window.name === EDITOR_FRAME_NAME && window.parent !== window) {
31
+ enabled = false;
32
+ const report = () => {
33
+ // nosemgrep: javascript.browser.security.wildcard-postmessage-configuration.wildcard-postmessage-configuration -- only the page path, and the site cannot know the editor's origin
34
+ window.parent.postMessage({ type: LOCATION_MESSAGE, pathname: window.location.pathname }, '*');
35
+ };
36
+ report();
37
+ unhook = installHistoryHook(report);
38
+ return;
39
+ }
25
40
  enabled = config.analyticsEnabled;
26
41
  writeKey = config.analyticsWriteKey.trim();
27
42
  endpoint = config.analyticsEndpoint.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reforma/site",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Visitor runtime for a Reforma site: publish metadata, analytics, and the PostCSS url guard.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",