本文介绍了将Google Analytics添加到PHP网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Google Analytics的新手,并试图将其添加到现有的PHP网站。在此阶段,我只能访问用于创建新页面和插入内容的内容管理系统。据我所知,该网页已经有一个经典分析代码(ga.js),由创建该网站的公司放在那里。



根据以下内容来自Google的网页我应该能够将Universal Analytics跟踪代码(analytics.js)添加到我的内容中,并且它应该协调工作。



哪里是所有其他网页?他们为什么不出现在名单上?我是否犯了一个初学者的错误?



为了让您更容易看到我在说什么,我正在处理的网站是。

更新:



我为Google Chrome添加了Google Analytics调查附加功能。它似乎在浏览器的每个页面上显示相同的错误。这里有一个例子:





错误:
community.php?
id = 66:484
未捕获的SyntaxError:
意外标识符
$ b 更新:



不幸的是,我忘记了网站上的内容管理系统使用方括号来知道在哪里插入图像的html代码。多么痛苦。正如您在下面的答案中看到的,这是导致两种不同外观的跟踪代码的原因。无论如何,至少我知道是什么导致了问题。再次感谢新浪!

解决方案

为什么你在不同的页面中有两个不同的代码?



例如,在index.php(工作)中您有:

 <脚本> 
(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-66181918-1','auto');
ga('send','pageview');

< / script>

鉴于您的 /studentservices.php?id=47

 < script> 
(函数(i,s,o,g,r,a,m){i< img style ='padding:8px;'src =。/ images / services /'GoogleAnalyticsObject'align = right> = r ; i< img style ='padding:8px;'src =。/ images / services / r align = right> = i< img style ='padding:8px;'src =。/ images / services / r align = right> || function(){
(i< img style ='padding:8px;'src =。/ images / services / r align = right> .q = i< img style ='padding:8px;'src = ./ images / services / r align = right> .q ||< img style ='padding:8px;'src =。/ images / services / align = right>)push(arguments)},i< img风格= '填充:8像素;' SRC = /图像/服务/ R ALIGN =右> .L = 1 *新日期(); A = s.createElement(○),
M = s.getElementsByTagName(邻。 )< img style ='padding:8px;'src =。/ images / services / 0 align = right> a.async = 1; a.src = g; m.parentNode.insertBefore(a,m)
})(window,document,'script','// www.google-analytics.com/analytics.js','ga');

ga('create','UA-66181918-1','auto');
ga('send','pageview');

< / script>

你看到区别了吗?

I'm new to Google Analytics and am trying to add it to my existing PHP website. At this stage I only have access to the Content Management System which is used for creating new pages and inserting content. As far as I am aware the page already has a Classic Analytics code (ga.js) which was put there by the company who created the website.

According to the following page from Google I should be able to add a Universal Analytics tracking code (analytics.js) to my content and it should work harmoniously.https://support.google.com/analytics/answer/1032400?hl=en

I've gone ahead and added the tracking code at the end of my content for each of the pages on the site.

Unfortunately I don't think the pages views are being shown accurately when I log in and look at the stats. They are being displayed as follows:

Where are all the other pages? Why aren't they coming up on the list? Am I making a beginners mistake?

To make this easier for you to see what I'm talking about, the site I'm working on is This Site.

UPDATE:

I've added the Google Analytics Debug add on for Chrome. It seems to be showing the same error on each page I go to in the browser. Here's an example:

http://www.maryborougheducationcentre.vic.edu.au/community.php?id=66

Error:community.php?id=66:484Uncaught SyntaxError:Unexpected Identifier

UPDATE:

Unfortunately I had forgotten that the Content Management System on the website uses square brackets to know where to insert html code for images. What a pain. This is what caused the two different looking tracking codes as you can see in the answer below. Anyway, at least I know what was causing problem. Thanks again Sina!

解决方案

Why are you having 2 different codes in different pages?

For example, in index.php (working) you have:

<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-66181918-1', 'auto');
  ga('send', 'pageview');

</script>

Whereas in your /studentservices.php?id=47 (not working) you have:

<script>
  (function(i,s,o,g,r,a,m){i<img style='padding:8px;' src=./images/services/'GoogleAnalyticsObject' align=right>=r;i<img style='padding:8px;' src=./images/services/r align=right>=i<img style='padding:8px;' src=./images/services/r align=right>||function(){
  (i<img style='padding:8px;' src=./images/services/r align=right>.q=i<img style='padding:8px;' src=./images/services/r align=right>.q||<img style='padding:8px;' src=./images/services/ align=right>).push(arguments)},i<img style='padding:8px;' src=./images/services/r align=right>.l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)<img style='padding:8px;' src=./images/services/0 align=right>;a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-66181918-1', 'auto');
  ga('send', 'pageview');

</script>

You see the difference?

这篇关于将Google Analytics添加到PHP网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:12