{
  "license": "CC BY 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by/4.0/",
  "recipe": {
    "slug": "time-to-activation-distribution",
    "title": "Measure Time to Activation",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-27"
  },
  "contract": {
    "tableName": "product_events",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Event time."
      },
      {
        "name": "user_id",
        "type": "Utf8",
        "description": "Stable user identifier."
      },
      {
        "name": "event_name",
        "type": "Utf8",
        "description": "Signup or activation milestone."
      }
    ]
  },
  "query": "WITH milestones AS (\n  SELECT\n    user_id,\n    MIN(CASE\n      WHEN event_name = 'signup_completed' THEN timestamp_utc\n    END) AS signed_up_at,\n    MIN(CASE\n      WHEN event_name = 'first_meaningful_action_completed' THEN timestamp_utc\n    END) AS activated_at\n  FROM product_events\n  WHERE timestamp_utc >= now() - INTERVAL '90 days'\n  GROUP BY user_id\n)\nSELECT\n  CASE\n    WHEN activated_at - signed_up_at < INTERVAL '10 minutes' THEN 'under 10m'\n    WHEN activated_at - signed_up_at < INTERVAL '1 hour' THEN '10m–1h'\n    WHEN activated_at - signed_up_at < INTERVAL '1 day' THEN '1h–1d'\n    WHEN activated_at - signed_up_at < INTERVAL '7 days' THEN '1d–7d'\n    ELSE '7d+'\n  END AS activation_window,\n  COUNT(*) AS users\nFROM milestones\nWHERE signed_up_at IS NOT NULL\n  AND activated_at >= signed_up_at\nGROUP BY activation_window\nORDER BY users DESC;",
  "fixtureKind": "schema-example",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "user_id": "user_1",
      "event_name": "workflow_completed"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "user_id": "user_2",
      "event_name": "workflow_completed"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "user_id": "user_3",
      "event_name": "workflow_completed"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "user_id": "user_1",
      "event_name": "workflow_completed"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "user_id": "user_2",
      "event_name": "workflow_completed"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "user_id": "user_3",
      "event_name": "workflow_completed"
    }
  ],
  "expectedOutput": {
    "columns": [
      "activation_window",
      "users"
    ],
    "rows": [
      {
        "activation_window": "under 10m",
        "users": 182
      },
      {
        "activation_window": "10m–1h",
        "users": 264
      },
      {
        "activation_window": "1h–1d",
        "users": 318
      },
      {
        "activation_window": "1d–7d",
        "users": 146
      },
      {
        "activation_window": "7d+",
        "users": 38
      }
    ]
  },
  "notes": [
    "The compact input rows demonstrate field names and JSON types; they are not claimed to generate the displayed aggregate by themselves.",
    "The expected output is deterministic synthetic review data for the documented output shape.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}