Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

How to add Google analytics code to php pages, per Google's instruction?

The instructions Google Analytics gives for adding their code to your php based site reads like this:

"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: "

What on earth do they mean by "include it on each template page"? How do you include a file on your template page?

I'm thinking that the instructions after the word "Then," are how you add it to your template page. Is that correct? Does Google really have such bad writers that they would write a confusing redundancy like that? What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Make sure that your pages have ".php" extension and that your server is running php. Then, on each page type the following php code:

<?php include("analyticstracking.php"); ?>

Or if your analytics file is placed in different directory than your pages:

<?php include("some_directory/analyticstracking.php"); ?>

As opening tag they mean the <html> tag at the top of the code.

Here is an example:

HTML/PHP PAGE CODE:

<html>

<?php include("some_directory/analyticstracking.php"); ?>

<head>

<!-- your head content goes here -->

</head>

<body>

<!-- your body content goes here -->

</body>

</html>

Hope that helps you...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...