@embeddable.com/init 0.1.23 → 0.1.24

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 (2) hide show
  1. package/dist/index.js +29 -30
  2. package/package.json +1 -2
package/dist/index.js CHANGED
@@ -11,37 +11,37 @@ import terminalLink from "terminal-link";
11
11
  import open from "open";
12
12
 
13
13
  // src/analytics.ts
14
- import * as amplitude from "@amplitude/analytics-node";
15
14
  import crypto from "crypto";
16
- var sessionUserId = crypto.randomUUID();
17
- function initAnalytics() {
18
- try {
19
- amplitude.init("9ceb0671ac9beaa2bb773d4ed7238d3d", {
20
- serverZone: "EU",
21
- flushIntervalMillis: 0,
22
- flushQueueSize: 1
23
- });
24
- } catch {
15
+ var deviceId = crypto.randomUUID();
16
+ function getAnalyticsUrl(region) {
17
+ if (region) {
18
+ return `https://api.${region.toLowerCase()}.embeddable.com/user-analytics`;
25
19
  }
20
+ return "https://api.eu.embeddable.com/user-analytics";
26
21
  }
27
- function trackEvent(name, properties) {
22
+ function trackEvent(name, properties, region, apiKey) {
28
23
  try {
29
- amplitude.track(name, properties, {
30
- user_id: sessionUserId,
31
- platform: "Web",
32
- ip: "$remote"
24
+ const url = getAnalyticsUrl(region);
25
+ const body = JSON.stringify({
26
+ eventType: name,
27
+ deviceId,
28
+ eventProperties: properties ?? {}
29
+ });
30
+ const headers = { "Content-Type": "application/json" };
31
+ if (apiKey) {
32
+ headers["Workspace-Api-Key"] = apiKey;
33
+ }
34
+ fetch(url, {
35
+ method: "POST",
36
+ headers,
37
+ body
38
+ }).catch(() => {
33
39
  });
34
40
  } catch {
35
41
  }
36
42
  }
37
43
  async function flushAndWait(timeoutMs = 1e3) {
38
- try {
39
- await Promise.race([
40
- amplitude.flush(),
41
- new Promise((resolve) => setTimeout(resolve, timeoutMs))
42
- ]);
43
- } catch {
44
- }
44
+ await new Promise((resolve) => setTimeout(resolve, timeoutMs));
45
45
  }
46
46
 
47
47
  // src/index.ts
@@ -129,7 +129,6 @@ async function main() {
129
129
  await typewriter(" and ", void 0, TYPEWRITER_SPEED);
130
130
  await typewriter("themes", chalk.bold, TYPEWRITER_SPEED);
131
131
  await typewriter(" (in your current directory) to help you create your first Embeddable dashboard.\n\n", void 0, TYPEWRITER_SPEED);
132
- initAnalytics();
133
132
  trackEvent("F1_Cli_Started");
134
133
  const cwd = process.cwd();
135
134
  currentStage = "dir_confirm";
@@ -223,7 +222,7 @@ Paste your API Key here:`,
223
222
  if (!apiKey) {
224
223
  await exit("\nSetup cancelled.\n");
225
224
  }
226
- trackEvent("F1_Api_Key_Entered");
225
+ trackEvent("F1_Api_Key_Entered", void 0, void 0, apiKey.trim());
227
226
  const embeddableDir = path.join(projectPath, ".embeddable");
228
227
  fs.mkdirSync(embeddableDir, { recursive: true });
229
228
  fs.writeFileSync(path.join(embeddableDir, ".api-key"), apiKey.trim());
@@ -246,7 +245,7 @@ Paste your API Key here:`,
246
245
  if (!region) {
247
246
  await exit("\nSetup cancelled.\n");
248
247
  }
249
- trackEvent("F1_Region_Selected", { region });
248
+ trackEvent("F1_Region_Selected", { region }, region, apiKey.trim());
250
249
  if (region === "EU") {
251
250
  const configPath = path.join(projectPath, "embeddable.config.ts");
252
251
  try {
@@ -276,9 +275,9 @@ Paste your API Key here:`,
276
275
  const startBuild = Date.now();
277
276
  try {
278
277
  execSync("npm run embeddable:build", { cwd: projectPath, stdio: "inherit" });
279
- trackEvent("F1_Bundle_Built", { duration_ms: Date.now() - startBuild });
278
+ trackEvent("F1_Bundle_Built", { duration_ms: Date.now() - startBuild }, region, apiKey.trim());
280
279
  } catch {
281
- trackEvent("F1_Cli_Error", { stage: "bundle_build", error: "build failed" });
280
+ trackEvent("F1_Cli_Error", { stage: "bundle_build", error: "build failed" }, region, apiKey.trim());
282
281
  await flushAndWait();
283
282
  console.error(chalk.red("\nFailed to build bundle.\n"));
284
283
  printDocsHint();
@@ -291,9 +290,9 @@ Paste your API Key here:`,
291
290
  `npm run embeddable:push -- --api-key ${apiKey.trim()} --email "no-reply@embeddable.com" --message "npx @embeddable.com/init"`,
292
291
  { cwd: projectPath, stdio: "inherit" }
293
292
  );
294
- trackEvent("F1_Bundle_Pushed", { duration_ms: Date.now() - startPush });
293
+ trackEvent("F1_Bundle_Pushed", { duration_ms: Date.now() - startPush }, region, apiKey.trim());
295
294
  } catch {
296
- trackEvent("F1_Cli_Error", { stage: "bundle_push", error: "push failed" });
295
+ trackEvent("F1_Cli_Error", { stage: "bundle_push", error: "push failed" }, region, apiKey.trim());
297
296
  await flushAndWait();
298
297
  console.error(chalk.red("\nFailed to push bundle to workspace.\n"));
299
298
  printDocsHint();
@@ -315,7 +314,7 @@ Success!
315
314
  `);
316
315
  console.log(`Follow the guide here to create your first Embeddable dashboard: ${chalk.cyan(docsLink)}
317
316
  `);
318
- trackEvent("F1_Cli_Completed", { region });
317
+ trackEvent("F1_Cli_Completed", { region }, region, apiKey.trim());
319
318
  await flushAndWait();
320
319
  await open(docsUrl);
321
320
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/init",
3
- "version": "0.1.23",
3
+ "version": "0.1.24",
4
4
  "description": "CLI tool for Embeddable",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,7 +27,6 @@
27
27
  "node": ">=20"
28
28
  },
29
29
  "dependencies": {
30
- "@amplitude/analytics-node": "^1.3.6",
31
30
  "chalk": "^5.3.0",
32
31
  "degit": "^2.8.4",
33
32
  "open": "^11.0.0",