Google analytic for PHP Pages

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
macmachi
Forum Newbie
Posts: 5
Joined: Thu Sep 08, 2011 5:46 am

Google analytic for PHP Pages

Post by macmachi »

Hi,
I'm new to this forum and to the concept PHP as well.

I'm trying to use google analytic tracking code in my php site, but I don't know how to do so as I have worked with html pages all these days. The thing is, if I open the source page in any browser it shows <html> tags and other tags like head, title, keywords, body....but when I open through web server I can only see php files staring with <?php.....

Could any of you help me in implementing the analytic code in my pages created with PHP? Thank you so much!
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Google analytic for PHP Pages

Post by Eric! »

Your sever isn't configured correctly if you are seeing the <?php tags and the code. This means your server isn't recognizing your php and running it.

When the server is configured correctly the following file:

Code: Select all

<html>
<?php echo "<b>Hello World!</b>"; ?>
</html>
when viewed via your server with your browser will look like[text]<html>
<b>Hello World!</b>
</html>[/text]Talk to your service provider, or if you set it up, you'll need to fix the install for Apache or Microsoft because it isn't running.
macmachi
Forum Newbie
Posts: 5
Joined: Thu Sep 08, 2011 5:46 am

Re: Google analytic for PHP Pages

Post by macmachi »

Hi Eric,

Thank you for your kind reply! I'm not familiar with PHP or accessing a server but only a little bit i know.
If the pages are not recognized how are all that pages in live online?
So, can I add <html> in all the pages that start with <?php..?

Could you please elaborate on how do I fix this up all by myself? Thanks for all your help! I appreciate it.
Eric! wrote:Your sever isn't configured correctly if you are seeing the <?php tags and the code. This means your server isn't recognizing your php and running it.

When the server is configured correctly the following file:

Code: Select all

<html>
<?php echo "<b>Hello World!</b>"; ?>
</html>
when viewed via your server with your browser will look like[text]<html>
<b>Hello World!</b>
</html>[/text]Talk to your service provider, or if you set it up, you'll need to fix the install for Apache or Microsoft because it isn't running.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Google analytic for PHP Pages

Post by Jonah Bron »

macmachi wrote:The thing is, if I open the source page in any browser it shows <html> tags and other tags like head, title, keywords, body....but when I open through web server I can only see php files staring with <?php.....
That's how PHP works, it's a server-side language. The server processes the PHP before sending it to the browser for display. The file doesn't need to start with <?php though: it just needs to surround any PHP code in the page. For example:

Code: Select all

<html>
    <head>
        <title><?php echo 'Blah blah' . $current_page; ?></title>
    </head>
    <body><?php
echo 'something <strong>else</strong>';
?>
    </body>
</html>
Will come out like this (providing $current_page has been set to " foo"):

Code: Select all

<html>
    <head>
        <title>Blah blah foo</title>
    </head>
    <body>something <strong>else</strong>
    </body>
</html>
macmachi
Forum Newbie
Posts: 5
Joined: Thu Sep 08, 2011 5:46 am

Re: Google analytic for PHP Pages

Post by macmachi »

Thanks Jonah for letting me know of that.

Can you please show some light on my query?
I see all the pages open with <?php and ends with </html> where is the opening tag <html> ? I don't find the opening tag in any of the source files.

Secondly, where do I put the tracking code????? please help.
That's how PHP works, it's a server-side language. The server processes the PHP before sending it to the browser for display. The file doesn't need to start with <?php though: it just needs to surround any PHP code in the page. For example:

Code: Select all

<html>
    <head>
        <title><?php echo 'Blah blah' . $current_page; ?></title>
    </head>
    <body><?php
echo 'something <strong>else</strong>';
?>
    </body>
</html>
Will come out like this (providing $current_page has been set to " foo"):

Code: Select all

<html>
    <head>
        <title>Blah blah foo</title>
    </head>
    <body>something <strong>else</strong>
    </body>
</html>
[/quote]
macmachi
Forum Newbie
Posts: 5
Joined: Thu Sep 08, 2011 5:46 am

Re: Google analytic for PHP Pages

Post by macmachi »

I solved the prob through a PHP developer we recently hired. Thank you Eric and Jonah for answering my question. Cheers!
Post Reply