{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "Track calculator usage, lead generation, and conversion metrics from Lambda logs",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 1,
  "id": 275620980383744,
  "links": [],
  "panels": [
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "blue",
                "value": 0
              },
              {
                "color": "green",
                "value": 100
              },
              {
                "color": "yellow",
                "value": 500
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "percentChangeColorMode": "standard",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showPercentChange": false,
        "textMode": "auto",
        "wideLayout": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT count() AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated')",
          "refId": "A"
        }
      ],
      "title": "Total Calculations",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": 0
              },
              {
                "color": "yellow",
                "value": 10
              },
              {
                "color": "green",
                "value": 50
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 6,
        "y": 0
      },
      "id": 2,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "percentChangeColorMode": "standard",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showPercentChange": false,
        "textMode": "auto",
        "wideLayout": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "rawSql": "SELECT count() AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated'",
          "refId": "A"
        }
      ],
      "title": "Leads Generated",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "max": 100,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "red",
                "value": 0
              },
              {
                "color": "yellow",
                "value": 5
              },
              {
                "color": "green",
                "value": 10
              }
            ]
          },
          "unit": "percent"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 12,
        "y": 0
      },
      "id": 3,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "percentChangeColorMode": "standard",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showPercentChange": false,
        "textMode": "auto",
        "wideLayout": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT round(countIf(json_data.event::String = 'roi_generated') / count() * 100, 2) AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated')",
          "refId": "A"
        }
      ],
      "title": "Conversion Rate",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 4,
        "w": 6,
        "x": 18,
        "y": 0
      },
      "id": 4,
      "options": {
        "colorMode": "background",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "auto",
        "percentChangeColorMode": "standard",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "showPercentChange": false,
        "textMode": "auto",
        "wideLayout": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT uniq(json_data.ipAddress::String) AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated')",
          "refId": "A"
        }
      ],
      "title": "Unique Users",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "barWidthFactor": 0.6,
            "drawStyle": "line",
            "fillOpacity": 10,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "insertNulls": false,
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "showValues": false,
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 24,
        "x": 0,
        "y": 4
      },
      "id": 5,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "hideZeros": false,
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {
            "alias": "Total Calculations"
          },
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT toStartOfHour(timestamp) AS time, count() AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated') GROUP BY time ORDER BY time",
          "refId": "Total Calculations"
        },
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {
            "alias": "Leads Generated"
          },
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT toStartOfHour(timestamp) AS time, count() AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated' GROUP BY time ORDER BY time",
          "refId": "Leads Generated"
        },
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {
            "alias": "Unique Users"
          },
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT toStartOfHour(timestamp) AS time, uniq(json_data.ipAddress::String) AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated') GROUP BY time ORDER BY time",
          "refId": "Unique Users"
        }
      ],
      "title": "Calculations & Leads Over Time",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "barWidthFactor": 0.6,
            "drawStyle": "line",
            "fillOpacity": 20,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "insertNulls": false,
            "lineInterpolation": "linear",
            "lineWidth": 2,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "showValues": false,
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "max": 100,
          "min": 0,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "percent"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 12
      },
      "id": 6,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "hideZeros": false,
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT toStartOfDay(timestamp) AS time, round(countIf(json_data.event::String = 'roi_generated') / count() * 100, 2) AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated') GROUP BY time ORDER BY time",
          "refId": "A"
        }
      ],
      "title": "Conversion Rate Trend",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "barWidthFactor": 0.6,
            "drawStyle": "line",
            "fillOpacity": 10,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "insertNulls": false,
            "lineInterpolation": "linear",
            "lineWidth": 1,
            "pointSize": 5,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "showValues": false,
            "spanNulls": false,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "currencyUSD"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 12
      },
      "id": 7,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "tooltip": {
          "hideZeros": false,
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT toStartOfDay(timestamp) AS time, avg(json_data.observabilitySpend::Float64) AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated' GROUP BY time ORDER BY time",
          "refId": "A"
        }
      ],
      "title": "Average Observability Spend (Leads Only)",
      "type": "timeseries"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "footer": {
              "reducers": []
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Current Spend"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "3-Year Savings"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 20
      },
      "id": 8,
      "options": {
        "cellHeight": "sm",
        "showHeader": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "rawSql": "SELECT timestamp, json_data.name::String AS Name, json_data.email::String AS Email, json_data.observabilitySpend::Float64 AS \"Current Spend\", json_data.savings3Year::Float64 AS \"3-Year Savings\" FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated' ORDER BY timestamp DESC LIMIT 50",
          "refId": "A"
        }
      ],
      "title": "Latest Leads",
      "type": "table"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "footer": {
              "reducers": []
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Current Spend"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Potential Savings"
            },
            "properties": [
              {
                "id": "unit",
                "value": "currencyUSD"
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 20
      },
      "id": 9,
      "options": {
        "cellHeight": "sm",
        "showHeader": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT timestamp, json_data.name::String AS Name, json_data.email::String AS Email, json_data.observabilitySpend::Float64 AS \"Current Spend\", json_data.savings3Year::Float64 AS \"Potential Savings\", json_data.savingsPercentage::Float64 AS \"Savings Percent\" FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated' AND json_data.observabilitySpend::Float64 > 100000 ORDER BY json_data.observabilitySpend::Float64 DESC LIMIT 50",
          "refId": "A"
        }
      ],
      "title": "High-Value Leads (>$100K spend)",
      "type": "table"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            }
          },
          "mappings": []
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 0,
        "y": 28
      },
      "id": 10,
      "options": {
        "legend": {
          "displayMode": "table",
          "placement": "right",
          "showLegend": true
        },
        "pieType": "donut",
        "reduceOptions": {
          "calcs": [
            "lastNotNull"
          ],
          "fields": "",
          "values": false
        },
        "sort": "desc",
        "tooltip": {
          "hideZeros": false,
          "mode": "single",
          "sort": "none"
        }
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "SELECT concat(toString(json_data.engagementMonths), ' months') AS engagement, count() AS value FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated' GROUP BY engagement ORDER BY engagement",
          "refId": "A"
        }
      ],
      "title": "Engagement Tier Distribution (Leads)",
      "type": "piechart"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "fillOpacity": 80,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineWidth": 1,
            "scaleDistribution": {
              "type": "linear"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 8,
        "y": 28
      },
      "id": 11,
      "options": {
        "barRadius": 0,
        "barWidth": 0.97,
        "fullHighlight": false,
        "groupWidth": 0.7,
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": true
        },
        "orientation": "horizontal",
        "showValue": "auto",
        "stacking": "none",
        "tooltip": {
          "hideZeros": false,
          "mode": "single",
          "sort": "none"
        },
        "xTickLabelRotation": 0,
        "xTickLabelSpacing": 0
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "rawSql": "SELECT CASE WHEN json_data.observabilitySpend::Float64 > 500000 THEN 'A - High' WHEN json_data.observabilitySpend::Float64 > 100000 THEN 'B - Medium' ELSE 'C - Small' END AS tier, count() AS count FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String = 'roi_generated' GROUP BY tier ORDER BY tier",
          "refId": "A"
        }
      ],
      "title": "Lead Quality Distribution",
      "type": "barchart"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource"
      },
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "footer": {
              "reducers": []
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 8,
        "x": 16,
        "y": 28
      },
      "id": 12,
      "options": {
        "cellHeight": "sm",
        "showHeader": true
      },
      "pluginVersion": "12.4.0-20781422371.patch3",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource"
          },
          "editorType": "sql",
          "format": 1,
          "meta": {},
          "pluginVersion": "4.12.0",
          "queryType": "table",
          "rawSql": "WITH last_events AS (SELECT json_data.ipAddress::String AS ip, argMax(json_data.event::String, timestamp) AS last_event, argMax(json_data.email::String, timestamp) AS email, count() AS total_events, max(timestamp) AS last_seen FROM lambda_logs WHERE $__timeFilter(timestamp) AND json_data.event::String IN ('calculation_tracked', 'roi_generated') GROUP BY ip) SELECT ip, last_event AS \"Last Event\", email AS Email, total_events AS \"Total Events\", last_seen AS \"Last Seen\" FROM last_events WHERE total_events > 1 ORDER BY total_events DESC LIMIT 50",
          "refId": "A"
        }
      ],
      "title": "Repeat Users (Deduplicated - Last Event per IP)",
      "type": "table"
    }
  ],
  "preload": false,
  "refresh": "5m",
  "schemaVersion": 42,
  "tags": [
    "lambda",
    "roi-calculator",
    "leads",
    "crm"
  ],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-30d",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "utc",
  "title": "ROI Calculator - Lead Generation Analytics",
  "uid": "7848559d-dcee-4f1d-9407-ec938391a9b0",
  "version": 7,
  "weekStart": ""
}
