| |||||||
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. ...
![]() |
| | Thread Tools |
| | #1 |
| Currently: Moderating! | Google Analytics - PHPHi 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 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 |
|
| | #2 |
| Mini Mac Join Date: Feb 2008
Posts: 3,143
![]() ![]() ![]() | 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. |
|
| | #3 |
| Currently: Moderating! | 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']]);
?>
__________________ Spoiler 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 |
|
| | #4 |
| What to put... | Why do you want to add a analytics code to a redirect page?
__________________ |
|
| | #5 |
| Looking for a new job!! | 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.
__________________ |
|
| | #6 | |
| What to put... | Quote:
__________________ | |
|
| | #7 |
| Looking for a new job!! | I know
__________________ |
|
| | #8 |
| Currently: Moderating! | 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 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.. |
|
| | #9 |
| Looking for a new job!! | 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.
__________________ |
|
| | #10 |
| Currently: Moderating! | "putting the include on there" ???
__________________ Spoiler 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 |
|
| | #11 |
| Looking for a new job!! | the include should be in the signup.php otherwise there is nothing in the signup.php to track anything??? Or am I missing something?
__________________ |
|
| | #12 |
| Currently: Moderating! | 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 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 |
|
| | #13 |
| Looking for a new job!! | 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"
__________________ |
|
| | #14 |
| Currently: Moderating! | Like so: Code: <?php
include_once("/analyticstracking.php")
$path = array(
'iphone4s' => 'http://www...
__________________ Spoiler 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 |
|
| | #15 |
| Looking for a new job!! | 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
__________________ Last edited by ndev2k; 30-11-11 at 11:12 AM.. |
|
| | #16 |
| What to put... | I got an error: Parse error: syntax error, unexpected T_VARIABLE in /home/quickiph/public_html/signup/signup.php on line 3
__________________ |
|
| | #17 |
| Looking for a new job!! | Ryan see my edit
__________________ |
|
| | #18 |
| Currently: Moderating! |
__________________ Spoiler 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.. |
|
| | #19 |
| Looking for a new job!! | Remove the include for the moment whilst I have a quick look at the code
__________________ |
|
| | #20 |
| Currently: Moderating! | 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 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 |
|
![]() |
| Thread Tools | |
| |