Reputation: 31
I'm trying to export data from GA using BigQuery and the Query failed.
I use this functions:
FLATTEN
TABLE_DATA_RANGE
Because I need data from hits.
Can anyone help me about this Error?
Error:
The project hits has not enabled BigQuery
Now, the error is other: Field CampaignGrouping not found:
SELECT
a.hits.contentGroup.contentGroup2 AS CampaignGrouping,
a.customDimensions.value AS member_PK,
'Web' AS Canal,
'ES' AS country_id,
count(a.hits.contentGroup.contentGroupUniqueViews2) AS VistasUnicas
FROM FLATTEN(FLATTEN(
(SELECT
hits.contentGroup.contentGroupUniqueViews2,
hits.contentGroup.contentGroup2,
customDimensions.value
FROM TABLE_DATE_RANGE([###.ga_sessions_], TIMESTAMP('2017-04-01'), TIMESTAMP('2017-04-30'))),
hits.contentGroup.contentGroupUniqueViews2), customDimensions.value
)a
WHERE hits.contentGroup.contentGroup2<>'(not set)' AND customDimensions.value<>'null' AND hits.contentGroup.contentGroupUniqueViews2 IS NOT NULL
GROUP BY 1,2,3,4
ORDER BY 5 ASC
Upvotes: 0
Views: 1658
Reputation: 11787
Solving your problem in Standard SQL is much easier than in Legacy.
This query might help you on computing this:
SELECT
hits.contentgroup.contentgroup2 CampaignGrouping,
custd.value member_PK,
'Web' Canal,
'ES' AS country_id,
SUM(hits.contentGroup.contentGroupUniqueViews2) VistasUnicas
FROM
`project_id.dataset_id.ga_sessions_*`,
UNNEST(customdimensions) custd,
UNNEST(hits) AS hits
WHERE
1 = 1
AND PARSE_TIMESTAMP('%Y%m%d', REGEXP_EXTRACT(_table_suffix, r'.*_(.*)')) BETWEEN TIMESTAMP('2017-05-01') AND TIMESTAMP('2017-05-06')
and hits.contentGroup.contentGroup2<>'(not set)'
AND custd.value<>'null'
AND hits.contentGroup.contentGroupUniqueViews2 IS NOT NULL
GROUP BY
1, 2
ORDER BY 5 ASC
You just need to enable it and it's already ready to run.
As you said you are learning SQL, it's highly recommended that you start by learning the Standard version instead of the Legacy one as it's more stable and offers several different techniques to better assist you on your analyzes.
Upvotes: 1