-- 添加缺失的UTM参数字段到shorturl_analytics.events表
-- 创建日期: 2024-07-02
-- 用途: 增强UTM参数追踪能力
-- 添加utm_term字段 (用于跟踪付费搜索关键词)
ALTER TABLE
  shorturl_analytics.events
ADD
  COLUMN utm_term String DEFAULT '' AFTER utm_campaign;

-- 添加utm_content字段 (用于区分相同广告的不同版本或A/B测试)
ALTER TABLE
  shorturl_analytics.events
ADD
  COLUMN utm_content String DEFAULT '' AFTER utm_term;

-- 验证字段添加成功
DESCRIBE TABLE shorturl_analytics.events;

-- 示例查询: 查看UTM参数分析数据
SELECT
  utm_source,
  utm_medium,
  utm_campaign,
  utm_term,
  utm_content,
  COUNT(*) as clicks
FROM
  shorturl_analytics.events
WHERE
  event_type = 'click'
  AND utm_source != ''
GROUP BY
  utm_source,
  utm_medium,
  utm_campaign,
  utm_term,
  utm_content
ORDER BY
  clicks DESC
LIMIT
  10;