php - Google Analytics causing 500 internal error - Stack Overflow

Using this code generated from googles analytic product: (information censored)<meta name="goog

Using this code generated from googles analytic product: (information censored)

<meta name="google-site-verification" content="xxxxxxxxxxxx" />



<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'xxxxxxxx']);
  _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/ga.js';
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s);
  })();

</script>

Causes internal 500 error, the code is in the head tag

Using this code generated from googles analytic product: (information censored)

<meta name="google-site-verification" content="xxxxxxxxxxxx" />



<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'xxxxxxxx']);
  _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./ga.js';
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s);
  })();

</script>

Causes internal 500 error, the code is in the head tag

Share Improve this question asked Nov 9, 2012 at 16:45 zomboblezomboble 8332 gold badges10 silver badges24 bronze badges 14
  • 3 it can't be from google analytics , check the error log to get more detailed error – tawfekov Commented Nov 9, 2012 at 16:46
  • you should put it at bottom of the page ! Something else might be causing this – user1607528 Commented Nov 9, 2012 at 16:46
  • @Muhammet not with the new one you shouldnt, it says so in the instructions – zomboble Commented Nov 9, 2012 at 16:47
  • @Muhammet It should be inside the <head> tag according to Google – nickhar Commented Nov 9, 2012 at 16:48
  • 1 "where can I find the error log?" Depends. Are you using Apache or nginx? Are you using PHP? Ruby on Rails? Sinatra.rb? Also, I agree with @tawfekov, there is no way GA could cause this. I don't think it really matters where the script is located, actually. GA doesn't impact page-loading performance that much, but I traditionally place it at the bottom myself, too. – omninonsense Commented Nov 9, 2012 at 16:55
 |  Show 9 more ments

4 Answers 4

Reset to default 7

If your website is using the Smarty Template engine, just pasting this code into the template will cause the 500 Internal Server Error, because the template is interpreting the code improperly.

Past the code inside a

{literal} 
...
{/literal}

block and your problems will be solved!

Shout out to Logicia.co.uk blog which helped me out with this same issue.

have you tried moving the script tag to the bottom of your content before the end of the element?

ie:

<body>
  stuff here
  <ga script include>
</body>

The script itself is appending and loading another script tag to the top of the head. So you might be getting conflicts between GA appending and loading the new script and your other JS piling.

I have gotten the 500 Error too. In my case, it was the template engine smarty!!!

It takes this line as a smarty mand because of the {}

function gtag(){dataLayer.push(arguments);}

change this to:

{literal}function gtag(){dataLayer.push(arguments);}{/literal}

maybe someone runns in this error with smarty too :-)

WAG (Wild-A**-Guess)*, based on your ment about lots of other SEO stuff and scripts in head...

Split the analytics code into two parts. Put the part that loads ga.js closer to the top of head, above any other script calls.

<script type="text/javascript">
  (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./ga.js';
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s);
  })();
</script>

Put the other part, that performs the analytics at the bottom of the head tag, or even at the bottom of the body tag.

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'xxxxxxxx']);
  _gaq.push(['_trackPageview']);
</script>

If you're still having problems, see what happens if you remove the _gaq code altogether

  • If you still get 500 errors, then the problem is with the async loading of ga.js. You could try switching to the older, non-async style of Google Analytics.
  • If the error goes away, then the problem is with the analytics tracking pixels requests...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744978922a4604319.html

相关推荐

  • php - Google Analytics causing 500 internal error - Stack Overflow

    Using this code generated from googles analytic product: (information censored)<meta name="goog

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信