Jump to content
osCoders

Google Analytics module

Recommended Posts

I may have just figured out the problem. When I did the body tag, I accidentally put a space in javascript. I had it as java script. Duh! I've fixed that and I'll see if that makes it work now. Thanks for being so patient with me! :blush:

 

this is what I can read in the Google Analytics OScomm installation file. there is no reason you didn't see the same ;)

 

2. Edit checkout_success.php -

 

INSERT into the <body tag the following code:

 

onLoad="java script:__utmSetTrans()"

Finally the line should look like this:

	<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" onLoad="java script:__utmSetTrans()">

3. Edit checkout_success.php -

 

ADD right ABOVE the </body> tag (the bottom of the page)

 

<?php 
// osCoders.biz - Analystics - start 
	include(DIR_WS_MODULES . 'analytics/analytics.php'); 
// osCoders.biz - Analistics - end
?>

4. Upload the analytics.php into a new includes/modules/analytics directory like:

 

- includes/modules/analytics/analytics.php


Laurel

Share this post


Link to post
Share on other sites
Ok, how long do ecommerce statistics usually take to show up in analytics? I fear I have done something wrong.

 

I've linked the analytics code in my header to the https://js.etc google tracker, and I have the correct code in place throughout the website. Then, on google analytics itself I have defined my website as https://mysite.com

 

And yet nothing shows up in the ecommerce section. If I set it to https as I have above for all of my pages, will it record the transactions as well as regular pages no problem? What have I done wrong?

Any thoughts on this? The ssl issue is very confusing with analytics, and I think it should be made clearer in their answers section explaining ecommerce integration.

Share this post


Link to post
Share on other sites
Any thoughts on this? The ssl issue is very confusing with analytics, and I think it should be made clearer in their answers section explaining ecommerce integration.

 

results show up usually after 24 hours

Share this post


Link to post
Share on other sites

I think I have found the problem. I put the google code in my header file, which is called after the <body> command in the checkout_success file. Do you think there would be any problem in placing the code, in addition to in the header, before the <body> on that one page, or would calling the same script twice on the same page cause errors?

Share this post


Link to post
Share on other sites

I'd be interested in it too. I still can't get purchases to show up in Goole Analytics.

Edited by amigaman

Share this post


Link to post
Share on other sites
I'd be interested in it too. I still can't get purchases to show up in Goole Analytics.

 

could you post

1) your site's url so I can see how the HTML and js is rendered when STS is installed

2) your checkout_sucess.php code

Share this post


Link to post
Share on other sites
could you post

1) your site's url so I can see how the HTML and js is rendered when STS is installed

2) your checkout_sucess.php code

 

 

Sure site is www.mrcloud.com

 

 

Checkout_success.php is as below:

 

<?php

/*

$Id: checkout_success.php,v 1.49 2003/06/09 23:03:53 hpdl Exp $

 

osCommerce, Open Source E-Commerce Solutions

http://www.oscommerce.com

 

Copyright © 2003 osCommerce

 

Released under the GNU General Public License

*/

 

require('includes/application_top.php');

 

// if the customer is not logged on, redirect them to the shopping cart page

if (!tep_session_is_registered('customer_id')) {

tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));

}

 

if (isset($HTTP_GET_VARS['action']) && ($HTTP_GET_VARS['action'] == 'update')) {

$notify_string = 'action=notify&';

$notify = $HTTP_POST_VARS['notify'];

if (!is_array($notify)) $notify = array($notify);

for ($i=0, $n=sizeof($notify); $i<$n; $i++) {

$notify_string .= 'notify[]=' . $notify[$i] . '&';

}

if (strlen($notify_string) > 0) $notify_string = substr($notify_string, 0, -1);

 

// PWA BOF

if($customer_id != 0)

{

tep_redirect(tep_href_link(FILENAME_DEFAULT, $notify_string));

}

else

{

tep_session_unregister('pwa_array_customer');

tep_session_unregister('pwa_array_address');

tep_session_unregister('pwa_array_shipping');

tep_session_unregister('customer_id');

tep_redirect(tep_href_link(FILENAME_DEFAULT));

}

// PWA EOF

}

 

 

require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_SUCCESS);

 

$breadcrumb->add(NAVBAR_TITLE_1);

$breadcrumb->add(NAVBAR_TITLE_2);

 

$global_query = tep_db_query("select global_product_notifications from " . TABLE_CUSTOMERS_INFO . " where customers_info_id = '" . (int)$customer_id . "'");

$global = tep_db_fetch_array($global_query);

 

if ($global['global_product_notifications'] != '1') {

$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);

 

$products_array = array();

$products_query = tep_db_query("select products_id, products_name from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . (int)$orders['orders_id'] . "' order by products_name");

while ($products = tep_db_fetch_array($products_query)) {

$products_array[] = array('id' => $products['products_id'],

'text' => $products['products_name']);

}

}

?>

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">

<html <?php echo HTML_PARAMS; ?>>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">

<title><?php echo TITLE; ?></title>

<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">

<link rel="stylesheet" type="text/css" href="stylesheet.css">

</head>

<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<!-- header //-->

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

<!-- header_eof //-->

 

<!-- body //-->

<table border="0" width="100%" cellspacing="3" cellpadding="3">

<tr>

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- left_navigation //-->

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

<!-- left_navigation_eof //-->

</table></td>

<!-- body_text //-->

<td width="100%" valign="top"><?php echo tep_draw_form('order', tep_href_link(FILENAME_CHECKOUT_SUCCESS, 'action=update', 'SSL')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td><table border="0" width="100%" cellspacing="4" cellpadding="2">

<tr>

<td valign="top"><?php echo tep_image(DIR_WS_IMAGES . 'table_background_man_on_board.gif', HEADING_TITLE); ?></td>

<td valign="top" class="main"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?><div align="center" class="pageHeading"><?php echo HEADING_TITLE; ?></div><br><?php echo TEXT_SUCCESS; ?><br><br>

<?php

if ($global['global_product_notifications'] != '1') {

echo TEXT_NOTIFY_PRODUCTS . '<br><p class="productsNotifications">';

 

$products_displayed = array();

for ($i=0, $n=sizeof($products_array); $i<$n; $i++) {

if (!in_array($products_array[$i]['id'], $products_displayed)) {

echo tep_draw_checkbox_field('notify[]', $products_array[$i]['id']) . ' ' . $products_array[$i]['text'] . '<br>';

$products_displayed[] = $products_array[$i]['id'];

}

}

 

echo '</p>';

} else {

echo TEXT_SEE_ORDERS . '<br><br>' . TEXT_CONTACT_STORE_OWNER;

}

?>

<h3><?php echo TEXT_THANKS_FOR_SHOPPING; ?></h3></td>

</tr>

</table></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<tr>

<td align="right" class="main"><?php echo tep_image_submit('button_continue.gif', IMAGE_BUTTON_CONTINUE); ?></td>

</tr>

<tr>

<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>

</tr>

<tr>

<td><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td width="50%" align="right"><?php echo tep_draw_separator('pixel_silver.gif', '1', '5'); ?></td>

<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>

</tr>

</table></td>

<td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>

<td width="25%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>

<td width="25%"><table border="0" width="100%" cellspacing="0" cellpadding="0">

<tr>

<td width="50%"><?php echo tep_draw_separator('pixel_silver.gif', '100%', '1'); ?></td>

<td width="50%"><?php echo tep_image(DIR_WS_IMAGES . 'checkout_bullet.gif'); ?></td>

</tr>

</table></td>

</tr>

<tr>

<td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_DELIVERY; ?></td>

<td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_PAYMENT; ?></td>

<td align="center" width="25%" class="checkoutBarFrom"><?php echo CHECKOUT_BAR_CONFIRMATION; ?></td>

<td align="center" width="25%" class="checkoutBarCurrent"><?php echo CHECKOUT_BAR_FINISHED; ?></td>

</tr>

</table></td>

</tr>

<?php if (DOWNLOAD_ENABLED == 'true') include(DIR_WS_MODULES . 'downloads.php'); ?>

</table></form></td>

<!-- body_text_eof //-->

<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">

<!-- right_navigation //-->

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

<!-- right_navigation_eof //-->

</table></td>

</tr>

</table>

<!-- body_eof //-->

 

<!-- footer //-->

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

<!-- footer_eof //-->

<br>

<?php

// osCoders.biz - Analystics - start

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

// osCoders.biz - Analistics - end

?>

</body>

</html>

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

 

Thanks!

Share this post


Link to post
Share on other sites
could you post

1) your site's url so I can see how the HTML and js is rendered when STS is installed

2) your checkout_sucess.php code

 

 

Any ideas on what I posted?

Share this post


Link to post
Share on other sites
Any ideas on what I posted?

 

sorry I forgot to answer: I looked at both, didn't see anything wrong...

Share this post


Link to post
Share on other sites

Small display bug!

 

in modules/analytics/analytics.php, at the end of the file, change:

from

<textarea id="utmtrans">

to

<textarea id="utmtrans" style="display:none;">

in order to be compatible with more browsers (Safari in particular).

Share this post


Link to post
Share on other sites

Thanks for your help!

 

I'm getting this error in my server logs. Any idea how to fix it?

 

[10-Dec-2006 18:41:22] PHP Warning: session_register() [<a href='function.session-register'>function.session-register</a>]: Cannot send session cache limiter - headers already sent (output started at /html/catalog/includes/modules/analytics/analytics.php:77) in /html/catalog/includes/functions/sessions.php on line 74

Share this post


Link to post
Share on other sites

I guess i figured out a failure. An order of 1300 EUR is being shown as 1 EUR in Google Analytics. I therefore changed the following:

 

number_format($items['final_price'], 2)

replaced with

str_replace(",", "", number_format($items['final_price'], 2))

 

so that 1,300.00 is changed to 1300.00. Unfortunately i mentioned that this did not solve the problem. Does anyone have the same problem and/or an idea how to fix this?

Edited by flom

Share this post


Link to post
Share on other sites

i think i solved the problem:

 

there is another function to be changed:

 

$analytics_total

change to

str_replace(",", "", $analytics_total)

 

hope it will work

Share this post


Link to post
Share on other sites

Hi all..

 

Ive installed the Google analytics module.. and everything seems to be working fine fine for me with the tracking and goal tracings. Also everything with e-shopping seems to be working.

 

BUT.. one thing seems to be failing for me..

 

I use a payment gateway for checkout.. so analytics show the refferals to be my own site :(

 

Google kinda allready posted a support thread for this issue.. but i cant seem to get this working.

 

http://adwords.google.com/support/bin/answer.py?answer=26915

 

 

Have anyone gotten this to work yet ??

 

Ive googled and searched this forum a lot without finding anyone that have fixed this issue..

Share this post


Link to post
Share on other sites

Just a little error I noticed. I haven't had time to test it much and/or fix the error, but I did a quick purchase on my site with css disable to see what the form it was submitting on the 'Thank You' page looked like and to make sure everything was correct.

 

I don't know if this has something to do with the will call contrib that I have (if the shipping address is in-state you can opt for will-call), but when I changed my address to the secondary address to enable will-call, on the 'Thank You' page the form was filled out with the primary address.

Obviously that was not the address I had chosen as my ship-to.

 

Just thought I would report that here in case anybody wants to check that out.

Share this post


Link to post
Share on other sites

I've installed Google Analytics with ecommerce (http://www.oscommerce.com/community/contributions,3756) in my OSC site (http://www.lenoir.es). The Ecommerce script seems to work fine but I've a problem :'( with the general script.

 

The general script (for tracking) is on footer.php file (like contrib indicates). But analyzing the Apache log file, results are VERY different then analyzing with Analytics: Visitors increasing x 3 and pages x 6 aprox in log file.

 

Any help would be great...

Share this post


Link to post
Share on other sites

Hi,

I used this contrib but edited it slightly so i could ammend the googleid from the admin

 

added this

INSERT INTO `configuration` VALUES (70, 'Google Analytics', 'GOOGLE_ID', 'google_id_here', 'Google Analytics ID', 1, 16, '2007-01-05 07:11:31', '2006-01-11 06:48:43', NULL, NULL);

 

(just have to be careful of the ID field that it doesn't clash)

 

Then changed the javascript to:

 

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

</script>

<script type="text/javascript">

_uacct = "<? echo GOOGLE_ID; ?>";

urchinTracker();

</script>

 

Maybe useful to someone out there

Share this post


Link to post
Share on other sites

Can anyone tell me if the analytics code is in the right place in my checkout_succes.php ?

 

at the top -

 

<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>

<?php
			// osCoders.biz - Analystics - start
			/*
			Conditional code added thank to  rrodkey and bfcase
			IMPORTANT -- IMPORTANT - IMPORTANT
			You'll need to update the "xxxx-x" in the samples (twice) above with your own Google Analytics account and profile number. 
			To find this number you can access your personalized tracking code in its entirety by clicking Check Status in the Analytics Settings page of your Analytics account.
			*/
			if ($request_type == 'SSL') {
			?>
			 <script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
			 </script>
			 <script type="text/javascript">
			   _uacct="UA-xxxxx-x";
			   urchinTracker();
			 </script>
			<?php
			} else {
			?>
			 <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
			 </script>
			   <script type="text/javascript">
				_uacct="UA-xxxxx-x";
				urchinTracker();
			 </script>
			<?
			}
			// osCoders.biz - Analistics - end
			?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" onLoad="java script:__utmSetTrans()">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->

 

At the bottom -

 

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
<?php 
// osCoders.biz - Analystics - start 
	include(DIR_WS_MODULES . 'analytics/analytics.php'); 
// osCoders.biz - Analistics - end
?>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

 

 

can anyone confirm this correct ?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×