GA和BigQuery之间的Google Analytics(分析)用户,交易和收入略有下降

时间:2018-10-08 15:04:49

标签: google-analytics google-bigquery standard-sql

我有一个相当简单的查询。对我来说最奇怪的部分是,例如,有些小时的收入会高出一千美元左右,而有些小时的收入会有点低。

我处于与BigQuery项目关联的视图中,并且没有选择任何细分。

这个让我有些难过。

#standardSQL
WITH
  ga_tables AS (
  SELECT
    CAST(CONCAT(SUBSTR(date,1,4),'-',SUBSTR(date,5,2),'-',SUBSTR(date,7,2)) AS DATE) AS Date,
    EXTRACT(HOUR
    FROM
      time(TIMESTAMP_SECONDS(visitStartTime),
        "America/New_York")) AS sessionHour,
    trafficSource.source AS source,
    trafficSource.medium AS medium,
    COUNT(DISTINCT fullVisitorId) AS users,
    SUM(totals.transactions) AS transactions,
    SUM(totals.transactionRevenue)/1000000 AS revenue
  FROM
    `big-query-project-34643.162968675.ga_sessions_*`
  WHERE
    _TABLE_SUFFIX BETWEEN FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 365 DAY))
    AND FORMAT_DATE('%Y%m%d',DATE_SUB(CURRENT_DATE(), INTERVAL 0 DAY))
  GROUP BY
    date,
    sessionHour,
    source,
    medium
  UNION ALL
  SELECT
    CAST(CONCAT(SUBSTR(date,1,4),'-',SUBSTR(date,5,2),'-',SUBSTR(date,7,2)) AS DATE) AS Date,
    EXTRACT(HOUR
    FROM
      time(TIMESTAMP_SECONDS(visitStartTime),
        "America/New_York")) AS sessionHour,
    trafficSource.source AS source,
    trafficSource.medium AS medium,
    COUNT(DISTINCT fullVisitorId) AS users,
    SUM(totals.transactions) AS transactions,
    SUM(totals.transactionRevenue)/1000000 AS revenue
  FROM
    `big-query-project-34643.162968675.ga_exportKey_view_2`
  GROUP BY
    date,
    sessionHour,
    source,
    medium )
SELECT
  Date AS Date,
  sessionHour,
  source,
  medium,
  users,
  transactions,
  revenue
FROM
  ga_tables
ORDER BY
  date DESC,
  sessionHour DESC

0 个答案:

没有答案