Hi
the source code provided by GA is this
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script>
I simply copied and pasted in my .html pages without changing anything and keeping the extension as .html.
Then I added the line to set a custom variable and it was not working because, you said, it is a PHP code but I am confused because it seems to me that they are using the same language...
Anyway, I tried to save all my pages as .php but I surely missed something because it did not work (i.e. tha pages did not upload coorectly). I probably re-try and take a look to the links you sent me
thanks a lot!
R
The part where it says <?php ... ?> tells the browser that your page has some PHP code in it (the part between those two 'tags'), which is why you need to rename it from .html to .php.
How are you uploading the pages to your server, with an FTP program? You may need to set it's upload mode to "Auto" before uploading the files if it's not already (usually is by default).
I whipped up a test page using your GA ID number and pasted exactly what I had on the first page, I just added your GA ID. Grab it here, and upload it to your server, then just navigate to: http://your-site.com/ga-test.php. View the source code to it and see if you spot an IP address in the code, if you do it's working. Also, read the short instructions I put on it. Lemme know how it turns out.
Hi
I upload the page as .php and when I opne the source code I actually spot an IP adress. However, when I go to
http://your-site.com/ga-test.php
it says 'sorry but the page does not exist' and the IP still does not appear on GA.
I do not know if I am doing everything right...
R
However, when I go to
http://your-site.com/ga-test.php
it says 'sorry but the page does not exist'
Might seem like a stupid question, but are you replacing "your-site.com" in that URL with your own actual site name? If you just go to the exact URL I gave you'd get a page doesn't exist error.
Sorry, when I go to the page you suggest it's actually showing the text you put on it...
but still no IP on GA (((
When you load up the page and see that text I put, view the page's source code and look for an IP address in the Google Analytics code, if it shows, it's working. Also, be sure to give it at least 24 hours since going to the page. GA is kinda slow with that.
Now the IP is appearing!
however, these IP adresses are the ones that have visited the page saved as .php?
I will try to re-upload all the pages as .php, but I don't understand why the last time my server was not able to correctly upload the pages...I just have to change the extension of pages and and the other files saved normally as .html, is it right? such as index.html? and also sitemap.xml and feed.xml?
thanks a lot!
rachele
I just have to change the extension of pages and and the other files saved normally as .html, is it right? such as index.html? and also sitemap.xml and feed.xml?
Yep, just changing the file extensions to .php will do the trick. Only for the .htm/.html files though, not .xml. XML files are basically just a flat database file and javascript/php don't work within them.
I still have a further question
in the test page you uploaded for me you wrote
['_setCustomVar', 1, 'IP', "(Mod note: IP Removed)", 2]
instead of
_gaq.push(['_setCustomVar', 1, 'IP', "<?php echo $_SERVER['REMOTE_ADDR']; ?>", 2]);
should I then replace what you wrote in all my pages or can I use the original line code? your line is associated to a specific IP...
Olympus
Single & Not Looking
could you give us the java code?
I wouldn't actually recommend forcing Javascript to do this, when it's so much easier to just rename the page that you have the GA code on to a .php extension. It adds alot more code and processing than is necessary, and is much more confusing. But if you're bound and determined to not rename that file to.php, here are 2 excellent links with information on how to do it.
Can Javascript know your IP?
Get Client IP using just Javascript?
Although after you check them out I have a feeling you'll agree.