Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

google analystic ecommerce


Guest

Recommended Posts

Posted

I've installed Google Analytics E commerce Integration as follow

 

 

Google Analytics E commerce Integration

 

 

This is a small hack put together to enable google analytics transaction tracking, I am by no way a programmer, if you have corrections. Please submit them. This is a pretty easy addition to your checkout system, it does require that you have a google analytics account setup for your site as an ecommerce site. You MUST also have the google tracking code installed on your site, (if you need help with that there is a contribution for that http://www.oscommerce.com/community/contributions,3756)

Please ensure that you either include the google tracking code from the footer of the document. OR ensure that where ever you put it in checkout_success.php it is after the call to urchin.js or the function __utmSetTrans() wont be defined and you will get errors in your JS console.

 

NOTE: My version is OSC is heavily modified. Line numbers will not match up to yours.... good luck.

 

We will be modifying two files for this

/catalog/checkout_process.php

/catalog/checkout_success.php

 

 

 

Good Luck

Shane

 

 

------- INSTRUCTIONS --------

backup your whole /catalog folder

backup your whole database

This is always a good way to start the day, helps for when you accidentally breaksomething

 

backup /catalog/checkout_process.php

 

Starting in /catalog/checkout_process.php

 

Right Around Line 13

 

include('includes/application_top.php');

 

 

----- ADD IN BELOW IT -----

 

// GOOGLE ANALYTICS BOF

// Reset the two variables in case we are processing a second order in the same session.

 

$_SESSION['google_analytics'] = '';

$google_analytics = '';

 

// GOOGLE ANALYTICS EOF

 

 

 

 

 

Half way down the page around line 227

 

tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);

$order_products_id = tep_db_insert_id();

 

 

 

----- ADD IN BELOW IT -----

 

// GOOGLE ANALYTICS BOF

 

$category = 'NULL';

 

$prod_category = tep_db_query("select c.categories_name as cname from categories_description as c, products_to_categories as p where p.categories_id = c.categories_id and p.products_id = '". $order->products[$i]['id'] ."' limit 1");

 

if (tep_db_num_rows($prod_category) > 0) {

$pc_values = tep_db_fetch_array($prod_category);

$category = $pc_values['cname'];

}

 

$google_analytics .= 'UTM:I|'.$insert_id.'|'.$order->products[$i]['model'].'|'.$order->products[$i]['name'].'|'. $category .'|'. $order->products[$i]['price'].'|'.$order->products[$i]['qty']."\n";

 

 

// GOOGLE ANALYTICS EOF

 

 

 

 

 

 

Next addition goes below this line, roughly Line 273

 

$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";

 

 

----- ADD IN BELOW IT -----

 

// GOOGLE ANALYTICS BOF

 

// Peter Anderson added the following line to register the session:

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

 

 

Close the file.

Open up /catalog/checkout_success.php

 

At the bottom of the file, below the footer include line

 

<!-- footer //-->

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

<!-- footer_eof //-->

 

Insert this code.

 

 

// GOOGLE ANALYTICS BOF

<!-- Google analytics transaction tracking -->

<form style="display:none;" name="utmform">

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

<? echo $_SESSION['google_analytics']; ?>

</textarea>

</form>

 

<script type="text/javascript">

__utmSetTrans();

</script>

<?

// reset these bits.

$_SESSION['google_analytics'] = '';

tep_session_unregister('google_analytics');

 

// GOOGLE ANALYTICS EOF

?>

 

That should be it, ensure when testing this that you dont have filters in google analytics setup to ignore your IP, it could keep your orders from being tracked. Make sure to check your handy dandy Javascript console for errors and view source to ensure everything shows up.

 

 

I don't know when i'll see the result on the google report, but i guess I've to wait a day or two.

 

My problem is that after i did theese changes my order confirmation mail look like this.

 

 

doppresent.sen------------------------------------------------------nOrdernummer: 1617nDetaljerad faktura: http://www.doppresent.se/account_history_i...617nOrderdatum: Söndag 11 November, 2007nnProduktern------------------------------------------------------n1 x Baby Art Print (549202) = 199.00Krn------------------------------------------------------nTotalt exklusive frakt: 199.00KrnHämtas hos oss (Hämta hos oss, ring för att komma överens om en tid): 0.00KrnVarav moms 25%: 39.80KrnTotalt: 199.00KrnnLeveransadressn------------------------------------------------------nJohan SundbergnHöjdvägen 20n14251 SkogåsnSverigenTel: 08-7719100nnFakturaadressn------------------------------------------------------nJohan SundbergnHöjdvägen 20n14251 SkogåsnSverigenTel: 08-7719100nnBetalningssättn------------------------------------------------------nFörskottsinbetalningnnBetala till: Bankgiro: 5347-5018

Looks like the line brakes dosent work anymore, and after each line I have "n".

Do you have any idees??

Posted

Editing PHP files with the osc File Manager (unpatched version) will cause that. Don't use it.

 

Start over with your backup copy (You did make a backup?)

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 >

Posted

Dosnt work.

 

Also I'm missing the data in the analytics report....

 

Damn... I want this to work..... :blink:

Posted
Dosnt work.

 

Also I'm missing the data in the analytics report....

 

Damn... I want this to work..... :blink:

 

Not a complete answer for you but Analytics data will take at least 24 hours to show up in reports.

Thanks for any help/comments.

 

Regards,

 

Lewis Hill

Posted

Craxen,

 

Take two aspirin and call me tomorrow afternoon...

:lol:

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 >

Archived

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

×
×
  • Create New...