Jump to content

Archived

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

woolef

Adding Google Analytics tracking code to osC

Recommended Posts

Navigate to /templates from your root folder. You will see two files in there along with some other folders. Ignore the folders and edit the file that relates to the type of template you are using - table based or default. Add your google tracking code into the file right before the </body> tag. Save your changes and exit the text editor. Job done.

 

To view that the code is entered correctly go to your index page and view it's source.

Share this post


Link to post
Share on other sites

hi i try to that but first i cant see anu <body> in this code and also i have this Error: I can not write to this file. Please set the right user permissions on: /var/www/vhosts/......./httpdocs//index.php

can you help me about that?thanks

Share this post


Link to post
Share on other sites

hi i try to that but first i cant see anu <body> in this code and also i have this Error: I can not write to this file. Please set the right user permissions on: /var/www/vhosts/......./httpdocs//index.php

can you help me about that?thanks

 

the user permissions i don't know for sure about other than if you have the file permissions set to read only on your server? you should be able to update this via your hosting control panel or your ftp access.

 

i also going to guess you're looking at the wrong file too. the file you want is located at catalog/templates/default.php (this *could* be different if you changed from the default template, but it is probably not named index.php) this is where your body tag should be

Share this post


Link to post
Share on other sites

woolef,

 

I wish I could follow your instructions. I recommend simply adding your tracking code to your footer file (includes/footer.php). Doing so applies it to every page.


plasma.jpg

Share this post


Link to post
Share on other sites

But...

The tracking code should be added just before the last </head> on the page, according to google. There are no </head>s on the footer, so where should I add the code?

 

Here's the footer code:

<?php

/*

$Id$

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2010 osCommerce

 

Released under the GNU General Public License

*/

 

require(DIR_WS_INCLUDES . 'counter.php');

?>

 

<div class="grid_24 footer">

<p align="center"><?php echo FOOTER_TEXT_BODY; ?></p>

</div>

 

<?php

if ($banner = tep_banner_exists('dynamic', '468x50')) {

?>

 

<div class="grid_24" style="text-align: center; padding-bottom: 20px;">

<?php echo tep_display_banner('static', $banner); ?>

</div>

 

<?php

}

?>

 

<script type="text/javascript">

$('.productListTable tr:nth-child(even)').addClass('alt');

</script>

 

 

Also - why footer, why not header? (still no </head>s, though) :blush:

 

Thanks in advance for any help!

 

Suvi

Share this post


Link to post
Share on other sites

I would like to thank everyone who helped to write this code. my site has been modified in so many aspects and did not think that "osCommerce Google Analytics module" contribution would work.

I can't believe the questions so many users make.

 

My advise download and read the read me files and follow the install instructions to the letter.

 

My site is now after 24 hours returning usfull data to GA.

 

Thanks Again

 

thebrit63

Share this post


Link to post
Share on other sites

But...

The tracking code should be added just before the last </head> on the page, according to google. There are no </head>s on the footer, so where should I add the code?

 

Here's the footer code:

<?php

/*

$Id$

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2010 osCommerce

 

Released under the GNU General Public License

*/

 

require(DIR_WS_INCLUDES . 'counter.php');

?>

 

<div class="grid_24 footer">

<p align="center"><?php echo FOOTER_TEXT_BODY; ?></p>

</div>

 

<?php

if ($banner = tep_banner_exists('dynamic', '468x50')) {

?>

 

<div class="grid_24" style="text-align: center; padding-bottom: 20px;">

<?php echo tep_display_banner('static', $banner); ?>

</div>

 

<?php

}

?>

 

<script type="text/javascript">

$('.productListTable tr:nth-child(even)').addClass('alt');

</script>

 

 

Also - why footer, why not header? (still no </head>s, though) blush.gif

 

Thanks in advance for any help!

 

Suvi

 

Thanks for sharing your view on it. It really helps!

Share this post


Link to post
Share on other sites

Hi, I need help. I need google analytics module for oscommerce version 1.03 with orders tracking. If you have some please help. Or if you have any idea how to do it. Great thanks

Share this post


Link to post
Share on other sites

You could try installing this contribution

 

http://addons.oscommerce.com/info/3756

 

HTH

 

G


Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Share this post


Link to post
Share on other sites

Hi, For OSC 2.3.1 I found that </head> tag is generated by /includes/template_top.php .

I've included google analytics code right before that tag without problems.

An additional option is to save the source (as suggested by Google) in a file called analyticstracking.php that I placed in the \includes directory...

Then, in the template_top.php file (right before the </head> tag..I included

<?php require(DIR_WS_INCLUDES . 'analyticstracking.php'); ?>

 

Hope it helps.

Share this post


Link to post
Share on other sites

Hi, For OSC 2.3.1 I found that </head> tag is generated by /includes/template_top.php .

I've included google analytics code right before that tag without problems.

An additional option is to save the source (as suggested by Google) in a file called analyticstracking.php that I placed in the \includes directory...

Then, in the template_top.php file (right before the </head> tag..I included

<?php require(DIR_WS_INCLUDES . 'analyticstracking.php'); ?>

 

Hope it helps.

 

If you are using 2.3.1 google analytics is already included, and just required turning on. In you admin area go to modules and click headertags. Then click google analytics. On the right of the page click edit and change Enable Google Analytics Module to true then click save. There is bo need to add any code anywhere. Just also add your google analytics number.


REMEMBER BACKUP, BACKUP AND BACKUP

Get the latest Responsive osCommerce CE (community edition) here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

If you are using 2.3.1 google analytics is already included, and just required turning on. In you admin area go to modules and click headertags. Then click google analytics. On the right of the page click edit and change Enable Google Analytics Module to true then click save. There is bo need to add any code anywhere. Just also add your google analytics number.

Thanks Steve, this made things alot easier. I just want to add that there was no Google Analytics Module but I just clicked 'Install Module' in the top right hand corner and hey presto, there it was.

Share this post


Link to post
Share on other sites

If you are using 2.3.1 google analytics is already included, and just required turning on. In you admin area go to modules and click headertags. Then click google analytics. On the right of the page click edit and change Enable Google Analytics Module to true then click save. There is bo need to add any code anywhere. Just also add your google analytics number.

 

I use 2.3.3. and don't have analytics included..?

 

Cheers

Share this post


Link to post
Share on other sites

Has there been any work on or an available update to the ht_google_analytics.php file to address the change to Universal Analytics tracking code. It’s different from the classic Google Analytic tracking code and is gradually being required (sort of, i.e. highly recommended) by Google.

 

Classic code style

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_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>

 

New Universal Code

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx-x', 'mydomainname.com');
ga('send', 'pageview');
</script>

 

Looking at the ht_google_analytics file in 2.3.3.4 it looks to be based on the Classic code. Please correct me if I am mistaken.


-Dave

Share this post


Link to post
Share on other sites

For OSCommerce 2.3.3.4. After logging onto Google analytics and filling in the details of your site you can add your google analytics Tracking ID in Admin/Modules/Header Tags then click SAVE

Share this post


Link to post
Share on other sites

Has there been any work on or an available update to the ht_google_analytics.php file to address the change to Universal Analytics tracking code. It’s different from the classic Google Analytic tracking code and is gradually being required (sort of, i.e. highly recommended) by Google.

 

Classic code style

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxx-x']);
_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>

 

New Universal Code

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxx-x', 'mydomainname.com');
ga('send', 'pageview');
</script>

 

Looking at the ht_google_analytics file in 2.3.3.4 it looks to be based on the Classic code. Please correct me if I am mistaken.

 

Hello David @@Roaddoctor,

How is going?

 

The update is uploaded:

Google Universal Analytics ht module OsC 2.3

http://addons.oscommerce.com/info/9060

 

Google Universal Analytics module OsC 2.2

http://addons.oscommerce.com/info/9059

 

 

Best ragards

Rainer

Share this post


Link to post
Share on other sites

@@raiwa in the code line 37 :

 

if (tep_not_null(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID) && tep_not_null(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_AFFILIATION)) {

 

MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_AFFILIATION appears to be undefined. What is the intended use ?

 

 

 


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

@@raiwa in the code line 37 :

 

if (tep_not_null(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID) && tep_not_null(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_AFFILIATION)) {

 

MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_AFFILIATION appears to be undefined. What is the intended use ?

 

Hello @@burt,

 

Oh yes, this is an error left from development. I wasn't sure if the store name will do it as affiliation and prepared an additional input field.

This is obsolete and should be:

  if ( tep_not_null(MODULE_HEADER_TAGS_GOOGLE_ANALYTICS_ID) ) {

 

I'll upload the fix. Thank you for the report.

 

Rainer

Share this post


Link to post
Share on other sites

@@raiwa

 

In installed up update as above but for about a week analytics wasn't showing data for the shop. No visitors.

 

I checked the code and note that in the latter part google's code uses the domain name, not the shop name. This line:

 

ga('create', 'My Tracking Code', 'myshopdomain.com');

 

According to page source the module code generates something like:

 

 

ga('create', 'My Tracking Code', 'My Shop Name');

 

So I manually hard coded 'myshopdomain.com' into the module and the data was again being collected.

 

Thoughts on that? Thanks


I am not a professional webmaster or PHP coder by background or training but I will try to help as best I can.

I remember what it was like when I first started with osC. It can be overwhelming.

However, I strongly recommend considering hiring a professional for extensive site modifications, site cleaning, etc.

There are several good pros here on osCommerce. Look around, you'll figure out who they are.

Share this post


Link to post
Share on other sites

@@raiwa

 

In installed up update as above but for about a week analytics wasn't showing data for the shop. No visitors.

 

I checked the code and note that in the latter part google's code uses the domain name, not the shop name. This line:

 

ga('create', 'My Tracking Code', 'myshopdomain.com');

 

According to page source the module code generates something like:

 

 

ga('create', 'My Tracking Code', 'My Shop Name');

 

So I manually hard coded 'myshopdomain.com' into the module and the data was again being collected.

 

Thoughts on that? Thanks

Hello @@altoid,

 

I wasn't sure about that and thought at the beginning to add an additional field "affiliation" to the module. But when I tested it on my stores with store name I found that it worked and I got also feedback from other users that it works for them too. Maybe it has to do which name you are using for STORENAME. If this problem gets confirmed by other users, I'll update the module with the additional field for affiliation.

 

Thanks and kind regards

Rainer

Share this post


Link to post
Share on other sites

Raiwa - when you generate the code at the analytics site it uses the shopdomain.com - so I would agree with Altoids' observation.


-Dave

Share this post


Link to post
Share on other sites

×