LoginSignup
2
2

More than 5 years have passed since last update.

Turbolinks 5 でGAのトラッキングコードを有効にする

Last updated at Posted at 2016-12-29

こんな感じの CofeeScript を書けばいいみたい。

document.addEventListener 'turbolinks:load', (event) ->
  if typeof ga is 'function'
    ga('set', 'location', event.data.url)
    ga('send', 'pageview')

Turbolinks は off にされがちだけど、個人サービスレベルであれば、 on のままで何か問題が起きたときは回避していく、という方針でやっていくのも悪くないと思う。早いは正義。

追記

Google Analytics のタグが新しくなり、それに対応するには

$(document).on 'turbolinks:load', ->
  if typeof gtag is 'function'
    gtag('config', [GA_TRACKING_ID], {'page_path': window.location.pathname})

こんな感じ。

2
2
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
2