Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Google Analytics强制HTTPS阻止307内部重定向_Javascript_Google Analytics_Measurement Protocol - Fatal编程技术网

Javascript Google Analytics强制HTTPS阻止307内部重定向

Javascript Google Analytics强制HTTPS阻止307内部重定向,javascript,google-analytics,measurement-protocol,Javascript,Google Analytics,Measurement Protocol,当Google Analytics从http页面发送数据时,它以http请求开始,如下所示: 但这会导致307状态代码(内部重定向),原因是,此重定向是完全相同URL的https版本 如何强制Google Analytics仅从http页面发送一个https请求?解决方案是使用ForceSSL。这迫使谷歌分析始终通过https发送数据 analytics.js ga('set', 'forceSSL', true); 默认情况下,从https页面发送的跟踪信标将使用https发送,而从ht

当Google Analytics从http页面发送数据时,它以http请求开始,如下所示:

但这会导致307状态代码(内部重定向),原因是,此重定向是完全相同URL的https版本


如何强制Google Analytics仅从http页面发送一个https请求?

解决方案是使用
ForceSSL
。这迫使谷歌分析始终通过https发送数据


analytics.js

ga('set', 'forceSSL', true);
默认情况下,从https页面发送的跟踪信标将使用https发送,而从http页面发送的信标将使用http发送。将forceSSL设置为true将强制http页面也使用https发送所有信标


示例:

<!-- Google Analytics -->
<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','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'forceSSL', true); // <---------------------------- add this!
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_gat._forceSSL']); // <------------------------ add this!
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
var pageTracker = _gat._getTracker("UA-XXXXX-X");
_gat._forceSSL(); // <---------------------------------------- add this!
pageTracker._trackPageview();
将Google Analytics配置为使用SSL发送所有点击,即使来自不安全(HTTP)页面


示例(异步):

<!-- Google Analytics -->
<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','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'forceSSL', true); // <---------------------------- add this!
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_gat._forceSSL']); // <------------------------ add this!
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
var pageTracker = _gat._getTracker("UA-XXXXX-X");
_gat._forceSSL(); // <---------------------------------------- add this!
pageTracker._trackPageview();

var _gaq=_gaq | |[];
_gaq推送(['''u setAccount','UA-XXXXX-X']);
_gaq.push(['''u gat.'u forceSSL'])//