-- ======================
-- ANALYTICS: Property
-- ======================
CREATE TABLE unified_analytics_property (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  timezone             text,
  currency             text,
  industry             text,
  parent_id            text,
  raw                  jsonb
);
-- ======================
-- ANALYTICS: Event
-- ======================
CREATE TABLE unified_analytics_event (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  name                 text,
  event_type           text,
  visitor_id           text,
  property_id          text,
  session_id           text,
  page_url             text,
  page_title           text,
  page_referrer        text,
  device               text,
  browser              text,
  os                   text,
  country              text,
  country_code         text,
  region               text,
  city                 text,
  metadata             jsonb,
  value                numeric,
  currency             text,
  utm_source           text,
  utm_medium           text,
  utm_campaign         text,
  utm_term             text,
  utm_content          text,
  raw                  jsonb
);
-- ======================
-- ANALYTICS: Session
-- ======================
CREATE TABLE unified_analytics_session (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  property_id          text,
  visitor_id           text,
  start_at             timestamptz,
  end_at               timestamptz,
  duration_seconds     numeric,
  landing_page         text,
  exit_page            text,
  page_views           numeric,
  events_count         numeric,
  source               text,
  medium               text,
  campaign             text,
  device               text,
  browser              text,
  os                   text,
  country              text,
  city                 text,
  is_bounce            boolean,
  is_conversion        boolean,
  raw                  jsonb
);
-- ======================
-- ANALYTICS: Visitor
-- ======================
CREATE TABLE unified_analytics_visitor (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  property_id          text,
  email                text,
  name                 text,
  age                  numeric,
  gender               text,
  country              text,
  country_code         text,
  city                 text,
  language             text,
  timezone             text,
  first_seen_at        timestamptz,
  last_seen_at         timestamptz,
  total_sessions       numeric,
  total_page_views     numeric,
  total_events         numeric,
  metadata             jsonb,
  raw                  jsonb
);
-- ======================
-- ANALYTICS: Report
-- ======================
CREATE TABLE unified_analytics_report (
  unified_connection_id  text NOT NULL,
  unified_webhook_id     text NOT NULL,
  unified_external_xref  text,
  unified_integration_type text NOT NULL,
  unified_raw_id         text,
  unified_id             text NOT NULL,
  id                   text,
  created_at           timestamptz,
  updated_at           timestamptz,
  property_id          text,
  start_at             timestamptz,
  end_at               timestamptz,
  metrics              jsonb,
  raw                  jsonb
);
