Where to add Google analytics code to a php website

隐身守侯 提交于 2019-12-12 21:20:11

问题


When adding Google analytics code to a php website do I add the code to only the index page, every page created or only the front facing pages in the customer journey? What is the best practice? Thank you for any responses in advance.


回答1:


All the pages you want analytics on, add the code on the front facing pages. Best practice will be to create a file "analytics.php" and paste the code there, and add

<?php include_once("analytics.php"); ?>

To all the front facing pages




回答2:


In Your Google Analytics Account:

Go to Home - > Admin -> Under Property click on Tracking Info ->

I usually put mine in the sub directory of partials/header.php in my server so it goes into every page that I create in the main directory.

This was taken from Google Analytics in 03/2014 (it might change)

PHP Implementation (optional)

Create a PHP file named "analyticstracking.php" with the code above and include it on each PHP template page. Then, add the following line to each template page immediately after the opening tag:

<?php include_once("analyticstracking.php") ?>

Dynamic Content Implementation (optional)

Use a common include or template to paste the code above instead of manually adding it to every page. WAP site - for older feature phonesoptional

If you have a site built for older feature phones with no JavaScript support, or if you cannot use JavaScript for some other reason, you can download the server-side code libraries from here.




回答3:


Add the code on every page you want to track (typically every page within your web site). If this is a dynamically (via PHP) generated website you most likely have template files or common header/footer files (at least you should have) so you can insert your code there, or create a separate file with the analytics code and use an include (this is even mentioned n the analytics interface, at the page that let's you fetch the GA code).




回答4:


you can put same code in header.php where you can initialize ga(setting account api key etc..) .and use it throughout the website.



来源:https://stackoverflow.com/questions/15201082/where-to-add-google-analytics-code-to-a-php-website

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