@webiny/telemetry 6.6.0-alpha.0 → 6.6.0-alpha.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.
Files changed (3) hide show
  1. package/cli.js +10 -0
  2. package/package.json +2 -2
  3. package/react.js +25 -9
package/cli.js CHANGED
@@ -33,6 +33,15 @@ export const sendEvent = async ({ event, version, properties }) => {
33
33
  installationProperties.installation_id = installationId;
34
34
  }
35
35
 
36
+ // Which hosting type the project runs on ("aws" or "server"). Both CLI bins set this marker at
37
+ // startup (`cli-aws/src/bin.ts`, `cli-server/src/bin.ts`), so every CLI event can be segmented
38
+ // by hosting type without each call site passing it along. Omitted when unset rather than
39
+ // defaulted to "aws", because a missing marker means an unknown caller, not an AWS project.
40
+ const hostingTypeProperties = {};
41
+ if (process.env.WEBINY_HOSTING_TYPE) {
42
+ hostingTypeProperties.hostingType = process.env.WEBINY_HOSTING_TYPE;
43
+ }
44
+
36
45
  const packageJsonPath = path.join(import.meta.dirname, "package.json");
37
46
  const packageJson = loadJsonFileSync(packageJsonPath);
38
47
 
@@ -42,6 +51,7 @@ export const sendEvent = async ({ event, version, properties }) => {
42
51
  ...properties,
43
52
  ...wcpProperties,
44
53
  ...installationProperties,
54
+ ...hostingTypeProperties,
45
55
  version: version || packageJson.version,
46
56
  ci: isCI,
47
57
  newUser: Boolean(globalConfig.get("newUser"))
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@webiny/telemetry",
3
- "version": "6.6.0-alpha.0",
3
+ "version": "6.6.0-alpha.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@webiny/global-config": "6.6.0-alpha.0",
7
+ "@webiny/global-config": "6.6.0-alpha.1",
8
8
  "@webiny/wts-client": "3.1.4",
9
9
  "ci-info": "4.4.0",
10
10
  "jsesc": "3.1.0",
package/react.js CHANGED
@@ -2,10 +2,12 @@ import baseSendEvent from "./sendEvent.js";
2
2
  import { WTS } from "@webiny/wts-client/web";
3
3
 
4
4
  const STORAGE_MACHINE_ID = "wts_machine_id";
5
- const STORAGE_PROJECT_ID = "wts_project_id";
5
+ // Storage key kept as-is: ids persisted by earlier versions still live under it, and renaming the
6
+ // key would silently mint a new installation id for every existing admin session.
7
+ const STORAGE_INSTALLATION_ID = "wts_project_id";
6
8
 
7
9
  let wtsInstance = null;
8
- let projectId = null;
10
+ let installationId = null;
9
11
  let distinctId = null;
10
12
 
11
13
  /**
@@ -17,14 +19,16 @@ let distinctId = null;
17
19
  * 3. `process.env.REACT_APP_WEBINY_TELEMETRY_USER_ID` (build-time fallback,
18
20
  * set by `SetAdminAppEnvVarsBefore{Build,Watch}` from `~/.webiny/config`).
19
21
  *
20
- * Priority for `project_id` (installation_id):
22
+ * Priority for `installation_id`:
21
23
  * 1. URL param `iid` on first load. Persisted to localStorage.
22
24
  * 2. localStorage.
23
25
  * 3. `process.env.REACT_APP_WEBINY_INSTALLATION_ID` (build-time fallback,
24
26
  * set from `<project>/package.json` → `webiny.installationId`).
25
27
  *
26
28
  * Attached as a super-property on every admin event so PostHog funnels can
27
- * group per-install.
29
+ * group per-install. The property name matches the one the CLI sends
30
+ * (`telemetry/cli.js`) so CLI and admin events for the same project join on a
31
+ * single property.
28
32
  */
29
33
  const initWts = () => {
30
34
  if (wtsInstance) {
@@ -32,7 +36,7 @@ const initWts = () => {
32
36
  }
33
37
 
34
38
  distinctId = process.env.REACT_APP_WEBINY_TELEMETRY_USER_ID;
35
- projectId = process.env.REACT_APP_WEBINY_INSTALLATION_ID || null;
39
+ installationId = process.env.REACT_APP_WEBINY_INSTALLATION_ID || null;
36
40
 
37
41
  if (typeof window !== "undefined") {
38
42
  const params = new URLSearchParams(window.location.search);
@@ -55,15 +59,16 @@ const initWts = () => {
55
59
 
56
60
  const iidFromUrl = params.get("iid");
57
61
  if (iidFromUrl) {
58
- projectId = iidFromUrl;
62
+ installationId = iidFromUrl;
59
63
  try {
60
- window.localStorage.setItem(STORAGE_PROJECT_ID, iidFromUrl);
64
+ window.localStorage.setItem(STORAGE_INSTALLATION_ID, iidFromUrl);
61
65
  } catch {
62
66
  // ignore
63
67
  }
64
68
  } else {
65
69
  try {
66
- projectId = window.localStorage.getItem(STORAGE_PROJECT_ID) || projectId;
70
+ installationId =
71
+ window.localStorage.getItem(STORAGE_INSTALLATION_ID) || installationId;
67
72
  } catch {
68
73
  // env-var value (set above) is used as fallback.
69
74
  }
@@ -98,12 +103,23 @@ export const sendEvent = async (event, properties = {}) => {
98
103
  wcpProperties.wcpProjectId = wcpProjectId;
99
104
  }
100
105
 
106
+ const installationProperties = {};
107
+ if (installationId) {
108
+ installationProperties.installation_id = installationId;
109
+ }
110
+
111
+ const hostingTypeProperties = {};
112
+ if (process.env.REACT_APP_WEBINY_HOSTING_TYPE) {
113
+ hostingTypeProperties.hostingType = process.env.REACT_APP_WEBINY_HOSTING_TYPE;
114
+ }
115
+
101
116
  return baseSendEvent({
102
117
  event,
103
118
  properties: {
104
119
  ...properties,
105
120
  ...wcpProperties,
106
- ...(projectId ? { project_id: projectId } : {}),
121
+ ...installationProperties,
122
+ ...hostingTypeProperties,
107
123
  version: process.env.REACT_APP_WEBINY_VERSION,
108
124
  ci: process.env.REACT_APP_IS_CI === "true",
109
125
  newUser: process.env.REACT_APP_WEBINY_TELEMETRY_NEW_USER === "true"