@malloydata/malloyyo 0.2.21 → 0.2.22

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 +21 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3275,7 +3275,14 @@ function navFor(dash, all, cleanUrls) {
3275
3275
  (n) => cleanUrls ? `./${encodeURIComponent(n)}` : `./${encodeURIComponent(n)}.html`
3276
3276
  );
3277
3277
  }
3278
- function page(dash, all, title, givenSpecs, tileSpecs, cleanUrls) {
3278
+ function analyticsSnippet(id) {
3279
+ if (!id) return "";
3280
+ const j = JSON.stringify(id);
3281
+ return `<script async src="https://www.googletagmanager.com/gtag/js?id=${encodeURIComponent(id)}"></script>
3282
+ <script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}
3283
+ gtag('js',new Date());gtag('config',${j});</script>`;
3284
+ }
3285
+ function page(dash, all, title, givenSpecs, tileSpecs, cleanUrls, analytics) {
3279
3286
  const info = {
3280
3287
  name: dash.name,
3281
3288
  query: dash.query,
@@ -3295,6 +3302,7 @@ function page(dash, all, title, givenSpecs, tileSpecs, cleanUrls) {
3295
3302
  <meta name="viewport" content="width=device-width, initial-scale=1">
3296
3303
  <title>${esc3(dash.title || dash.name)}${title ? ` \xB7 ${esc3(title)}` : ""}</title>
3297
3304
  <link rel="stylesheet" href="./assets/site.css">
3305
+ ${analyticsSnippet(analytics)}
3298
3306
  </head>
3299
3307
  <body>
3300
3308
  ${navFor(dash, all, cleanUrls)}
@@ -3317,7 +3325,7 @@ window.__GIVENS__ = ${JSON.stringify(givenSpecs)};
3317
3325
  </html>
3318
3326
  `;
3319
3327
  }
3320
- function indexPage(dashboards, title, custom, cleanUrls) {
3328
+ function indexPage(dashboards, title, custom, cleanUrls, analytics) {
3321
3329
  const link = (n) => cleanUrls ? `./${encodeURIComponent(n)}` : `./${encodeURIComponent(n)}.html`;
3322
3330
  const body = custom ? `<div id="root"></div>
3323
3331
  <script>window.__DASHBOARDS__ = ${JSON.stringify(
@@ -3333,6 +3341,7 @@ function indexPage(dashboards, title, custom, cleanUrls) {
3333
3341
  <meta name="viewport" content="width=device-width, initial-scale=1">
3334
3342
  <title>${esc3(title)}</title>
3335
3343
  <link rel="stylesheet" href="./assets/site.css">
3344
+ ${analyticsSnippet(analytics)}
3336
3345
  </head>
3337
3346
  <body>
3338
3347
  ${navHtml("", dashboards, link)}
@@ -3493,9 +3502,9 @@ boot(Dashboard);
3493
3502
  if (!got.ok) throw new Error(`dashboard ${d.name}: ${got.error}`);
3494
3503
  specs = got.givens;
3495
3504
  }
3496
- fs6.writeFileSync(path7.join(outDir, `${d.name}.html`), page(d, dashboards, title, specs, tileSpecs, cleanUrls));
3505
+ fs6.writeFileSync(path7.join(outDir, `${d.name}.html`), page(d, dashboards, title, specs, tileSpecs, cleanUrls, opts.analytics));
3497
3506
  }
3498
- fs6.writeFileSync(path7.join(outDir, "index.html"), indexPage(dashboards, title, !!landing, cleanUrls));
3507
+ fs6.writeFileSync(path7.join(outDir, "index.html"), indexPage(dashboards, title, !!landing, cleanUrls, opts.analytics));
3499
3508
  if (landing) {
3500
3509
  await esbuild3.build({
3501
3510
  stdin: {
@@ -3668,7 +3677,7 @@ async function launchCmd(mode, opts) {
3668
3677
  }
3669
3678
 
3670
3679
  // package.json
3671
- var version = "0.2.21";
3680
+ var version = "0.2.22";
3672
3681
 
3673
3682
  // src/index.ts
3674
3683
  function shortSha(sha) {
@@ -3775,7 +3784,7 @@ program.command("author").option("-C, --root <dir>", "project root (default: cur
3775
3784
  program.command("test").option("-C, --root <dir>", "project root (default: current directory)").description("launch Claude wired ONLY to the explore surface \u2014 the claude.ai web preview").action(async (opts) => {
3776
3785
  await launchCmd("test", opts);
3777
3786
  });
3778
- program.command("dashboard").argument("<action>", "action to run (dev | bundle)").option("-C, --root <dir>", "project root (default: current directory)").option("-p, --port <port>", "port to serve on (dev)", "4173").option("-o, --out <dir>", "output directory (bundle)", "docs").option("--title <title>", "site title (bundle; default: project directory name)").option("--target <target>", "deploy target: pages | vercel (bundle)", "pages").option("--duckdb <source>", "DuckDB binaries: cdn | bundled (bundle)", "cdn").option("--no-serve", "bundle only; don't serve the result (bundle)").description("preview dashboards locally (dev), or build a static site from them (bundle)").action(
3787
+ program.command("dashboard").argument("<action>", "action to run (dev | bundle)").option("-C, --root <dir>", "project root (default: current directory)").option("-p, --port <port>", "port to serve on (dev)", "4173").option("-o, --out <dir>", "output directory (bundle)", "docs").option("--title <title>", "site title (bundle; default: project directory name)").option("--target <target>", "deploy target: pages | vercel (bundle)", "pages").option("--duckdb <source>", "DuckDB binaries: cdn | bundled (bundle)", "cdn").option("--analytics <id>", "Google Analytics 4 Measurement ID, e.g. G-XXXXXXXXXX (bundle)").option("--no-serve", "bundle only; don't serve the result (bundle)").description("preview dashboards locally (dev), or build a static site from them (bundle)").action(
3779
3788
  async (action, opts) => {
3780
3789
  if (action === "dev") {
3781
3790
  await serveDashboard({ root: opts.root, port: Number(opts.port) });
@@ -3785,6 +3794,11 @@ program.command("dashboard").argument("<action>", "action to run (dev | bundle)"
3785
3794
  if (opts.target !== "pages" && opts.target !== "vercel") {
3786
3795
  throw new Error(`unknown --target '${opts.target}' (expected: pages | vercel)`);
3787
3796
  }
3797
+ if (opts.analytics && !/^G-[A-Z0-9]+$/i.test(opts.analytics)) {
3798
+ throw new Error(
3799
+ `--analytics expects a GA4 Measurement ID like G-XXXXXXXXXX, got '${opts.analytics}'`
3800
+ );
3801
+ }
3788
3802
  if (opts.duckdb !== "cdn" && opts.duckdb !== "bundled") {
3789
3803
  throw new Error(`unknown --duckdb '${opts.duckdb}' (expected: cdn | bundled)`);
3790
3804
  }
@@ -3795,6 +3809,7 @@ program.command("dashboard").argument("<action>", "action to run (dev | bundle)"
3795
3809
  serve: opts.serve,
3796
3810
  target: opts.target,
3797
3811
  duckdb: opts.duckdb,
3812
+ analytics: opts.analytics,
3798
3813
  // `dashboard dev` owns 4173/4174; default the bundle preview clear of
3799
3814
  // both so you can run the two side by side.
3800
3815
  port: opts.port === "4173" ? 4180 : Number(opts.port)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloyyo",
3
- "version": "0.2.21",
3
+ "version": "0.2.22",
4
4
  "description": "Publish Malloy models to a Malloyyo instance",
5
5
  "license": "MIT",
6
6
  "repository": {