I used the following code to query Google Analytics data from BigQuery. I only selected a few metrics but seeing from the results, it gives me everything starts with "product".
#standardSQL
SELECT
date, prod.productRevenue,
hits.transaction.transactionId,
prod.productQuantity, hits.product, prod.productSKU
FROM `XXX.ga_sessions_*`,
UNNEST(hits) AS hits,
UNNEST(hits.product) AS prod
WHERE _TABLE_SUFFIX BETWEEN 'XXX' AND 'XXX' AND hits.transaction.transactionId IS NOT NULL
Is this because I used UNNEST? If so what should I do to only query the columns I have selected?
Also, is there a good way to clean the results data? The results data look like this:
v2ProductName:"AAA" productQuantity:"1" transactionId:"123"
v2ProductName:"BBB" productQuantity:"1" transactionId:"456"
But what I want is:
+---------------+-----------------+---------------+
| v2ProductName | productQuantity | transactionId |
+---------------+-----------------+---------------+
| AAA | 1 | 123 |
| BBB | 1 | 456 |
+---------------+-----------------+---------------+
Is there a way to format the results like this before exporting it from BigQuery? If not, is there a good way to do that?