eXceem

Go Back   eXceem > Websites > Website Discussion

Claim your amazing £1,000 slots booster bonus now!


Google Analytics - PHP

This is a discussion on Google Analytics - PHP within the Website Discussion forums, part of the Websites category; Hi guys, Was wondering if anyone could help. I want to add my google analytics code to a php page. ...

Reply
 
Thread Tools
Old 30-11-11, 08:40 AM   #1
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10

Google Analytics - PHP


Hi guys,

Was wondering if anyone could help.

I want to add my google analytics code to a php page. What do I have to do to convert it? (I can write HTML, but not PHP!)

Thanks
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler
 
Reply With Quote
Old 30-11-11, 08:44 AM   #2
Mini Mac
 
Join Date: Feb 2008
Posts: 3,143
-null- is a glorious beacon of light-null- is a glorious beacon of light-null- is a glorious beacon of light
You just add the analytics javascript code to the head part of your website. So you just need to add it to the bit of your PHP that outputs the html head code.
 
Reply With Quote
Old 30-11-11, 08:47 AM   #3
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
Just realised there's a "I want to track PHP pages" option that edits the code!

My PHP page doesn't actually have any head tags etc as it's a redirecting sign up page.

Code:
<?php
$path = array(
'iphone4s' => 'REFLINK',
'video' => 'REFLINK',

...more reflinks...

'points' => 'REFLINK',);
if (array_key_exists($_GET['id'], $path)) header('Location: ' . $path[$_GET['id']]);
?>
So where do I place the php analytics code?!
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler
 
Reply With Quote
Old 30-11-11, 09:41 AM   #4
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
Why do you want to add a analytics code to a redirect page?
__________________
 
Reply With Quote
Old 30-11-11, 09:44 AM   #5
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
To track clicks. Not sure how it will track which link though.

It might be easier to add a counter to the PHP and link this to a database. That way you can track each click on each different link in the array.
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 09:47 AM   #6
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
Quote:
Originally Posted by ndev2k View Post
To track clicks. Not sure how it will track which link though.

It might be easier to add a counter to the PHP and link this to a database. That way you can track each click on each different link in the array.
Now that's going to confuse him further
__________________
 
Reply With Quote
Old 30-11-11, 09:47 AM   #7
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
I know
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 09:58 AM   #8
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
lol, I just get annoyed when I view my "in-page analytics's page" and see lots of clicks onto other pages, but not on any of my links (which is what I want to see).

So my idea was to stick a tracking code in the php file, which will show the number of clicks through to the signup.php.

Make sense?

I have followed Google's explanation and have created an "analyticstracking.php" file located in the root (ie: .com/analyticstracking.php) and I have included the "<?php include_once("analyticstracking.php") ?>" code in my index.html file.

I guess time will tell if it works! Anyone else have experience of this? Or advice?
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler

Last edited by MJ10; 30-11-11 at 10:00 AM..
 
Reply With Quote
Old 30-11-11, 10:06 AM   #9
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
php will not be read unless you have a handler set up on the server to read php in html files.

If you want this to track on the signup.php page then you should be putting the include on there I believe.
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 10:24 AM   #10
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
Quote:
Originally Posted by ndev2k View Post
php will not be read unless you have a handler set up on the server to read php in html files.

If you want this to track on the signup.php page then you should be putting the include on there I believe.
"putting the include on there" ???
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler
 
Reply With Quote
Old 30-11-11, 10:40 AM   #11
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
the include should be in the signup.php otherwise there is nothing in the signup.php to track anything???

Or am I missing something?
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 10:51 AM   #12
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
Oh right. Google said "under the <body> tag"... which I don't have in the php so put it in the index page.

Where in the php code should it go?
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler
 
Reply With Quote
Old 30-11-11, 10:59 AM   #13
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
It should be able to sit anywhere as the php file doesn't really render anything. It would probable be best for it to run before the redirect so put it at the top of the file.

Also you will not need the php tags around it as it is already enclosed in the whole script.

Finally make sure the path to the analytics.php file is fully qualified so if it is in the root then "/analytics.php" rather than just "analytics.php"
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 11:08 AM   #14
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
Like so:

Code:
<?php
include_once("/analyticstracking.php")
$path = array(
'iphone4s' => 'http://www...
the "analyticstracking.php" is in the root.
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler
 
Reply With Quote
Old 30-11-11, 11:11 AM   #15
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
That should work. I can test it for you by clicking a link and seeing if you see the count in analytics?

Remember to close the statement with ; otherwise it will error
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler


Last edited by ndev2k; 30-11-11 at 11:12 AM..
 
Reply With Quote
Old 30-11-11, 11:12 AM   #16
What to put...
 
ryan1087's Avatar
 
Join Date: Mar 2010
Posts: 9,073
ryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of lightryan1087 is a glorious beacon of light
Send a message via MSN to ryan1087
I got an error:

Parse error: syntax error, unexpected T_VARIABLE in /home/quickiph/public_html/signup/signup.php on line 3
__________________
 
Reply With Quote
Old 30-11-11, 11:14 AM   #17
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
Ryan see my edit
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 11:19 AM   #18
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
Oh crap... now what?!

http://www.quickfreeiphone.com/signu...p.php?id=video
__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler

Last edited by MJ10; 30-11-11 at 11:19 AM..
 
Reply With Quote
Old 30-11-11, 11:20 AM   #19
Looking for a new job!!
 
ndev2k's Avatar
 
Join Date: Jun 2008
Location: St Helens
Posts: 4,277
ndev2k is a name known to allndev2k is a name known to allndev2k is a name known to allndev2k is a name known to all
Send a message via MSN to ndev2k Send a message via twitter to ndev2k
Remove the include for the moment whilst I have a quick look at the code
__________________
Free Stuff |Free iPhone 3GS | Free Nintendo Wii | Free PS3 | Free Stuff
Spoiler

 
Reply With Quote
Old 30-11-11, 11:32 AM   #20
Currently: Moderating!
 
MJ10's Avatar
 
Join Date: Nov 2008
Location: Thatcham, Reading
Posts: 15,787
MJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to beholdMJ10 is a splendid one to behold
Send a message via twitter to MJ10
Thank you. I can send the files if you like, although you probably have access! Not quite sure what I did wrong!

Here are the google instructions I was following:

__________________
Spoiler
2011 Winner of Best Site Award and Grammanazi Award. Runner up for Member of the Year 2011

Free iPhone | Free iPhone | Free iPad 3 | Sign Define App | Freebie Proof Photo Blog

Total Received: £7,446.87 plus Current Stats: 0 green 12 pending


WIN an iPod Shuffle, XBox Live, Amazon or iTunes vouchers
>> Free competition entry here <<










Spoiler

Spoiler

Spoiler
 
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off





All times are GMT. The time now is 08:27 PM.
All trademarks and copyrights held by respective owners. Forum posts are owned by the poster.

Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO
no new posts