LoginSignup
2
1

More than 5 years have passed since last update.

GoogleAnalyticsとBigQueryをリンクした時のtimezone

Posted at

GoogleAnalyticsとBigQueryをリンクしたときに日次でga_sessions_YYYYMMDDなテーブルが
自動で作成され、そこに日次のGAデータが格納される

スキーマとして、日時を表すvisitStartTimeはTIMESTAMPとして、日付を表すdateはSTRINGとして扱われているが、
BigQueryのtimezoneのデフォルトはUTCなので、ひょっとして1日のga_sessions_YYYYMMDDの中に
dateが2ついるのかと考えて、以下のクエリを試してみた

bigquery
#standardSQL

SELECT
    MIN(date) AS min_date
  , MAX(date) AS max_date
  , MIN(TIMESTAMP_MILLIS(visitStartTime * 1000)) AS min_time
  , MAX(TIMESTAMP_MILLIS(visitStartTime * 1000)) AS max_time
  , MIN(DATETIME(TIMESTAMP_MILLIS(visitStartTime * 1000), 'Asia/Tokyo')) AS min_tokyo_time
  , MAX(DATETIME(TIMESTAMP_MILLIS(visitStartTime * 1000), 'Asia/Tokyo')) AS max_tokyo_time
FROM
    `projectId.datasetId.ga_sessions_20170508`

結果は以下で、dateとテーブル名に食い違いはなかった
ソートしたり極限値を条件にするだけならわざわざtimezoneは変換しなくて良さそう

min_date max_date min_time max_time min_tokyo_time max_tokyo_time
20170508 20170508 2017-05-07 15:00:00 UTC 2017-05-08 14:59:59 UTC 2017-05-08T00:00:00 2017-05-08T23:59:59
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1