SELECT
  submission_date,
  normalized_os,
  normalized_os_version,
  country_code,
  locale,
  channel,
  browser_version,
  browser_name,
  default_search_engine,
  default_private_search_engine,
  pocket_is_signed_in,
  pocket_enabled,
  pocket_sponsored_stories_enabled,
  topsites_enabled,
  topsites_sponsored_enabled,
  newtab_homepage_category,
  newtab_newtab_category,
  topsites_rows,
  is_new_profile,
  activity_segment,
  COUNT(DISTINCT client_id) AS client_count,
  COUNT(DISTINCT legacy_telemetry_client_id) AS legacy_telemetry_client_count,
  SUM(newtab_visit_count) AS newtab_visit_count,
  SUM(visits_with_non_impression_engagement) AS visits_with_non_impression_engagement,
  SUM(visits_with_non_search_engagement) AS visits_with_non_search_engagement,
  SUM(searches) AS searches,
  SUM(tagged_search_ad_clicks) AS tagged_search_ad_clicks,
  SUM(tagged_search_ad_impressions) AS tagged_search_ad_impressions,
  SUM(follow_on_search_ad_clicks) AS follow_on_search_ad_clicks,
  SUM(follow_on_search_ad_impressions) AS follow_on_search_ad_impressions,
  SUM(tagged_follow_on_search_ad_clicks) AS tagged_follow_on_search_ad_clicks,
  SUM(tagged_follow_on_search_ad_impressions) AS tagged_follow_on_search_ad_impressions,
  SUM(topsite_tile_clicks) AS topsite_tile_clicks,
  SUM(sponsored_topsite_tile_clicks) AS sponsored_topsite_tile_clicks,
  SUM(organic_topsite_tile_clicks) AS organic_topsite_tile_clicks,
  SUM(topsite_tile_impressions) AS topsite_tile_impressions,
  SUM(sponsored_topsite_tile_impressions) AS sponsored_topsite_tile_impressions,
  SUM(organic_topsite_tile_impressions) AS organic_topsite_tile_impressions,
  SUM(topsite_tile_dismissals) AS topsite_tile_dismissals,
  SUM(sponsored_topsite_tile_dismissals) AS sponsored_topsite_tile_dismissals,
  SUM(organic_topsite_tile_dismissals) AS organic_topsite_tile_dismissals,
  SUM(pocket_impressions) AS pocket_impressions,
  SUM(sponsored_pocket_impressions) AS sponsored_pocket_impressions,
  SUM(organic_pocket_impressions) AS organic_pocket_impressions,
  SUM(pocket_clicks) AS pocket_clicks,
  SUM(sponsored_pocket_clicks) AS sponsored_pocket_clicks,
  SUM(organic_pocket_clicks) AS organic_pocket_clicks,
  SUM(pocket_saves) AS pocket_saves,
  SUM(sponsored_pocket_saves) AS sponsored_pocket_saves,
  SUM(organic_pocket_saves) AS organic_pocket_saves,
FROM
  `moz-fx-data-shared-prod.telemetry_derived.newtab_clients_daily_v1`
WHERE
  {% if is_init() %}
    submission_date >= "2022-11-01"
  {% else %}
    submission_date = @submission_date
  {% endif %}
GROUP BY
  submission_date,
  normalized_os,
  normalized_os_version,
  country_code,
  locale,
  channel,
  browser_version,
  browser_name,
  default_search_engine,
  default_private_search_engine,
  pocket_is_signed_in,
  pocket_enabled,
  pocket_sponsored_stories_enabled,
  topsites_enabled,
  topsites_sponsored_enabled,
  newtab_homepage_category,
  newtab_newtab_category,
  topsites_rows,
  is_new_profile,
  activity_segment
