How do I set USER_ID in Google Universal Analytics tracking code in Rails?

ぐ巨炮叔叔 提交于 2019-12-04 11:24:54
Keval Gohil

As per directive given in google analytics

You should do like this

ga('create', 'UA-XXXX-Y', { 'userId': <%= current_user.id %> })

and link it in application.html.erb exactly before closing of head tag

use this link for reference https://developers.google.com/analytics/devguides/collection/analyticsjs/user-id

Also you may need to add condition to decide whether the user is logged in or not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!