BigQueryによるGAトラフィック分析

某旅行会社のeコマース部門にいます。BigQueryを利用してGoogleアナリティクスデータの分析例を紹介します。

BigQueryでGoogleアナリティクスのトランザクションの間隔をだす

f:id:webmarketer_desu:20200426152208j:plain

Googleアナリティクスのセッションの間隔をだす」でセッションの間隔を出したのですが、トランザクションにも応用できるのでポストします。

 select
 round(avg(interval_session),2) as avg_interval_session
 from
 (select
 fullvisitorid,
 paese_date('%Y%m%d', date) as date,
 lead(parse_date('%Y%m%d', date))
 over(
 partition by fullvisitorid
 order by date desc) as date2,
 date_diff(parse_date('%Y%m%d', date),
 lead(parse_date('%Y%m%d', date))
 over(
 partition by fullvisitorid
 order by date desc),day) as interval_session
 from `{bigqueryプロジェクトID}.{データセット}.{ga_sessions_*}`
 where _table_suffix between 'yyyymmdd' and 'yyyymmdd')
 and totals.transactions is not null
 ;

 トランザクションの間隔をだすには、トランザクションが発生したセッションだけに絞る必要がありますので、where句で「totals.transactions is not null」を書いています。

セッションの間隔で示したクエリと違うのはその部分だけです!