0

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?

Nimantha
  • 6,405
  • 6
  • 28
  • 69
xxyb
  • 13
  • 1
  • 4

1 Answers1

0

The query you pasted doesn't seem to have any nested data.

The JSON results you pasted don't match with the query either.

Make sure your results don't contain nested/repeated data, and you'll be able to export CSVs.

Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325