简体   繁体   English

使用javascript更改浏览器语言代码以进行Google Analytics(分析)

[英]change browser language code with javascript for google analytics

I am using google analytics code but in my google analytics there are languages of many users not correctly identified - because in section area of our intranet webapp there are many users with other languages but the main language is the same, so I need to record this "correct" language. 我正在使用Google Analytics(分析)代码,但是在我的Google Analytics(分析)中,有许多用户的语言没有正确识别-因为在我们的Intranet Web应用程序的部分区域中,有许多用户使用其他语言,但是主要语言是相同的,因此我需要记录一下“正确的”语言。 I would like to use my php script to add some variable to analytics tracking code to record right language. 我想使用我的PHP脚本向分析跟踪代码中添加一些变量以记录正确的语言。

What should I change/add in ga code? 我应该在ga代码中更改/添加什么?

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA', 'auto');
  ga('send', 'pageview');
</script>

According to the documentation that should be the user language field 根据应为用户语言字段的文档

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA', 'auto');
ga('set', 'language', <?php echo $userLang; ?>');
  ga('send', 'pageview');
</script>

where $userLang would be the PHP var with the language, and the "set" call takes care that this is applied to all subsequent hits (pageviews, events, transactions etc) on the page. 其中$ userLang是使用该语言的PHP变量,“ set”调用应确保将其应用于页面上的所有后续匹配(页面浏览量,事件,交易等)。

Expected format is a IETF language tag , eg "en-us". 期望的格式是IETF语言标签 ,例如“ en-us”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM