Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Google Analytics module


Guest

Recommended Posts

Just like letting the fox guard the henhouse, aint it...

:huh:

If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.

 

"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -

 

"Headers already sent" - The definitive help

 

"Cannot redeclare ..." - How to find/fix it

 

SSL Implementation Help

 

Like this post? "Like" it again over there >

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 389
  • Created
  • Last Reply

Top Posters In This Topic

Are the changes to checkout_success instead of or as well as the changes in the contribution. I've done it as well as but I'm getting the following error and wonder if this is why:

 

pageTracker._addTrans( "70","boxershortz","133.49","19.06","0.00","Steventon","onbekend","United Kingdom" ); pageTracker._addItem( "70","53","Acoustic Dreadnought style guitar","Acoustic Guitars","108.93","1"); pageTracker._trackTrans();

 

Many thanks

 

 

i think that correct is

from:

 

<?php

include(DIR_WS_MODULES . 'analytics/analytics.php');

?>

 

to modify in checkout_success.php with this

 

<script type="text/javascript">

var pageTracker = _gat._getTracker("UA-xxxxxx-x");

pageTracker._initData();

pageTracker._trackPageview();

 

<?php

include(DIR_WS_MODULES . 'analytics/analytics.php');

?>

 

</script>

 

Please reply if the error was corrected.

Link to comment
Share on other sites

Hey Pix I need your help please!!

<?php
/*
==========================================================
Include Google Analystics module for osCommerce
  modified by PIXCLINIC (www.pixclinic.com)
v. 1.0 - 2008/09/01
==========================================================	

--------------------------------------------------
 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com
 Copyright (c) 2003 osCommerce
--------------------------------------------------

 Released under the GNU General Public License
*/

// ############## Google Analytics - start ###############

// Get order id
$orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$customer_id . "' order by date_purchased desc limit 1");
$orders = tep_db_fetch_array($orders_query);
$order_id = $orders['orders_id'];

// Get order info for Analytics "Transaction line" (affiliation, city, state, country, total, tax and shipping)

// Set value for  "affiliation"

$analytics_affiliation = 'your_store_name';


// Get info for "city", "state", "country"
$orders_query = tep_db_query("select customers_city, customers_state, customers_country from " . TABLE_ORDERS . " where orders_id = '" . $order_id . "' AND customers_id = '" . (int)$customer_id . "'");
$orders = tep_db_fetch_array($orders_query);

$totals_query = tep_db_query("select value, class from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . (int)$order_id . "' order by sort_order");
// Set values for "total", "tax" and "shipping"
$analytics_total = '';
$analytics_tax = '';
$analytics_shipping = '';

 while ($totals = tep_db_fetch_array($totals_query)) {

	if ($totals['class'] == 'ot_total') {
		$analytics_total = number_format($totals['value'], 2);
		$total_flag = 'true';
	} else if ($totals['class'] == 'ot_tax') {
		$analytics_tax = number_format($totals['value'], 2);
		$tax_flag = 'true';
	} else if ($totals['class'] == 'ot_shipping') {
		$analytics_shipping = number_format($totals['value'], 2);
		$shipping_flag = 'true';
	}

 }

/* Prepare the Analytics "Transaction line" string - replace the XXXX by your Google ID
<script type="text/javascript"> 
var pageTracker = _gat._getTracker("XX-XXXX-X"); 
pageTracker._initData(); 
pageTracker._trackPageview(); 
pageTracker._addTrans( 
  "1234",			 // order ID - required 
  "Mountain View",	// affiliation or store name 
  "11.99",			// total - required 
  "1.29",			 // tax 
  "5",				// shipping 
  "San Jose",		 // city 
  "California",	   // state or province 
  "USA"			   // country 
); 
*/

$transaction_string = '
<script type="text/javascript"> 
var pageTracker = _gat._getTracker("XX-XXXXX-X"); 
pageTracker._initData(); 
pageTracker._trackPageview(); 
pageTracker._addTrans( ';
$transaction_string .= '"' . $order_id . '",';
$transaction_string .= '"' . $analytics_affiliation . '",';
$transaction_string .= '"' . $analytics_total . '",';
$transaction_string .= '"' . $analytics_tax . '",';
$transaction_string .= '"' . $analytics_shipping . '",';
$transaction_string .= '"' . $orders['customers_city'] . '",';
$transaction_string .= '"' . $orders['customers_state'] . '",';
$transaction_string .= '"' . $orders['customers_country'] .'"';
$transaction_string .= ');';



/* Get products info for Analytics "Item lines"
pageTracker._addItem( 
  "1234",			 // order ID - required 
  "DD44",			 // SKU/code 
  "T-Shirt",		  // product name 
  "Green Medium",	 // category or variation 
  "11.99",			// unit price - required 
  "1"				 // quantity - required 
); 
pageTracker._trackTrans(); 
</script> 


*/
$item_string = '';
	$items_query = tep_db_query("select products_id, products_model, products_name, final_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $order_id . "' order by products_name");
while ($items = tep_db_fetch_array($items_query)) {
$category_query = tep_db_query("select p2c.categories_id, cd.categories_name from " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c, " . TABLE_CATEGORIES_DESCRIPTION . " cd where p2c.products_id = '" . $items['products_id'] . "' AND cd.categories_id = p2c.categories_id AND cd.language_id = '" . (int)$languages_id . "'");
$category = tep_db_fetch_array($category_query);	
$item_string .= ' pageTracker._addItem(';
$item_string .= '"' . $order_id . '",';
$item_string .= '"' . $items['products_model'] . '",';
$item_string .= '"' . $items['products_name'] . '",';
$item_string .= '"' . $category['categories_name'] . '",';
$item_string .= '"' . number_format($items['final_price'], 2) . '",';
$item_string .= '"' . $items['products_quantity'] . '"';
$item_string .= ');';
};

$item_string .= ' pageTracker._trackTrans();</script>';



echo $transaction_string . $item_string;
?>

Link to comment
Share on other sites

  • 2 months later...

I've downloaded verison RC1 and have installed as per the instructions on my site, which is running Ver 2.2 RC2. There is no data being tracked by Google despite Google stating data is being received. I've installed the code into the footer.php and checkout_process.php as per the instructions.

 

Can you help?

 

Kind regards

 

Ian R Smith

Link to comment
Share on other sites

The current contribution (labeled "RC1") by bloness contains this code

 

// GOOGLE ANALYTICS BOF

session_register('google_analytics');

 

$_SESSION['google_analytics'] = 'UTM:T|'.

$insert_id .

'|Web Sales|'.$order->info['total'].'|'.

$order->info['tax'].'|'.

$order->info['shipping_cost'].'|'.

$order->customer['city'].'|'.

$order->customer['state'].'|'.

$order->customer['country']['iso_code_2']."\n".$google_analytics;

// GOOGLE ANALYTICS EOF

 

I don't understand what this code is good for. It seems to remain from earlier releases. The current release does not use this session data AFAICS. If you agree that the code is not needed then I'd remove it from the contribution.

Link to comment
Share on other sites

Just installed this module yesterday and it is up and running with statistics already - YAY!

 

Now the questions is: How do I do A/B Split Testing on the site? I want to create a different version of the home page and test that against our current version.

 

According to the videos I watched on google to see what analytics was, it claims to have the ability to allow for two different types of testing - A/B being one of them.

 

The only thing I can figure out so far, is that one would have to somehow run two separate versions of the website and plug each version into analytics as a "profile" - which would then mean that each version would need it's own UA-XXXXX number - which then means the entire site needs to be different, not just the content portion of the home page. Being I'm also running STS I would need a change in the database configuration table for each different version.

 

I was hoping somebody here has used Analytics for A/B Split Testing and can tell me if I'm missing something. The way the video explained it on google's site I thought it was something that Analytics let you setup. Now I'm starting to wonder as I can't find anywhere in analytics to change what content loads on a page and how to see which one is causing more conversions.

~Tracy
 

Link to comment
Share on other sites

Hello guys,

 

I see a lot people writing that they can't receive e-commerce data unless they did the settings for it.

I have also installed this module and did the settings.

 

I receive all information from google analytics but can't to receive the e-commerce data.

 

Can someone say what the problem can be because I think a lot people are still waiting how to solve this.

 

Marco

Link to comment
Share on other sites

I learned that the A/B Split testing is done through Google Website Optimizer - just in case anybody else has this question later on :)

 

Just installed this module yesterday and it is up and running with statistics already - YAY!

 

Now the questions is: How do I do A/B Split Testing on the site? I want to create a different version of the home page and test that against our current version.

 

According to the videos I watched on google to see what analytics was, it claims to have the ability to allow for two different types of testing - A/B being one of them.

 

The only thing I can figure out so far, is that one would have to somehow run two separate versions of the website and plug each version into analytics as a "profile" - which would then mean that each version would need it's own UA-XXXXX number - which then means the entire site needs to be different, not just the content portion of the home page. Being I'm also running STS I would need a change in the database configuration table for each different version.

 

I was hoping somebody here has used Analytics for A/B Split Testing and can tell me if I'm missing something. The way the video explained it on google's site I thought it was something that Analytics let you setup. Now I'm starting to wonder as I can't find anywhere in analytics to change what content loads on a page and how to see which one is causing more conversions.

~Tracy
 

Link to comment
Share on other sites

Hi fellas,

I am new to Google Analytics, I have just activated my account and must place the tracking code throughout my page.

 

I have 3 simple questions for you pro's to answer so that I can begin,

(firstly I am running MS2).

 

1) Do I post the google tracking code on all the pages? If not, which ones are best?

2) What do I do with the analytics.php contribution?

3) Thanks!

Link to comment
Share on other sites

Hello Everyone,

I have looked through the thread with the contribution for the google analytics contribution, however, I don't have sts4 installed. Now I'm uncertain which version I should be using? Can anyone point me in the right direction?

 

Thanks, Lukas

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

Hi there.

I am fairly new to the e-commerce side of GA but I can shed some light on some of the other stuff which I see people asking questions about.

 

1. Google Analytics has all sorts of different information that you can track, such as where users are going, where they are coming from etc etc. The code that you embed into the footer is put there to 'track' a user through your website. It is put in the footer so if Google is slow loading for some reason, your customer won't be held up by waiting for the page to display. However, this 'tracking' data has no added information about e-commerce things such as purchase price/size, this is left to the contribution in question.

 

2. The RC1 English file has a spelling mistake.

catalog/includes/modules/analitycs/analitics.php

Should be:

catalog/includes/modules/analytics/analytics.php

 

as you'll see in the footer file:

include(DIR_WS_MODULES . 'analytics/analytics.php');

 

So, basically what you are doing with the code stated:

 

<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
	pageTracker._initData();
	pageTracker._setDomainName("YOURDOMAIN.com");
	pageTracker._trackPageview();
<?php
	if (strpos($_SERVER['PHP_SELF'], 'checkout_success.php') !== false)
		include(DIR_WS_MODULES . 'analytics/analytics.php'); 
?>
</script>

 

is setting up your usual footer tracking, with the additional : analytics/analytics.php

information included.

 

This should work straight out of the box. If you got fooled by the spelling mistake just go back and fix it up.. the guy who wrote the install must have been in a rush (interestingly, the french that wrote the first RC1 version did spell it correctly).

 

I have just installed it into my own site so i'll post a reply if it works fine for me.

Link to comment
Share on other sites

Yep, turns out it is working perfectly.

The only orders Analytics does not track are those in which the customer pays via PayPal, then has a Credit Card error, and then does not return to the site (I have a system in place to record the order in my admin however).

 

I will look @ ways around this.

 

Anyway! Go Google Analytics!

 

If you get stuck send me a PM and i'll try to help.

Link to comment
Share on other sites

  • 4 weeks later...
Can someone please explain to me why its neccessary to instal such a huge contrib when all you have to do is install some code onto the footer?

 

This addon not only add the tracker to your page, but it adds the ability to let know to analytics when a custommer bough something. So, in analytics, you will be able to see, for each keayword, each referal, what was sell, and how much. It's an automatic GOAL system, if you prefer.

Link to comment
Share on other sites

  • 4 weeks later...

One question.

 

I have follow install instructions but can any confirm this line of code in the checkout_success

 

<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer-tracker.php'); ?>

<!-- footer_eof //-->

 

I don't have footer-tracker.php .

 

Thanks this is a very good module for tracking transactions.

Link to comment
Share on other sites

One question.

 

I have follow install instructions but can any confirm this line of code in the checkout_success

 

<!-- footer //-->

<?php require(DIR_WS_INCLUDES . 'footer-tracker.php'); ?>

<!-- footer_eof //-->

 

I don't have footer-tracker.php .

 

Thanks this is a very good module for tracking transactions.

 

 

You missed a step in the instructions - Step 3 - make a copy of your original footer.php file in the directory catalog/includes/, rename this file to footer-tracker.php

Link to comment
Share on other sites

im digging this so far but for some reason the e-commerce overview keeps saying 0 even though orders have been placed. I have the code in the checkout_success so shouldnt it register? The original footer.php i made a copy and renamed it to footer-tracker.php and then continued to modify the footer.php with the new code additions. I'm using paypal ipn and it kicks them back automatically to checkout_success when done.

Edited by Jayman11
Link to comment
Share on other sites

im digging this so far but for some reason the e-commerce overview keeps saying 0 even though orders have been placed. I have the code in the checkout_success so shouldnt it register? The original footer.php i made a copy and renamed it to footer-tracker.php and then continued to modify the footer.php with the new code additions. I'm using paypal ipn and it kicks them back automatically to checkout_success when done.

 

I have been unsuccessful in getting this contribution to work... for both PayPal orders and straight credit card orders through our gateway.

Link to comment
Share on other sites

I have been unsuccessful in getting this contribution to work... for both PayPal orders and straight credit card orders through our gateway.

 

Allow me to expand... The instructions provided state the following misnomers:

 

6. open/edit catalog/checkout_success.php

 

---------------------------------------------------------------------------

 

7. Under <link rel="stylesheet" type="text/css" href="style.css"> paste the following code:

 

<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
	pageTracker._initData();
	pageTracker._trackPageview();

	<?php 
		include(DIR_WS_MODULES . 'analytics/analytics.php'); 
	?>

</script>

 

Well... my checkout_success.php (osCommerce Online Merchant v2.2 RC2) doesn't have a <head> with a linked in stylesheet. It's all PHP, from line 1 to end. I'm a little displaced with the above instruction. The same applies to this rule of instruction:

 

9. At the bottom of the file checkout_success.php change the following line:

 

<!-- footer //-->
	<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

into

<!-- footer //-->
	<?php require(DIR_WS_INCLUDES . 'footer-tracker.php'); ?>
<!-- footer_eof //-->

 

I don't have a footer include request in my checkout_success.php.

 

If anyone can advise I'd greatly appreciate it!

Link to comment
Share on other sites

It's definitely working for me now. Unfortunately it doesn't record every sale since they don't always return to the checkout_success page. Wonder if something could be added to the paypal ipn that is returned. Anyway my checkout_success.php has that stylesheet code, if you are searching in dreamweaver it just might not have come up in the search if you pasted it ... .look around line 58, that's where it is on mine, if not try doing a search in the php file just for "stylesheet.css" and you'll probably find the right line. The other code should be at the very bottom of your php file. It's the second to last require in mine, my line # for it is 163. I'm on RC1, can't imagine it being that much different.

 

 

Allow me to expand... The instructions provided state the following misnomers:

 

6. open/edit catalog/checkout_success.php

 

---------------------------------------------------------------------------

 

7. Under <link rel="stylesheet" type="text/css" href="style.css"> paste the following code:

 

<script type="text/javascript">
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
	var pageTracker = _gat._getTracker("UA-xxxxxxx-x");
	pageTracker._initData();
	pageTracker._trackPageview();

	<?php 
		include(DIR_WS_MODULES . 'analytics/analytics.php'); 
	?>

</script>

 

Well... my checkout_success.php (osCommerce Online Merchant v2.2 RC2) doesn't have a <head> with a linked in stylesheet. It's all PHP, from line 1 to end. I'm a little displaced with the above instruction. The same applies to this rule of instruction:

 

9. At the bottom of the file checkout_success.php change the following line:

 

<!-- footer //-->
	<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->

into

<!-- footer //-->
	<?php require(DIR_WS_INCLUDES . 'footer-tracker.php'); ?>
<!-- footer_eof //-->

 

I don't have a footer include request in my checkout_success.php.

 

If anyone can advise I'd greatly appreciate it!

Edited by Jayman11
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...