carlos / platform Public

Analytics on-ramp Task 3: create-time analytics, new accounts on, CLI flags

Create an app gets an analytics checkbox ticked from the account's
default. An owner's choice that differs gives the app its own setting
through the app settings door's write; a matching one writes nothing. A
member's checkbox is disabled; a member's hand-written different choice
is refused before the claim. Owners get Make this the account default,
which posts the form to the account door and comes back (back=new-app).

New accounts minted by the console get analytics on at the account
level (best-effort). carlos apps create gains --analytics/--no-analytics
over an additive "analytics" field; the console echoes analytics and
analytics_from and the CLI checks the echo. The two settings pages, the
CLI page and carlos analytics --help no longer say off until turned on.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev dddebe3de30ad97dcdcf2d4785519fa7b68cbad6 parent af83261
15 files changed, +709 −16
  • analytics_cmd.go +1 −1
  • apimode.go +18 −1
  • apps.go +61 −3
  • apps_analytics_test.go +98 −0
  • docs/site/cli.md +6 −1
  • docs/superpowers/plans/2026-10-26-analytics-onramp-copy.md +4 −3
  • internal/console/analytics_onramp_test.go +275 −0
  • internal/console/analyticsonramp.go +135 −0
  • internal/console/apicli.go +35 −0
  • internal/console/approved_analytics_onramp_copy_test.go +4 −0
  • internal/console/regionpicker_test.go +12 −1
  • internal/console/server.go +34 −2
  • internal/console/templates/account_settings.html +2 −2
  • internal/console/templates/app_new.html +22 −0
  • internal/console/templates/app_settings.html +2 −2
diff --git a/analytics_cmd.go b/analytics_cmd.go
index 490277f7c..93c06c240 100644
--- a/analytics_cmd.go
+++ b/analytics_cmd.go
@@ -15,7 +15,7 @@ import (
const analyticsUsage = `usage: carlos analytics --app <a> [flags]
Page views, daily visitors, bytes served, top pages, top referers and named
-events, counted at the edge. Off until you turn it on.
+events, counted at the edge. New accounts start with analytics on.
--range is today, 7d or 30d; multi-day visitor totals are daily visitors
summed. The same view is the Analytics tab on the app's dashboard.
diff --git a/apimode.go b/apimode.go
index 4701fbcd6..558f17172 100644
--- a/apimode.go
+++ b/apimode.go
@@ -1052,6 +1052,13 @@ type apiCreateAppResult struct {
// RegionLabel is the stored region's label, "London (uk)" (region
// labels spec §4); "" from an older console.
RegionLabel string `json:"region_label"`
+
+ // Analytics is what the new app's counting resolves to after the
+ // create, "edge" or "off", and AnalyticsFrom where that comes from
+ // ("app", "account" or "default"). Both "" from an older console, which
+ // also ignores a requested choice; runAppsCreate checks the echo.
+ Analytics string `json:"analytics"`
+ AnalyticsFrom string `json:"analytics_from"`
}
// createApp claims one app name through the console — the API door onto the
@@ -1082,6 +1089,15 @@ type apiCreateAppResult struct {
// (validBuildProbe, apps.go), same "a shape the server is certain to
// refuse should cost nothing" principle as place.
func (s *apiSession) createApp(ctx context.Context, a apiAcct, app, place string, controlPlane bool, buildProbe, region, timezone string) (apiCreateAppResult, error) {
+ return s.createAppAnalytics(ctx, a, app, place, controlPlane, buildProbe, region, timezone, "")
+}
+
+// createAppAnalytics is createApp with the new app's analytics choice:
+// "" follows the account, "edge" or "off" asks for that (`carlos apps create
+// --analytics/--no-analytics`). Only an owner may ask for something other
+// than the account's default; the console refuses anyone else before the
+// name is claimed.
+func (s *apiSession) createAppAnalytics(ctx context.Context, a apiAcct, app, place string, controlPlane bool, buildProbe, region, timezone, analytics string) (apiCreateAppResult, error) {
in := struct {
Name string `json:"name"`
Place string `json:"place,omitempty"`
@@ -1089,7 +1105,8 @@ func (s *apiSession) createApp(ctx context.Context, a apiAcct, app, place string
BuildProbe string `json:"build_probe,omitempty"`
Region string `json:"region,omitempty"`
Timezone string `json:"timezone,omitempty"`
- }{app, place, controlPlane, buildProbe, region, timezone}
+ Analytics string `json:"analytics,omitempty"`
+ }{app, place, controlPlane, buildProbe, region, timezone, analytics}
status, body, err := s.postJSON(ctx, apiPath(a, "new", ""), in)
if err != nil {
return apiCreateAppResult{}, err
diff --git a/apps.go b/apps.go
index 9e4831726..f2412ddf0 100644
--- a/apps.go
+++ b/apps.go
@@ -520,6 +520,8 @@ func runAppsCreate(args []string) {
"stamps from the route row and which therefore lies until the process restarts; "+
`the build must appear as a whole whitespace-delimited word in the body, e.g. "ok abc1234"`)
region := fs.String("region", "", flagRegionAppsCreate)
+ analyticsOn := fs.Bool("analytics", false, "turn analytics on for the new app (default: follow the account)")
+ analyticsOff := fs.Bool("no-analytics", false, "turn analytics off for the new app (default: follow the account)")
// Not accountFlags: that helper also registers --registry for direct-mode
// resolution, and this verb never resolves locally — the console resolves
// the account against the caller's own memberships.
@@ -530,7 +532,12 @@ func runAppsCreate(args []string) {
fs.Parse(args)
if strings.TrimSpace(*app) == "" {
log.Fatal("usage: carlos apps create --app <name> [--place fleet/<f>] [--control-plane] " +
- "[--build-probe /path] [--region <code>] [--account <sqid|name>] [--account-id <sqid>] [--console <origin>]")
+ "[--build-probe /path] [--region <code>] [--analytics | --no-analytics] " +
+ "[--account <sqid|name>] [--account-id <sqid>] [--console <origin>]")
+ }
+ analytics, err := analyticsChoice(*analyticsOn, *analyticsOff)
+ if err != nil {
+ log.Fatalf("apps create: %v", err)
}
// Client-side gates before the server's: the create limiter charges
// ATTEMPTS, so a name — or a place or build-probe value — the server is
@@ -567,8 +574,8 @@ func runAppsCreate(args []string) {
printUsing(stdout, sess)
acct := resolvedAccount(sess, acctRaw, acctIDRaw)
region2 := strings.TrimSpace(*region)
- res, err := sess.createApp(context.Background(), acct, strings.TrimSpace(*app), place2, *controlPlane, probe2,
- region2, detectTimezone())
+ res, err := sess.createAppAnalytics(context.Background(), acct, strings.TrimSpace(*app), place2, *controlPlane, probe2,
+ region2, detectTimezone(), analytics)
if err != nil {
log.Fatalf("apps create: %v", err)
}
@@ -610,6 +617,57 @@ func runAppsCreate(args []string) {
}
fmt.Fprintf(stdout, " build probe: %s\n", res.BuildProbe)
}
+ // The same "what actually stuck" check for --analytics/--no-analytics:
+ // the console echoes what the app now resolves to, and an older console
+ // echoes nothing at all.
+ if err := analyticsMismatchErr(res.App, analytics, res.Analytics); err != nil {
+ log.Fatalf("apps create: %v", err)
+ }
+ if line := analyticsLine(res); line != "" {
+ fmt.Fprintf(stdout, " %s\n", line)
+ }
+}
+
+// analyticsChoice maps --analytics and --no-analytics onto the create
+// request's "analytics" value: "" (neither: follow the account), "edge" or
+// "off". Both at once is refused before any call.
+func analyticsChoice(on, off bool) (string, error) {
+ switch {
+ case on && off:
+ return "", errors.New("choose --analytics or --no-analytics, not both")
+ case on:
+ return "edge", nil
+ case off:
+ return "off", nil
+ }
+ return "", nil
+}
+
+// analyticsLine is the create output's analytics line, from the console's
+// echo: "" from a console too old to echo it.
+func analyticsLine(res apiCreateAppResult) string {
+ if res.Analytics == "" {
+ return ""
+ }
+ state := "off"
+ if res.Analytics == "edge" {
+ state = "on"
+ }
+ if res.AnalyticsFrom == "app" {
+ return "analytics: " + state + ", set for this app"
+ }
+ return "analytics: " + state + ", following the account"
+}
+
+// analyticsMismatchErr compares the analytics choice asked for with what
+// the console echoed, the way placementMismatchErr does for --place. No
+// choice asked for is never a mismatch.
+func analyticsMismatchErr(app, requested, echoed string) error {
+ if requested == "" || requested == echoed {
+ return nil
+ }
+ return fmt.Errorf("the app %s was created, but the console did not confirm its analytics setting. "+
+ "Set it with: carlos analytics --app %s --set-count %s", app, app, requested)
}
// placementMismatchErr compares what --place asked for (requested) against
diff --git a/apps_analytics_test.go b/apps_analytics_test.go
new file mode 100644
index 000000000..a83ff0896
--- /dev/null
+++ b/apps_analytics_test.go
@@ -0,0 +1,98 @@
+package main
+
+// `carlos apps create --analytics/--no-analytics` (analytics on-ramp plan,
+// docs/superpowers/plans/2026-10-26-analytics-onramp.md, item 4): the flags
+// map onto the create API's "analytics" field, and the output reports what
+// the console echoed rather than what was asked for.
+
+import (
+ "context"
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+)
+
+func TestAppsCreateAnalyticsFlagsMapToTheAPI(t *testing.T) {
+ for _, tc := range []struct {
+ on, off bool
+ want string // the request's "analytics" value; "-" = key absent
+ bad bool
+ }{
+ {false, false, "-", false},
+ {true, false, "edge", false},
+ {false, true, "off", false},
+ {true, true, "", true},
+ } {
+ choice, err := analyticsChoice(tc.on, tc.off)
+ if tc.bad {
+ if err == nil || err.Error() != "choose --analytics or --no-analytics, not both" {
+ t.Errorf("both flags: err = %v, want the both-flags refusal", err)
+ }
+ continue
+ }
+ if err != nil {
+ t.Fatalf("analyticsChoice(%v, %v) = %v", tc.on, tc.off, err)
+ }
+ var got map[string]any
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ json.NewDecoder(r.Body).Decode(&got)
+ json.NewEncoder(w).Encode(map[string]any{"account": "acct", "app": "app",
+ "analytics": "edge", "analytics_from": "app"})
+ }))
+ res, err := newTestSession(ts.URL).createAppAnalytics(context.Background(), apiAcct{Seg: "acct"}, "app", "", false, "", "", "", choice)
+ ts.Close()
+ if err != nil {
+ t.Fatalf("createAppAnalytics: %v", err)
+ }
+ v, present := got["analytics"]
+ if tc.want == "-" {
+ if present {
+ t.Errorf("no flag sent analytics=%v; want the key absent so the app follows the account", v)
+ }
+ } else if v != tc.want {
+ t.Errorf("flags on=%v off=%v sent analytics=%v, want %q", tc.on, tc.off, v, tc.want)
+ }
+ if res.Analytics != "edge" || res.AnalyticsFrom != "app" {
+ t.Errorf("result = %+v, want the console's echo", res)
+ }
+ }
+}
+
+func TestAppsCreateAnalyticsLine(t *testing.T) {
+ for _, tc := range []struct {
+ res apiCreateAppResult
+ want string
+ }{
+ {apiCreateAppResult{Analytics: "edge", AnalyticsFrom: "app"}, "analytics: on, set for this app"},
+ {apiCreateAppResult{Analytics: "off", AnalyticsFrom: "app"}, "analytics: off, set for this app"},
+ {apiCreateAppResult{Analytics: "edge", AnalyticsFrom: "account"}, "analytics: on, following the account"},
+ {apiCreateAppResult{Analytics: "off", AnalyticsFrom: "default"}, "analytics: off, following the account"},
+ {apiCreateAppResult{}, ""}, // an older console echoes nothing
+ } {
+ if got := analyticsLine(tc.res); got != tc.want {
+ t.Errorf("analyticsLine(%+v) = %q, want %q", tc.res, got, tc.want)
+ }
+ }
+}
+
+func TestAppsCreateAnalyticsMismatch(t *testing.T) {
+ for _, tc := range []struct{ requested, echoed string }{{"", ""}, {"", "edge"}, {"edge", "edge"}, {"off", "off"}} {
+ if err := analyticsMismatchErr("shop", tc.requested, tc.echoed); err != nil {
+ t.Errorf("requested %q, echoed %q: %v, want no error", tc.requested, tc.echoed, err)
+ }
+ }
+ // An older console echoes "", and a failed write echoes the account's.
+ for _, echoed := range []string{"", "off"} {
+ err := analyticsMismatchErr("shop", "edge", echoed)
+ const want = "the app shop was created, but the console did not confirm its analytics setting. " +
+ "Set it with: carlos analytics --app shop --set-count edge"
+ if err == nil || err.Error() != want {
+ t.Errorf("echoed %q: err = %v, want %q", echoed, err, want)
+ }
+ }
+ if err := analyticsMismatchErr("shop", "off", "edge"); err == nil || !strings.HasSuffix(err.Error(), "--set-count off") {
+ t.Errorf("off not confirmed: %v", err)
+ }
+}
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 08d959a04..3b5711e4e 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -127,6 +127,10 @@ prints one line saying which and why:
carlos apps create --app hello --region uk
```
+`--analytics` or `--no-analytics` turns analytics on or off for the new app.
+Without either, the app follows the account's setting. Only an owner can
+choose differently from the account.
+
A name is also refused when its platform apex, `<app>.<account>.<apps
domain>`, is already taken: by another app's instance, even one in the Trash,
or by any route there at all. The new app would otherwise never get an address
@@ -1421,7 +1425,8 @@ Records the edge filed before causes were recorded are grouped under
Page views, daily visitors, bytes served, top pages, top referers and named
events, counted at the edge as it serves your app: no JavaScript, no cookie,
-no stored IP. Off until you turn it on, for one app or for the whole account.
+no stored IP. New accounts start with analytics on. Turn it on or off for one
+app or for the whole account.
```sh
carlos analytics --app hello --set-count edge
diff --git a/docs/superpowers/plans/2026-10-26-analytics-onramp-copy.md b/docs/superpowers/plans/2026-10-26-analytics-onramp-copy.md
index 80ab91d2d..b33875fa2 100644
--- a/docs/superpowers/plans/2026-10-26-analytics-onramp-copy.md
+++ b/docs/superpowers/plans/2026-10-26-analytics-onramp-copy.md
@@ -63,8 +63,8 @@ What the strings are for:
| AN-C14 | templates/app_new.html (owner's button under the checkbox) | (new) | Make this the account default | gate | approved |
| AN-C15 | templates/app_new.html (owner's note beside the button) | (new) | The account default also applies to every existing app without its own setting. | gate | approved |
| AN-C16 | templates/app_new.html (member's note; the checkbox is shown but cannot be changed) | (new) | Only an owner can change this. | gate | approved |
-| AN-C17 | server.go (flash: a member's form chose differently from the account default) | (new) | Only an owner can change analytics for a new app. Nothing was created. | gate | approved |
-| AN-C18 | server.go (flash: the app was created but its analytics setting failed to save) | (new) | Created app `<app>`, but its analytics setting could not be saved. Set it in Settings, under Errors and analytics. | TestNewAppAnalyticsWriteFailureSaysSo | approved |
+| AN-C17 | analyticsonramp.go (flash: a member's form chose differently from the account default) | (new) | Only an owner can change analytics for a new app. Nothing was created. | gate | approved |
+| AN-C18 | analyticsonramp.go (flash: the app was created but its analytics setting failed to save) | (new) | Created app `<app>`, but its analytics setting could not be saved. Set it in Settings, under Errors and analytics. | TestNewAppAnalyticsWriteFailureSaysSo | approved |
| AN-C19 | analyticsview.go (flash on the create form after Make this the account default, on) | (new) | Analytics is now on for every app in this account without its own setting. | gate | approved |
| AN-C20 | analyticsview.go (flash on the create form after Make this the account default, off) | (new) | Analytics is now off for every app in this account without its own setting. | gate | approved |
| AN-C21 | templates/account_settings.html (Analytics, last sentence of the help) | Whether that needs consent where your visitors are is your call, which is why it is off until you turn it on. | Whether that needs consent where your visitors are is your call. New accounts start with analytics on. | gate | approved |
@@ -75,6 +75,7 @@ What the strings are for:
| AN-C33 | ../../apps.go (`carlos apps create` output, the app follows the account) | (new) | analytics: `<state>`, following the account | TestAppsCreateAnalyticsLine | approved |
| AN-C34 | ../../apps.go (`carlos apps create` error, the console did not confirm the choice) | (new) | the app `<app>` was created, but the console did not confirm its analytics setting. Set it with: carlos analytics --app `<app>` --set-count `<count>` | TestAppsCreateAnalyticsMismatch | approved |
| AN-C35 | ../../apps.go (`carlos apps create` error, both flags given) | (new) | choose --analytics or --no-analytics, not both | gate | approved |
-| AN-C36 | apicli.go (`carlos apps create` refusal printed to a member) | (new) | only an owner can choose analytics for a new app. Leave out --analytics and --no-analytics to follow the account | gate | approved |
+| AN-C36 | analyticsonramp.go (`carlos apps create` refusal printed to a member) | (new) | only an owner can choose analytics for a new app. Leave out --analytics and --no-analytics to follow the account | gate | approved |
| AN-C40 | ../../docs/site/cli.md (carlos analytics, first paragraph) | Off until you turn it on, for one app or for the whole account. | New accounts start with analytics on. Turn it on or off for one app or for the whole account. | gate | approved |
| AN-C41 | ../../docs/site/cli.md (carlos apps, after the `--region` example) | (new) | `--analytics` or `--no-analytics` turns analytics on or off for the new app. Without either, the app follows the account's setting. Only an owner can choose differently from the account. | gate | approved |
+| AN-C42 | ../../analytics_cmd.go (`carlos analytics --help`, first paragraph; found after the Luna pass, and uses AN-C40's approved first sentence verbatim) | Off until you turn it on. | New accounts start with analytics on. | gate | approved |
diff --git a/internal/console/analytics_onramp_test.go b/internal/console/analytics_onramp_test.go
index b4f6c30fb..cdd450bcb 100644
--- a/internal/console/analytics_onramp_test.go
+++ b/internal/console/analytics_onramp_test.go
@@ -6,6 +6,7 @@ package console
import (
"context"
+ "encoding/json"
"net/http"
"net/url"
"strings"
@@ -155,3 +156,277 @@ func TestAnalyticsWindowHasData(t *testing.T) {
t.Error("a window holding only a named event has no data")
}
}
+
+// setAccountAnalytics writes the fixture account's analytics default.
+func setAccountAnalytics(t *testing.T, fx *consoleFixture, count string) {
+ t.Helper()
+ if err := telemetry.Update(context.Background(), fx.rel, telemetry.AccountKey(fx.sqid), func(st *telemetry.Settings) {
+ mergeAnalytics(st, count, "")
+ }); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// appAnalyticsObject reports whether the app has its own telemetry object.
+func appAnalyticsObject(t *testing.T, fx *consoleFixture, app string) bool {
+ t.Helper()
+ st, etag, err := telemetry.Read(context.Background(), fx.rel, telemetry.AppKey(fx.sqid, app))
+ if err != nil {
+ t.Fatal(err)
+ }
+ return etag != "" || st.Analytics != nil
+}
+
+const (
+ onrampCheckbox = `<input type="checkbox" name="count" value="edge"`
+ onrampHiddenOff = `<input type="hidden" name="count" value="off">`
+ onrampMakeDefault = "Make this the account default"
+ onrampDefaultOn = "This account's default is on."
+ onrampDefaultOff = "This account's default is off."
+ onrampOnlyOwnerNote = "Only an owner can change this."
+)
+
+func TestNewAppFormAnalyticsFollowsAccount(t *testing.T) {
+ fx, _ := instanceFixture(t, "code-onramp-form")
+ fx.setUser("paul@keymail.dev")
+ c := newBrowser(t)
+ signUp(t, fx, c, "code-onramp-form-owner")
+
+ checkbox := func(body string) string {
+ at := strings.Index(body, onrampCheckbox)
+ if at < 0 {
+ t.Fatalf("the create form has no analytics checkbox:\n%s", body)
+ }
+ tag, _, _ := strings.Cut(body[at:], ">")
+ return tag
+ }
+ // No account setting: the built-in default, off, and the box unticked.
+ _, _, body := get(t, c, fx.u("/apps/new"))
+ if tag := checkbox(body); strings.Contains(tag, "checked") || strings.Contains(tag, "disabled") {
+ t.Errorf("default off: owner's checkbox = %s, want unticked and enabled", tag)
+ }
+ for _, want := range []string{onrampDefaultOff, onrampHiddenOff, onrampMakeDefault,
+ `formaction="/a/` + fx.sqid + `/analytics/setting"`, `name="back" value="new-app"`,
+ "The account default also applies to every existing app without its own setting."} {
+ if !strings.Contains(body, want) {
+ t.Errorf("owner's create form missing %q", want)
+ }
+ }
+ // Enter in the name field presses the first submit button: Create app.
+ if strings.Index(body, ">Create app</button>") > strings.Index(body, onrampMakeDefault) {
+ t.Error("Make this the account default comes before Create app, so Enter would press it")
+ }
+
+ setAccountAnalytics(t, fx, telemetry.CountEdge)
+ _, _, body = get(t, c, fx.u("/apps/new"))
+ if tag := checkbox(body); !strings.Contains(tag, "checked") {
+ t.Errorf("default on: owner's checkbox = %s, want ticked", tag)
+ }
+ if !strings.Contains(body, onrampDefaultOn) {
+ t.Errorf("default on: form missing %q", onrampDefaultOn)
+ }
+
+ // A member sees the account's choice and cannot change it.
+ fx.setUser("alice@keymail.dev")
+ m := newBrowser(t)
+ signUp(t, fx, m, "code-onramp-form-member")
+ _, _, body = get(t, m, fx.u("/apps/new"))
+ if tag := checkbox(body); !strings.Contains(tag, "checked") || !strings.Contains(tag, "disabled") {
+ t.Errorf("member's checkbox = %s, want ticked and disabled", tag)
+ }
+ if !strings.Contains(body, onrampOnlyOwnerNote) {
+ t.Errorf("member's form missing %q", onrampOnlyOwnerNote)
+ }
+ for _, gone := range []string{onrampHiddenOff, onrampMakeDefault, "formaction="} {
+ if strings.Contains(body, gone) {
+ t.Errorf("member's form shows %q", gone)
+ }
+ }
+}
+
+func TestNewAppAnalyticsChoice(t *testing.T) {
+ fx, _ := instanceFixture(t, "code-onramp-create")
+ fx.setUser("paul@keymail.dev")
+ c := newBrowser(t)
+ signUp(t, fx, c, "code-onramp-create-owner")
+ csrf := sessionToken(t, fx, c)
+ create := func(c *http.Client, csrf, name string, count ...string) (int, string) {
+ form := url.Values{"csrf": {csrf}, "name": {name}}
+ for _, v := range count {
+ form.Add("count", v)
+ }
+ status, loc, _ := postForm(t, c, fx.u("/apps/new"), form)
+ return status, loc
+ }
+ created := func(name string) bool {
+ has, err := fx.st.HasAppIn(OpsAccountID, name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return has
+ }
+
+ // The account default is off (no setting). Ticked: the app's own edge.
+ if st, loc := create(c, csrf, "shop-on", "edge", "off"); st != http.StatusSeeOther || loc != fx.path("/apps/shop-on") {
+ t.Fatalf("owner create ticked = %d -> %q", st, loc)
+ }
+ if res, _ := telemetry.Resolve(context.Background(), fx.rel, fx.sqid, "shop-on"); res.Count != telemetry.CountEdge || res.CountFrom != "app" {
+ t.Errorf("ticked over an off default: %+v, want edge from the app", res)
+ }
+ // Unticked matches the default: nothing written, the app follows.
+ if st, _ := create(c, csrf, "shop-off", "off"); st != http.StatusSeeOther || !created("shop-off") {
+ t.Fatalf("owner create unticked = %d", st)
+ }
+ if appAnalyticsObject(t, fx, "shop-off") {
+ t.Error("a choice matching the account default wrote an app setting")
+ }
+
+ // Default on: unticked gives the app its own off; ticked writes nothing.
+ setAccountAnalytics(t, fx, telemetry.CountEdge)
+ create(c, csrf, "shop-quiet", "off")
+ if res, _ := telemetry.Resolve(context.Background(), fx.rel, fx.sqid, "shop-quiet"); res.Count != telemetry.CountOff || res.CountFrom != "app" {
+ t.Errorf("unticked over an on default: %+v, want off from the app", res)
+ }
+ create(c, csrf, "shop-follow", "edge", "off")
+ if !created("shop-follow") || appAnalyticsObject(t, fx, "shop-follow") {
+ t.Error("ticked over an on default wrote an app setting, or created nothing")
+ }
+
+ // A member: no field (the disabled box) or the account's own choice
+ // creates and writes nothing; a different choice is refused up front.
+ fx.setUser("alice@keymail.dev")
+ m := newBrowser(t)
+ signUp(t, fx, m, "code-onramp-create-member")
+ mcsrf := sessionToken(t, fx, m)
+ for _, tc := range []struct {
+ name string
+ count []string
+ }{{"member-plain", nil}, {"member-same", []string{"edge"}}} {
+ if st, loc := create(m, mcsrf, tc.name, tc.count...); st != http.StatusSeeOther || loc != fx.path("/apps/"+tc.name) {
+ t.Fatalf("member create %s = %d -> %q", tc.name, st, loc)
+ }
+ if appAnalyticsObject(t, fx, tc.name) {
+ t.Errorf("member create %s wrote an app setting", tc.name)
+ }
+ }
+ st, loc := create(m, mcsrf, "member-other", "off")
+ if st != http.StatusSeeOther || loc != fx.path("/apps/new") {
+ t.Fatalf("member create with a different choice = %d -> %q, want 303 back to the form", st, loc)
+ }
+ if created("member-other") {
+ t.Fatal("a member's different analytics choice still created the app")
+ }
+ if _, _, body := get(t, m, fx.ts.URL+loc); !strings.Contains(body, newAppAnalyticsNotOwnerFlash) {
+ t.Errorf("the form does not show %q", newAppAnalyticsNotOwnerFlash)
+ }
+}
+
+func TestNewAppMakeAccountDefault(t *testing.T) {
+ fx, _ := instanceFixture(t, "code-onramp-default")
+ fx.setUser("paul@keymail.dev")
+ c := newBrowser(t)
+ signUp(t, fx, c, "code-onramp-default-owner")
+ for _, tc := range []struct {
+ count []string
+ want string
+ flash string
+ }{
+ {[]string{"edge", "off"}, telemetry.CountEdge, analyticsAccountDefaultOnFlash},
+ {[]string{"off"}, telemetry.CountOff, analyticsAccountDefaultOffFlash},
+ } {
+ // The whole create form, posted to the account door by the button's
+ // formaction: name and region ride along and are ignored.
+ form := url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {"shop"}, "count": tc.count, "back": {"new-app"}}
+ status, loc, _ := postForm(t, c, fx.u("/analytics/setting"), form)
+ if status != http.StatusSeeOther || loc != fx.path("/apps/new") {
+ t.Fatalf("Make this the account default = %d -> %q, want 303 to the form", status, loc)
+ }
+ def, err := fx.srv.accountAnalyticsDefault(context.Background(), fx.sqid)
+ if err != nil || def.Count != tc.want || def.CountFrom != "account" {
+ t.Errorf("account default = %+v %v, want %s from the account", def, err, tc.want)
+ }
+ if _, _, body := get(t, c, fx.ts.URL+loc); !strings.Contains(body, tc.flash) {
+ t.Errorf("the form does not show %q", tc.flash)
+ }
+ }
+ if has, _ := fx.st.HasAppIn(OpsAccountID, "shop"); has {
+ t.Error("Make this the account default created the app")
+ }
+}
+
+func TestNewAppAnalyticsWriteFailureSaysSo(t *testing.T) {
+ fx, _ := instanceFixture(t, "code-onramp-fail")
+ fx.setUser("paul@keymail.dev")
+ c := newBrowser(t)
+ signUp(t, fx, c, "code-onramp-fail-owner")
+ fx.srv.cfg.Releases = &hookStore{Store: fx.rel, failPut: map[string]int{telemetry.AppKey(fx.sqid, "shop"): -1}}
+ form := url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {"shop"}, "count": {"edge", "off"}}
+ status, loc, _ := postForm(t, c, fx.u("/apps/new"), form)
+ if status != http.StatusSeeOther || loc != fx.path("/apps/shop") {
+ t.Fatalf("create = %d -> %q, want the app created anyway", status, loc)
+ }
+ want := "Created app shop, but its analytics setting could not be saved. Set it in Settings, under Errors and analytics."
+ if _, _, body := get(t, c, fx.ts.URL+loc); !strings.Contains(body, want) {
+ t.Errorf("the app page does not say %q", want)
+ }
+ if res, _ := telemetry.Resolve(context.Background(), fx.rel, fx.sqid, "shop"); res.CountFrom == "app" {
+ t.Errorf("the failed write left an app setting: %+v", res)
+ }
+}
+
+func TestNewAccountStartsWithAnalyticsOn(t *testing.T) {
+ fx, _ := instanceFixture(t, "code-onramp-account")
+ fx.setUser("newcomer@keymail.dev")
+ c := newBrowser(t)
+ signUp(t, fx, c, "code-onramp-account-newcomer") // no membership: landing mints one
+ accts, err := fx.st.AccountsFor("newcomer@keymail.dev")
+ if err != nil || len(accts) != 1 {
+ t.Fatalf("newcomer's accounts = %v %v, want the one minted", accts, err)
+ }
+ st, _, err := telemetry.Read(context.Background(), fx.rel, telemetry.AccountKey(accts[0].Sqid))
+ if err != nil || st.Analytics == nil || st.Analytics.Count != telemetry.CountEdge || st.Analytics.Door != "" {
+ t.Fatalf("new account's telemetry = %+v %v, want count edge and nothing else", st.Analytics, err)
+ }
+ // An account that already existed is unchanged: no object written.
+ if st, etag, _ := telemetry.Read(context.Background(), fx.rel, telemetry.AccountKey(fx.sqid)); etag != "" || st.Analytics != nil {
+ t.Errorf("the existing account gained an analytics setting: %+v", st.Analytics)
+ }
+}
+
+// The CLI door: the same rules, with the choice echoed back.
+func TestAPICreateAppAnalytics(t *testing.T) {
+ fx, member := instanceFixture(t, "code-onramp-api")
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-onramp-api-owner")
+ create := func(token, body string) (int, map[string]any) {
+ status, _, raw := rawReq(t, http.MethodPost, fx.ts.URL+"/api/cli/apps/"+fx.sqid+"/new", token, body)
+ var out map[string]any
+ _ = json.Unmarshal([]byte(raw), &out)
+ return status, out
+ }
+ // Owner, default off: --analytics gives the app its own edge.
+ st, out := create(owner, `{"name":"api-on","analytics":"edge"}`)
+ if st != http.StatusOK || out["analytics"] != "edge" || out["analytics_from"] != "app" {
+ t.Fatalf("owner --analytics = %d %v", st, out)
+ }
+ // Owner, --no-analytics matches the default: nothing written.
+ st, out = create(owner, `{"name":"api-off","analytics":"off"}`)
+ if st != http.StatusOK || out["analytics"] != "off" || out["analytics_from"] != "default" || appAnalyticsObject(t, fx, "api-off") {
+ t.Fatalf("owner --no-analytics = %d %v", st, out)
+ }
+ // No flag: follows the account, and the echo says so.
+ st, out = create(member, `{"name":"api-plain"}`)
+ if st != http.StatusOK || out["analytics"] != "off" || out["analytics_from"] != "default" {
+ t.Fatalf("member, no flag = %d %v", st, out)
+ }
+ // A member asking for something else is refused before the claim.
+ st, out = create(member, `{"name":"api-member","analytics":"edge"}`)
+ if st != http.StatusForbidden || out["error"] != newAppAnalyticsNotOwnerMsg {
+ t.Fatalf("member --analytics = %d %v, want 403 %q", st, out, newAppAnalyticsNotOwnerMsg)
+ }
+ if has, _ := fx.st.HasAppIn(OpsAccountID, "api-member"); has {
+ t.Fatal("the refused create still claimed the name")
+ }
+ if st, _ = create(owner, `{"name":"api-bad","analytics":"browser"}`); st != http.StatusBadRequest {
+ t.Fatalf("analytics=browser = %d, want 400", st)
+ }
+}
diff --git a/internal/console/analyticsonramp.go b/internal/console/analyticsonramp.go
new file mode 100644
index 000000000..a67db6203
--- /dev/null
+++ b/internal/console/analyticsonramp.go
@@ -0,0 +1,135 @@
+package console
+
+// The analytics on-ramp's create-time half
+// (docs/superpowers/plans/2026-10-26-analytics-onramp.md, items 2 and 3):
+// a new app's analytics choice, made on either create door, and the account
+// setting a new account starts with. Both reuse the telemetry objects the
+// settings doors write (analyticsview.go); there is no new storage.
+
+import (
+ "context"
+ "errors"
+ "log"
+
+ "github.com/carlosframework/platform/internal/telemetry"
+)
+
+// errAnalyticsNotOwner is a create that asked for analytics different from
+// the account's default, from someone who is not an owner. Only an owner may
+// change analytics (the settings doors' owner gate), so the create is refused
+// before the name is claimed rather than the choice being quietly dropped.
+var errAnalyticsNotOwner = errors.New("console: only an owner can choose analytics for a new app")
+
+// Copy deck 2026-10-26-analytics-onramp-copy.md, AN-C17 (browser) and
+// AN-C36 (the API, printed by the CLI).
+const (
+ newAppAnalyticsNotOwnerFlash = "Only an owner can change analytics for a new app. Nothing was created."
+ newAppAnalyticsNotOwnerMsg = "only an owner can choose analytics for a new app. Leave out --analytics and --no-analytics to follow the account"
+)
+
+// newAppAnalyticsSaveFailedFlash is AN-C18: the app exists, its analytics
+// choice did not stick, and the owner is told where to set it.
+func newAppAnalyticsSaveFailedFlash(app string) string {
+ return "Created app " + app + ", but its analytics setting could not be saved. Set it in Settings, under Errors and analytics."
+}
+
+// accountAnalyticsDefault is what an app without its own setting resolves
+// to in this account: the account object folded over the built-in default.
+// No deployment bucket resolves to the built-in default, as Resolve does.
+func (s *Server) accountAnalyticsDefault(ctx context.Context, sqid string) (telemetry.Resolved, error) {
+ if s.cfg.Releases == nil {
+ return telemetry.Fold(telemetry.Settings{}, telemetry.Settings{}), nil
+ }
+ st, _, err := telemetry.Read(ctx, s.cfg.Releases, telemetry.AccountKey(sqid))
+ if err != nil {
+ return telemetry.Fold(telemetry.Settings{}, telemetry.Settings{}), err
+ }
+ return telemetry.Fold(st, telemetry.Settings{}), nil
+}
+
+// checkNewAppAnalytics runs before the claim. choice is "" (follow the
+// account), telemetry.CountEdge or telemetry.CountOff, already validated. An
+// owner may choose either. Anyone else may only name what the account
+// already resolves to, which writes nothing; a default that cannot be read
+// refuses rather than guessing.
+func (s *Server) checkNewAppAnalytics(ctx context.Context, sqid, choice string, owner bool) error {
+ if choice == "" || owner {
+ return nil
+ }
+ def, err := s.accountAnalyticsDefault(ctx, sqid)
+ if err != nil {
+ return err
+ }
+ if def.Count != choice {
+ return errAnalyticsNotOwner
+ }
+ return nil
+}
+
+// applyNewAppAnalytics runs after a successful claim. It gives the app its
+// own setting only when the choice differs from what the app resolves to
+// (the account's default, for a new name); a choice matching it writes
+// nothing, so the app goes on following the account. The write is the app
+// settings door's: the same mutation, audit row and serial bump.
+//
+// Only an owner's choice is written. checkNewAppAnalytics let a non-owner
+// through only when the choice matched the account, so a difference seen
+// here means the default moved in between; the app then follows the account,
+// which is what the non-owner could have had anyway.
+func (s *Server) applyNewAppAnalytics(ctx context.Context, acct *Account, app, addr, choice string, owner bool) error {
+ if choice == "" || !owner || s.cfg.Releases == nil {
+ return nil
+ }
+ res, err := telemetry.Resolve(ctx, s.cfg.Releases, acct.Sqid, app)
+ if err != nil {
+ return err
+ }
+ if res.Count == choice {
+ return nil
+ }
+ if err := s.updateAppTelemetry(ctx, acct, app, "analytics-setting", func(st *telemetry.Settings) {
+ mergeAnalytics(st, choice, "")
+ }); err != nil {
+ return err
+ }
+ s.audit(acct, app, addr, "analytics-setting", "set "+analyticsAudit(choice, "")+" for this app")
+ s.bumpSerial(ctx)
+ return nil
+}
+
+// newAppAnalyticsView is the Create an app form's analytics block: the
+// account's default, which the checkbox starts from. nil hides the block
+// (no bucket, or a default that could not be read), and the app then
+// follows the account.
+type newAppAnalyticsView struct {
+ On bool
+}
+
+func (s *Server) newAppAnalytics(ctx context.Context, sqid string) *newAppAnalyticsView {
+ if s.cfg.Releases == nil {
+ return nil
+ }
+ def, err := s.accountAnalyticsDefault(ctx, sqid)
+ if err != nil {
+ log.Printf("console: new app form %s: read analytics default: %v", sqid, err)
+ return nil
+ }
+ return &newAppAnalyticsView{On: def.Count == telemetry.CountEdge}
+}
+
+// startNewAccountAnalytics writes analytics on as a new account's own
+// setting (plan item 3): new accounts count from the start, and an owner can
+// turn it off in the account's Settings. Accounts that already exist have no
+// such object written, so they keep the built-in default. Best-effort: an
+// account that could not take the setting still exists and simply starts
+// with analytics off, which is how every account began before.
+func (s *Server) startNewAccountAnalytics(ctx context.Context, sqid string) {
+ if s.cfg.Releases == nil {
+ return
+ }
+ if err := telemetry.Update(ctx, s.cfg.Releases, telemetry.AccountKey(sqid), func(st *telemetry.Settings) {
+ mergeAnalytics(st, telemetry.CountEdge, "")
+ }); err != nil {
+ log.Printf("console: new account %s: could not turn analytics on: %v", sqid, err)
+ }
+}
diff --git a/internal/console/apicli.go b/internal/console/apicli.go
index 6746db73b..18537caeb 100644
--- a/internal/console/apicli.go
+++ b/internal/console/apicli.go
@@ -31,6 +31,7 @@ import (
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/svcrole"
+ "github.com/carlosframework/platform/internal/telemetry"
"github.com/carlosframework/platform/internal/version"
)
@@ -405,12 +406,35 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) {
BuildProbe string `json:"build_probe"`
Region string `json:"region"`
Timezone string `json:"timezone"`
+ // Analytics is the new app's counting choice (`carlos apps create
+ // --analytics/--no-analytics`): "" follows the account, otherwise
+ // edge or off. An older console ignores the key; the "analytics"
+ // echo below is how the CLI tells.
+ Analytics string `json:"analytics"`
}
if !readJSON(w, r, &req) {
return
}
name := normalizeAppName(req.Name)
place := strings.TrimSpace(req.Place)
+ // Like control_plane: a choice the caller may not make refuses the whole
+ // create before the claim. Only a person who owns the account may choose
+ // analytics different from the account's; a service credential holds no
+ // role, so it may only name what the account already has.
+ analyticsOwner := p.Kind == PrincipalUser && acct.Role == RoleOwner
+ if req.Analytics != "" && !validCount(req.Analytics) {
+ jsonError(w, http.StatusBadRequest, `analytics must be "edge", "off" or absent`)
+ return
+ }
+ if err := s.checkNewAppAnalytics(r.Context(), acct.Sqid, req.Analytics, analyticsOwner); err != nil {
+ if errors.Is(err, errAnalyticsNotOwner) {
+ jsonError(w, http.StatusForbidden, newAppAnalyticsNotOwnerMsg)
+ return
+ }
+ log.Printf("console: api create %s/%s: read analytics default: %v", acct.Sqid, name, err)
+ jsonError(w, http.StatusBadGateway, "could not read the account's analytics setting. Try again")
+ return
+ }
// Validated BEFORE claimApp, like place: a refused flag refuses the WHOLE
// create rather than leaving a claimed name with the wrong shape, and a
// shape the server is certain to refuse costs no claim attempt.
@@ -533,6 +557,17 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) {
"build_probe": gotProbe,
}
s.echoCreatedRegion(r.Context(), acct, name, out)
+ // "analytics" and "analytics_from" echo what the app now resolves to,
+ // read back after the write, so the CLI compares that with what it
+ // asked for. A failed write leaves the app following the account.
+ if err := s.applyNewAppAnalytics(r.Context(), acct, name, addr, req.Analytics, analyticsOwner); err != nil {
+ log.Printf("console: api create %s/%s: analytics setting: %v", acct.Sqid, name, err)
+ }
+ if res, err := telemetry.Resolve(r.Context(), s.cfg.Releases, acct.Sqid, name); err != nil {
+ log.Printf("console: api create %s/%s: read back analytics: %v", acct.Sqid, name, err)
+ } else {
+ out["analytics"], out["analytics_from"] = res.Count, res.CountFrom
+ }
writeJSON(w, http.StatusOK, out)
default:
// Any future claimOutcome lands here rather than silently 200ing
diff --git a/internal/console/approved_analytics_onramp_copy_test.go b/internal/console/approved_analytics_onramp_copy_test.go
index c26aa8fc1..782a819ae 100644
--- a/internal/console/approved_analytics_onramp_copy_test.go
+++ b/internal/console/approved_analytics_onramp_copy_test.go
@@ -21,6 +21,10 @@ const onrampCopyDeckPath = "../../docs/superpowers/plans/2026-10-26-analytics-on
// be in its file, and any other row's named test must exist.
var onrampCopyBuilt = map[string]bool{
"AN-C01": true, "AN-C02": true, "AN-C03": true, "AN-C04": true, "AN-C05": true, "AN-C06": true,
+ "AN-C10": true, "AN-C11": true, "AN-C12": true, "AN-C13": true, "AN-C14": true, "AN-C15": true,
+ "AN-C16": true, "AN-C17": true, "AN-C18": true, "AN-C19": true, "AN-C20": true, "AN-C21": true,
+ "AN-C22": true, "AN-C30": true, "AN-C31": true, "AN-C32": true, "AN-C33": true, "AN-C34": true,
+ "AN-C35": true, "AN-C36": true, "AN-C40": true, "AN-C41": true, "AN-C42": true,
}
// onrampCopyTestFiles are the test sources a non-gate row's test may live in:
diff --git a/internal/console/regionpicker_test.go b/internal/console/regionpicker_test.go
index 2a36efc90..e7b4aa64c 100644
--- a/internal/console/regionpicker_test.go
+++ b/internal/console/regionpicker_test.go
@@ -18,13 +18,24 @@ import (
func has(body, plain string) bool { return strings.Contains(body, html.EscapeString(plain)) }
// newAppFormGolden is the base tree's own rendering of the create-app form
-// (the branch base, switch off), with the session's CSRF value blanked.
+// (the branch base, switch off), with the session's CSRF value blanked, plus
+// the analytics on-ramp's checkbox block as an owner sees it on an account
+// whose default is off (analyticsonramp.go): the picker's absence is what
+// this pins, and the analytics block sits where the picker would.
const newAppFormGolden = `<form class="signin" method="post" action="/a/bab/apps/new">
<input type="hidden" name="csrf" value="CSRF">
<label class="visually-hidden" for="app-name">App name</label>
<input id="app-name" type="text" name="name" placeholder="my-app" autofocus
required pattern="[A-Za-z][A-Za-z0-9-]{0,31}" maxlength="32">
+ <label><input type="checkbox" name="count" value="edge">
+ Count page views and visitors with analytics</label>
+ <input type="hidden" name="count" value="off">
+ <p class="small">No JavaScript, no cookie, no stored IP.
+ This account's default is off.</p>
<button type="submit">Create app</button>
+ <input type="hidden" name="back" value="new-app">
+ <button type="submit" class="btn-sm" formaction="/a/bab/analytics/setting" formnovalidate>Make this the account default</button>
+ <p class="small">The account default also applies to every existing app without its own setting.</p>
</form>`
// newAppForm is the rendered <form>…</form>, CSRF value blanked.
diff --git a/internal/console/server.go b/internal/console/server.go
index 93ce5ce98..4632a2d6e 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -2010,6 +2010,9 @@ func normalizeHost(host string) string {
// page is the one bag every template reads from; unused fields are ignored.
type page struct {
RegionPicker *regionPickerView // new-app page: nil = no picker
+ // NewAppAnalytics is the new-app page's analytics checkbox: nil = no
+ // checkbox, and the app follows the account (analyticsonramp.go).
+ NewAppAnalytics *newAppAnalyticsView
AccountStore *accountStoreView
StoreQueue *storeQueueView
@@ -2673,6 +2676,7 @@ func (s *Server) mintAccount(ctx context.Context, name, ownerAddr string) (*Acco
if err := s.store.SetLastAccount(ownerAddr, id); err != nil {
log.Printf("console: set last account for %s: %v", ownerAddr, err)
}
+ s.startNewAccountAnalytics(ctx, sqid)
return &Account{ID: id, Sqid: sqid, Name: name, Role: RoleOwner, CreatedAt: now}, nil
}
@@ -4893,6 +4897,7 @@ func (s *Server) handleNewAppForm(w http.ResponseWriter, r *http.Request) {
p.Title = "Create an app"
p.ActiveNav = "apps"
p.RegionPicker = s.newAppPicker(r.Context(), s.personIP(r))
+ p.NewAppAnalytics = s.newAppAnalytics(r.Context(), acct.Sqid)
s.render(w, http.StatusOK, "app_new", p)
}
@@ -4929,6 +4934,26 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) {
fail(regionCopy.Unavailable)
return
}
+ // The analytics checkbox (the on-ramp): "count" is edge or off from an
+ // owner's form, absent from a member's (whose checkbox is disabled) and
+ // from any older form, which then follows the account. A member's
+ // hand-written choice that differs from the account is refused here,
+ // before the claim, rather than silently dropped.
+ owner := role == RoleOwner
+ choice := r.FormValue("count")
+ if choice != "" && !validCount(choice) {
+ fail("Choose edge or off for counting.")
+ return
+ }
+ if err := s.checkNewAppAnalytics(r.Context(), acct.Sqid, choice, owner); err != nil {
+ if errors.Is(err, errAnalyticsNotOwner) {
+ fail(newAppAnalyticsNotOwnerFlash)
+ return
+ }
+ log.Printf("console: create %s/%s: read analytics default: %v", acct.Sqid, name, err)
+ fail("Could not create the app. Please try again.")
+ return
+ }
// The browser door never places at create time, so the second return
// (what actually stuck) is "" here and there is nothing to echo it to —
// this form has no placement concept at all. With
@@ -4944,7 +4969,7 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) {
fail("Could not create the app. Please try again.")
return
}
- outcome, msg, held := s.claimApp(r.Context(), acct, name, addr, "", role == RoleOwner, rq)
+ outcome, msg, held := s.claimApp(r.Context(), acct, name, addr, "", owner, rq)
switch outcome {
case claimInvalid:
fail("Invalid app name — lowercase letters, digits, and dashes, starting with a letter.")
@@ -4973,7 +4998,14 @@ func (s *Server) handleNewApp(w http.ResponseWriter, r *http.Request) {
detail = fmt.Sprintf(regionCopy.AuditCreated, name, regionlabel.ForCode(region, s.regionHome(), s.regionNames()).Text)
}
s.audit(acct, name, addr, "create", detail)
- s.setFlash(w, "ok", "Created app "+name+" — it's yours.")
+ // After the claim, like the CLI door's flags: a failed write leaves the
+ // app created and following the account, and says so.
+ if err := s.applyNewAppAnalytics(r.Context(), acct, name, addr, choice, owner); err != nil {
+ log.Printf("console: create %s/%s: analytics setting: %v", acct.Sqid, name, err)
+ s.setFlash(w, "err", newAppAnalyticsSaveFailedFlash(name))
+ } else {
+ s.setFlash(w, "ok", "Created app "+name+" — it's yours.")
+ }
http.Redirect(w, r, home+"apps/"+url.PathEscape(name), http.StatusSeeOther)
}
}
diff --git a/internal/console/templates/account_settings.html b/internal/console/templates/account_settings.html
index 43513848b..546b94865 100644
--- a/internal/console/templates/account_settings.html
+++ b/internal/console/templates/account_settings.html
@@ -203,8 +203,8 @@ concluding anything.</p>
{{end}}
<p class="small">When on, the edge counts HTML page views and daily visitors as it serves them: no
JavaScript, no cookie, no stored IP. A visitor is a salted hash that changes every day and cannot be
-joined across days. Whether that needs consent where your visitors are is your call, which is why it
-is off until you turn it on.</p>
+joined across days. Whether that needs consent where your visitors are is your call. New accounts
+start with analytics on.</p>
<h2>Delete this account</h2>
{{if .HasApps}}
diff --git a/internal/console/templates/app_new.html b/internal/console/templates/app_new.html
index efd6e13b1..25424081d 100644
--- a/internal/console/templates/app_new.html
+++ b/internal/console/templates/app_new.html
@@ -39,7 +39,29 @@
.catch(function () {});
})();
</script>{{end}}
+ {{- /* The checkbox comes before the hidden "off": a ticked box posts
+ count=edge first, and FormValue reads the first value. A member's box
+ is disabled and posts nothing, so the app follows the account. */}}
+ {{- with .NewAppAnalytics}}
+ <label><input type="checkbox" name="count" value="edge"{{if .On}} checked{{end}}{{if not $.IsOwner}} disabled{{end}}>
+ Count page views and visitors with analytics</label>
+ {{- if $.IsOwner}}
+ <input type="hidden" name="count" value="off">
+ {{- end}}
+ <p class="small">No JavaScript, no cookie, no stored IP.
+ {{if .On}}This account's default is on.{{else}}This account's default is off.{{end}}
+ {{- if not $.IsOwner}} Only an owner can change this.{{end}}</p>
+ {{- end}}
<button type="submit">Create app</button>
+ {{- /* After Create app on purpose: Enter in the name field presses the
+ form's first submit button, and that must create the app, never
+ change the account default. This one posts the same form to the
+ account's analytics door, which comes back here (back=new-app). */}}
+ {{- if and .NewAppAnalytics .IsOwner}}
+ <input type="hidden" name="back" value="new-app">
+ <button type="submit" class="btn-sm" formaction="{{.Base}}/analytics/setting" formnovalidate>Make this the account default</button>
+ <p class="small">The account default also applies to every existing app without its own setting.</p>
+ {{- end}}
</form>
<p class="small">Names are lowercase letters, digits, and dashes, starting with a letter — unique within this account, not across the platform.</p>
{{template "bottom" .}}{{end}}
diff --git a/internal/console/templates/app_settings.html b/internal/console/templates/app_settings.html
index 6ec60d656..09be4156e 100644
--- a/internal/console/templates/app_settings.html
+++ b/internal/console/templates/app_settings.html
@@ -438,8 +438,8 @@ the {{.AnalyticsSetting.CountFrom}}. Only the account owner can change it.</p>
{{end}}
<p class="small">When on, the edge counts HTML page views and daily visitors as it serves them: no
JavaScript, no cookie, no stored IP. A visitor is a salted hash that changes every day and cannot be
-joined across days. Whether that needs consent where your visitors are is your call, which is why it
-is off until you turn it on.</p>
+joined across days. Whether that needs consent where your visitors are is your call. New accounts
+start with analytics on.</p>
{{end}}
{{if eq .SettingsSection "general"}}
<h2>{{.SwapCopy.Heading}}</h2>