I am trying to create a view with the following fields: Date, values for custom dimension X, values for custom dimension Y, visitor ID, pageviews, values for content group A, values for content group B, event category, event action.
I am aware this is a lot of fields and I'm having a really hard time coming up with a solution.
Right now, I have created one view with Date, values for custom dimension X, values for custom dimension Y, visitor ID, pageviews.
I then created a second view, with Date, visitor ID, values for content group A, values for content group B, event category, event action.
I joined the two on Date and Visitor ID.
-- code below --
CREATE VIEW `TEST_1`
AS
SELECT
date AS Date,
(SELECT value FROM UNNEST(customDimensions) WHERE index=2) AS Institution_ID,
(SELECT value FROM UNNEST(customDimensions) WHERE index=3) AS Institution_Name,
fullVisitorId AS Visitor_ID,
SUM(totals.pageviews) AS Pageviews
FROM
`ga_sessions_*`
GROUP BY
date,
Visitor_ID,
Institution_ID,
Institution_Name
CREATE VIEW `TEST_2`
AS
select
DATE as DATE,
fullVisitorId AS Visitor_ID,
hits.contentGroup.contentGroup3 as Topic_Name,
hits.contentGroup.contentGroup5 as Topic_ID,
hits.eventInfo.eventCategory as Event_Category,
hits.eventInfo.eventAction as Event_Action
FROM
`ga_sessions_*`
, UNNEST (HITS) AS HITS
CREATE VIEW `TEST_3` AS
SELECT A.DATE,
A.VISITOR_ID,
Institution_ID,
Institution_Name,
Pageviews,
Topic_Name,
Topic_ID,
Event_Category,
Event_Action
FROM `TEST_1` A
JOIN `TEST_2` B ON A.DATE=B.DATE AND A.VISITOR_ID=B.VISITOR_ID
The queries run with no error, but the number of pageviews is totally wrong and much much higher than what is reported in GA. I suspect I'm duplicating rows inefficiently here.
Can someone help me out understand what I am doing wrong? Thank you so much!