Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Google analytics with Header Tags


Jack_mcs

Recommended Posts

If you want to install the code for analytics and you have Header Tags installed, add this code to the bottom of the includes/header_tags.php file before the last ?>

echo '<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">' . "\n";

echo '</script>' . "\n";

echo '<script type=\"text/javascript\">' . "\n";

echo '_uacct = \"XX-XXXXXX-X\";' . "\n";

echo 'urchinTracker();' . "\n";

echo '</script>' . "\n";

Be sure to replace the X' with your actual account number. Doing the above will include the code on every page that has the header tags code installed, thus saving a lot of changes.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

is anyone else having error messages with this? looking at my awstats, it is showing hundreds of 404 errors with the url not found as:

 

/"http://www.google-analytics.com/urchin.js/"

 

This is what my headers_tag.php looks like now at the end:

 

echo ' <META NAME="Description" Content="' . $the_desc . '">' . "\n";

echo ' <META NAME="Keywords" CONTENT="' . $the_key_words . '">' . "\n";

echo ' <title>' . $the_title . '</title>' . "\n";

 

echo '<!-- EOF: Generated Meta Tags -->' . "\n";

 

echo '<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">' . "\n";

echo '</script>' . "\n";

echo '<script type=\"text/javascript\">' . "\n";

echo '_uacct = \"UA-xxxxx-x\";' . "\n";

echo 'urchinTracker();' . "\n";

echo '</script>' . "\n";

 

 

?>

 

I have replaced my actual account number with x's before posting but the header_tags.php has the actual account number in it.

 

when I view the source for a page, this is what is showing:

 

<script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\">

</script>

<script type=\"text/javascript\">

_uacct = \"UA-xxxxx-x\";

urchinTracker();

</script>

Link to comment
Share on other sites

That looks OK to me. You could try removing the Header Tags change and placing the code directly into the file. If it still fails, which I suspect it will, contact google and ask them what is going on.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

I'm sorry, I looked at it again and realized the escapes should not be in there (too much editing in language files I guess). Anyway, if anyone has used this, please change it to the following format:

echo '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">' . "\n";
echo '</script>' . "\n";
echo '<script type="text/javascript">' . "\n";
echo '_uacct = "XX-XXXXXX-X";' . "\n";
echo 'urchinTracker();' . "\n";
echo '</script>' . "\n";

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

I'm sorry, I looked at it again and realized the escapes should not be in there (too much editing in language files I guess). Anyway, if anyone has used this, please change it to the following format:

echo '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">' . "\n";
echo '</script>' . "\n";
echo '<script type="text/javascript">' . "\n";
echo '_uacct = "XX-XXXXXX-X";' . "\n";
echo 'urchinTracker();' . "\n";
echo '</script>' . "\n";

 

Jack

 

hi there

 

can you help as i have so many account numbers which one do i use for the account number in the code

do i use googls account number not to sure hope you can help

 

kind regards

 

maltonge

Link to comment
Share on other sites

When yu signed up with google to use Analytics, they would have given you an account number. Just replace the X's in the code listed with that number. It is in the same format. You can log into your google account to find the account number if you have misplaced it.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

When yu signed up with google to use Analytics, they would have given you an account number. Just replace the X's in the code listed with that number. It is in the same format. You can log into your google account to find the account number if you have misplaced it.

 

Jack

 

hi there

 

thank you for your reply

I have checked with google-analytics and at the moment they are not letting anyone signup

 

I will await there email cheers for your help

 

kind regards

 

maltonge

Link to comment
Share on other sites

I'm sorry, I looked at it again and realized the escapes should not be in there (too much editing in language files I guess). Anyway, if anyone has used this, please change it to the following format:...

 

Jack

 

 

Thanks, Jack !

Link to comment
Share on other sites

now google says it doesn't see this on my page. before, their instructions said to put the code in the header but today my page is saying this:

 

Click in the box below to select all code. Copy and paste the code segment into the bottom of your content, immediately before the </body> tag of each page you are planning to track. If you use a common include or template, you can enter it there.

 

didn't it say before to put it right before the </head> tag or am I just losing it?

Link to comment
Share on other sites

The code needs to go in the head section after the title and meta tags so using Header Tags to insert it works fine. Did you make the change I mentioned above? How long has it been since you made the change and started your account with google? They are having a lot of problems with this option due to the overwhelming response so it may fix itself in a day or two. If you want to PM me a link to your site, I will look at the code to see if it is correct.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

The code needs to go in the head section after the title and meta tags so using Header Tags to insert it works fine. Did you make the change I mentioned above? How long has it been since you made the change and started your account with google? They are having a lot of problems with this option due to the overwhelming response so it may fix itself in a day or two. If you want to PM me a link to your site, I will look at the code to see if it is correct.

 

Jack

 

 

My website is http://tresrhnter.com.

 

I'm fairly sure it is installed correctly. I don't remember exactly when I signed up but it's been close to a month :( As of today, google is still saying it isn't installed correctly. yes, I made the change you referenced above. Thank you.

Link to comment
Share on other sites

I found this email from google posted on another site re: their changing to putting it right above the </body> tag instead of in the header:

 

Thank you for your email. We’ve noticed that some users’ networks have a hard time contacting Google Analytics in order to communicate your traffic information. To prevent your page load time from slowing, we recommend that you place your tracking code at the bottom of your page, before the (/body) tag. This will allow your entire page contents to load before needing to communicate with Google Analytics.
Link to comment
Share on other sites

The code on your page appears to be correct. The email you mention refers to sites that have problems loading because they cannot connect to google fast enough. If your page is loading but the code isn't being seen by google, then it is something else. You can try removing it from the header_tags.php file and manually inserting into the index.php file in various places. Wait a day or so and see if it works.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

  • 3 weeks later...

A couple of things.. First off, Google says that the code should be at the *end* of the site, not the beginning like you have it:

 

"It should be immediately before the </body> tag of your page, and should look exactly as it was provided to you:"

 

Don't think it matters too much, but it's always nice to do it right. Also, if you're using SSL you'll want to disable analytics when in SSL mode as it will through insecure page errors in IE.

 

 

I currently have this set up as follows:

 

in my includes/footer.php file, at the very end of the file after the </table>, I have:

<?php
 }
 if ($request_type != 'SSL') {
 echo GOOGLE_ANALYTICS;
 }
?>

 

This tells OsC to load the analytics code only if the page is NOT SSL.

 

Instead of doing a bunch of echos as jack did here, I then just defined GOOGLE_ANALYTICS in my english.php file as follows:

 

define('GOOGLE_ANALYTICS', '
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "XX-XXXXXX-X";
urchinTracker();
</script>');

 

If you don't want to do that though, just do the echos in the footer.php file like this:

 

<?php
 }
 if ($request_type != 'SSL') {
 echo '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">' . "\n";
  echo '</script>' . "\n";
  echo '<script type="text/javascript">' . "\n";
  echo '_uacct = "XX-XXXXXX-X";' . "\n";
  echo 'urchinTracker();' . "\n";
  echo '</script>' . "\n";
 }
?>

 

 

Hopefully that helps some of you out (especially those that use SSL!)

 

-Adam

Link to comment
Share on other sites

Originally google said to put the code in the head section. They received complaints that that caused some sites to load slower since the page would not display until it finished with google. So they said to place it in the footer so the page can load without waiting. This doesn't happen on all sites. If it is a problem, or you think it might be, then using this approach (Header tags) shouldn't be used.

 

Jack

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...
  • 3 weeks later...
Don't think it matters too much, but it's always nice to do it right. Also, if you're using SSL you'll want to disable analytics when in SSL mode as it will through insecure page errors in IE.

I currently have this set up as follows:

 

in my includes/footer.php file, at the very end of the file after the </table>, I have:

<?php
 }
 if ($request_type != 'SSL') {
 echo GOOGLE_ANALYTICS;
 }
?>

 

This tells OsC to load the analytics code only if the page is NOT SSL.

 

Hopefully that helps some of you out (especially those that use SSL!)

 

-Adam

 

Thanks Adam.

 

I even sent out an email to Google Analytics about this SSL problem. But your solution is very effective, although in this way the Google Analytics can not track the activities of registered users.

 

Thanks a lot!

Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I just got my google analytics invitation code. I placed the following in my includes/header_tags.php file before the last ?>:

echo '<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">' . "\n";
echo '</script>' . "\n";
echo '<script type="text/javascript">' . "\n";
echo '_uacct = "XX-XXXXXX-X";' . "\n";
echo 'urchinTracker();' . "\n";
echo '</script>' . "\n";

 

I replaced the xx-xxxxxx-x with my account number. I ran the check status on google, and it says that it is not installed properly.

 

Any ideas?

 

Thanks!

Link to comment
Share on other sites

Have you viewed the source of oyur home page and compared it to what google says to enter?

 

Jack

 

Hi Jack,

 

It's not even showing up when I view source. Does this mean the header tags is not installed properly? My website url is in my profile.

 

Thanks.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...