google-analytics - 使用 Google Big Query 为嵌套表选择每个着陆页的收入

标签 google-analytics google-bigquery

我正在尝试使用 Google Big Query 并弄清楚如何复制 London Cycle Helmet GA 样本数据的一些标准报告。我偶然发现的一个简单示例是选择按着陆页划分的收入总和。

嵌套表对我来说是新事物,我正在努力寻找任何使用标准 SQL 执行此操作或类似操作的示例。

如何使用标准 SQL 来完成此操作?或者有人可以向我指出任何类似的例子吗?

更新

对于没有预先提供更多详细信息,我们深表歉意。我已经取得了一些进展,使我能够发布一些代码。我对数据结构有了更好的理解,并尝试像这样取消嵌套:

#StandardSQL
SELECT Visit_ID, h.page.pagePath AS LandingPage, Sales, Revenue
FROM (
  SELECT
    visitID AS Visit_ID,
    h.hitNumber,
    h.page.pagePath
  FROM
    `project_id.dataset.table`, UNNEST(hits) as h
)  AS landingpages
JOIN (
  SELECT
      fullVisitorId AS Visit_ID, sum(totals.transactions) AS Sales, (sum(totals.transactionRevenue)/1000000) AS Revenue
    FROM
      `project_id.dataset.table`
    WHERE
      totals.visits>0
      AND totals.transactions>=1
      AND totals.transactionRevenue IS NOT NULL
    GROUP BY
      fullVisitorId
) AS sales
ON landingpages.Visit_ID = sales.Visit_ID

这会引发错误:

No matching signature for operator = for argument types: INT64, STRING. Supported signature: ANY = ANY at [23:4]

我认为这已经差不多了,但我不明白它想告诉我什么。我该如何修复这个连接?

最佳答案

No matching signature for operator = for argument types: INT64, STRING. Supported signature: ANY = ANY at [23:4]
I don't understand what it's trying to tell me.

您正在尝试加入两个完全不同领域的平等。
它们不仅在值(value)观上不同,甚至在类型上也不同

Field Name      Data Type   Description
fullVisitorId   STRING      The unique visitor ID (also known as client ID).
visitId         INTEGER     An identifier for this session. This is part of the value usually stored as the _utmb cookie. This is only unique to the user. For a completely unique ID, you should use a combination of fullVisitorId and visitId.  

How can I fix this join?

尝试如下(我不是 GA 人员[在帖子中添加了相应的标签],但至少它应该有助于进行下一步 - 我尝试尽可能地保留/重用您的原始代码)

#StandardSQL
WITH landingpages AS (
  SELECT
    fullVisitorId,
    visitID,
    h.page.pagePath AS LandingPage
  FROM
    `project_id.dataset.table`, UNNEST(hits) AS h
  WHERE hitNumber = 1
), 
sales AS (
   SELECT
      fullVisitorId, visitID, SUM(totals.transactions) AS Transactions , (SUM(totals.transactionRevenue)/1000000) AS Revenue
    FROM
      `project_id.dataset.table`
    WHERE
      totals.visits > 0
      AND totals.transactions >= 1
      AND totals.transactionRevenue IS NOT NULL
    GROUP BY fullVisitorId, visitID
)
SELECT 
  LandingPage, 
  SUM(Transactions) AS Transactions, 
  SUM(Revenue) AS Revenue
FROM landingpages 
JOIN sales
ON landingpages.VisitID = sales.VisitID 
AND landingpages.fullVisitorId = sales.fullVisitorId
GROUP BY LandingPage

关于google-analytics - 使用 Google Big Query 为嵌套表选择每个着陆页的收入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39894328/

相关文章:

ipython - 如何在 IPython 中使用 read_gbq 或其他 bq 访问 BigQuery 中托管的数据集

node.js - 将数据从 node.js 添加到 Google BigQuery 表

javascript - JavaScript 中的 Google Analytics 图表

google-analytics - 核心报告 API 和新的实时报告 API 之间有什么区别?

google-analytics - 电子商务数据缺失

sql - Big Query 是否支持自定义排序?

google-bigquery - Google 大查询 UTC_USEC_TO_DAY/WEEK/MONTH/YEAR

google-analytics - Google Analytics(分析)—数据导出限制

javascript - 如何跟踪出站链接的点击次数

sql - 如何在 BigQuery 中获取连续时间戳之间的差异