以下BigQuery SQL將檢索爲客戶購買的所有其他產品(fullVisitorId),該產品購買了名爲「大象「和一類」動物「。GA BigQuery - 購買產品x的用戶還購買了產品abc,然後僅篩選完整交易單,其中x是交易的一部分
現在是這個問題。如果同一個客戶(fullVisitorId)在同一日期範圍內發出兩個訂單。假設他或她在一次交易中購買了名爲「Tiger」的產品,再加上其他產品,然後是Tiger,那麼如果他或她在購買Elephant前一天或晚些時候做出類似訂單,這些產品也會顯示爲相關產品,因爲我的查詢是使用fullVisitorId。換句話說,一個fullVisitorId可以有一個或多個事務ID。一次交易對於當前交易購買的每件產品都具有相同的交易ID。
因此,有誰知道如何在最終購買主要產品Elephant時忽略所有其他使用不同transactionID的其他過濾器來僅顯示具有相同transactionId的相關產品的額外過濾功能嗎?
SELECT hits.product.productSKU AS other_purchased_products_sku,
hits.product.v2ProductName AS other_product_name,
hits.product.v2ProductCategory AS other_prod_category,
COUNT(hits.product.productSKU) AS quantity,
hits.transaction.transactionId AS trans_id,
fullVisitorId
FROM
(SELECT fullVisitorId,
hits.product.productSKU,
hits.eCommerceAction.action_type,
hits.product.v2ProductName,
hits.product.v2ProductCategory,
hits.transaction.transactionId
FROM TABLE_DATE_RANGE([XXXXXX.ga_sessions_], TIMESTAMP('2016-04-1'), TIMESTAMP('2016-04-30')))
WHERE fullVisitorId IN
(SELECT fullVisitorId
FROM TABLE_DATE_RANGE([XXXXXX.ga_sessions_], TIMESTAMP('2016-04-1'), TIMESTAMP('2016-04-30'))
WHERE hits.product.v2ProductCategory CONTAINS 'Animals'
AND hits.product.v2ProductName = 'Elephant'
AND hits.eCommerceAction.action_type = '6'
GROUP BY fullVisitorId)
AND hits.product.v2ProductCategory CONTAINS 'Animals'
AND hits.product.v2ProductName IS NOT NULL
AND hits.product.v2ProductName !='Elephant'
AND hits.eCommerceAction.action_type = '6'
GROUP BY other_purchased_products_sku,
other_product_name,
other_prod_category,
trans_id,
fullVisitorId
ORDER BY trans_id DESC;
嗨請問,謝謝你解決問題和質量的解釋。你也知道我可以如何添加兩個額外的列。 transaction_ga:date(YYYYMMDD),transaction_ga:isoWeek_number(1-52(如果第53周存在,則爲3)?)? –
只是在每個組內加入'date'和'week(date)'這兩個字段,並在這些字段上加入連接。 –
也行得通。再次感謝您對此的支持。 –