Forums / General Questions / Google Analytics update

Google Analytics update

Locked

Views: 6,670

Results 1 to 17 of 17
This thread is locked. New replies are disabled.
17 May 2006, 6:06 PM
#1
besheer avatar

besheer

New Zenner

Join Date:
Nov 2004
Posts:
69
Plugin Contributions:
0

Google Analytics update

Just wondering if the instructions posted here: http://www.zen-cart.com/forum/showthread.php?t=25233&highlight=analytics on how to integrate GA into ZC are still valid with the newest version (1.3.0.1). Sorry to start a new thread, but the other one is locked and I would really like to use GA without breaking the cart.

This is what they had concluded I think:

#1 Go to your Google Analytics Settings -> Edit Settings -> Edit Main Website Profile -> E-Commerce Website : Yes

#2 Edit
includes/templates/your-template/common/html_header.php
At the very bottom just before </head>

<?php if ($request_type == 'NONSSL') { echo '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-XXXXXX-1"; urchinTracker(); </script>'; } else { echo '<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-XXXXXX-1"; urchinTracker(); </script>'; } ?> </head> ``` > > > #3 Create a new file: > includes/modules/pages/checkout_success/on_load_ga.js > Insert into the new file: > > > ``` javascript:__utmSetTrans() ``` > > > #4 Edit > includes/templates/template_default/tpl_checkout_success_default.php > At the very bottom add: > > > ``` <?php $ga_orders_id = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' order by date_purchased desc limit 1"); $ga_utm_t = $db->Execute("select order_total , order_tax, delivery_city, delivery_state, delivery_country from " . TABLE_ORDERS . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "'"); $ga_utm_t_delivery_country = $db->Execute("select countries_iso_code_2 from " . TABLE_COUNTRIES . " where countries_name = '" . $ga_utm_t->fields['delivery_country'] . "'"); $ga_utm_t_delivery_state = $db->Execute("select zone_code from " . TABLE_ZONES . " where zone_name = '" . $ga_utm_t->fields['delivery_state'] . "'"); $ga_utm_t_ship = $db->Execute("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "' && class = 'ot_shipping'"); $ga_utm_i = $db->Execute("select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "' order by products_name"); //$ga_utm_i_category = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $ga_utm_i->fields['products_id'] . "'"); //$ga_utm_i_category_name = $db->Execute("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $ga_utm_i_category->fields['categories_id'] . "'");

$ga_utm_i_array = array();
while (!$ga_utm_i->EOF) {
$ga_utm_i_array[] = array('product_id' => $ga_utm_i->fields['products_id'],
'name' => $ga_utm_i->fields['products_name'],
'price' => $ga_utm_i->fields['final_price'],
'quantity' => $ga_utm_i->fields['products_quantity'],
//'category' => $ga_utm_i_category_name->fields['categories_name']
);
$ga_utm_i->MoveNext();
}
?>

<form style="display:none;" name="utmform"> <textarea id="utmtrans"> UTM:T|<?php echo $ga_orders_id->fields['orders_id'] . '|' . "zencart" . '|' . $ga_utm_t->fields['order_total'] . '|' . $ga_utm_t->fields['order_tax'] . '|' . substr($ga_utm_t_ship->fields['value'], 0, 4) . '|' . $ga_utm_t->fields['delivery_city'] . '|' . $ga_utm_t_delivery_country->fields['countries_iso_code_2'] . '|' . $ga_utm_t_delivery_state->fields['zone_code']; ?> <?php $ga_utm_i_array_displayed = array(); for ($i=0, $n=sizeof($ga_utm_i_array); $i<$n; $i++) { if (!in_array($ga_utm_i_array[$i]['products_id'], $ga_utm_i_array_displayed)) { echo ' UTM:I|' . $ga_orders_id->fields['orders_id'] . '|' . $ga_utm_i_array[$i]['product_id'] . '|' . $ga_utm_i_array[$i]['name'] . '||' . sprintf("%01.2f", $ga_utm_i_array[$i]['price']) . '|' . $ga_utm_i_array[$i]['quantity']; } } ?>
20 May 2006, 5:55 PM
#2
besheer avatar

besheer

New Zenner

Join Date:
Nov 2004
Posts:
69
Plugin Contributions:
0

Re: Google Analytics update

In case anyone is wondering, I've been using it for a few days and everything seems to be working alright.

20 May 2006, 7:55 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Google Analytics update

The more effective way to do the step you mentioned above for "includes/templates/your-template/common/html_header.php" is to create a new file called:
includes/templates/YOURTEMPLATE/jscript/jscript_google_analytics.php

... and put the code you suggested above into that file instead.

This will make upgrading Zen Cart easier because it won't have touched the html_header.php core file.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

22 May 2006, 7:42 PM
#4
besheer avatar

besheer

New Zenner

Join Date:
Nov 2004
Posts:
69
Plugin Contributions:
0

Re: Google Analytics update

But being in the includes/templates/your-template/common/ directory, isn't the file untouched anyway?

22 May 2006, 11:34 PM
#5
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Google Analytics update

yes, it's untouched, but if the next version of zen cart includes an update to the template_default/common/html_header.php file, then YOU NEED TO MERGE THOSE CHANGES into YOUR includes/templates/XXXXXCUSTOM/common/html_header.php file

I was just suggesting to use the jscript overrides system to save yourself the step.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

21 Jun 2006, 12:50 AM
#6
wickedklown avatar

wickedklown

Zen Follower

Join Date:
Aug 2005
Posts:
370
Plugin Contributions:
0

Re: Google Analytics update

drbyte,

You said to create another file in the jscript directory. Exactly what code should be entered into that file? all of it, or just the stuff thats suppose to be in html_header.php?
and the rest of it is as stated? or does all the code go into that one file?

Any help would be great

Super Orders2
Info at a glance
export email address
encrypted master pass
quick updates
recover carts
order Tracking
Tabbed products lite - admin edition
Hosted with sashbox.net <- best host around...

21 Jun 2006, 1:29 AM
#7
wickedklown avatar

wickedklown

Zen Follower

Join Date:
Aug 2005
Posts:
370
Plugin Contributions:
0

Re: Google Analytics update

sorry for the double post, but im noticing something that might be a problem

for some reason the tpl_checkout_sucess_defualt.php file is located in

/includes/templates/template_defult/templates

is this correct, or did i mess something up when i updated??????

everything has been functional, although this dont seem to be the correct structure that you guys have listed here...

please help

Super Orders2
Info at a glance
export email address
encrypted master pass
quick updates
recover carts
order Tracking
Tabbed products lite - admin edition
Hosted with sashbox.net <- best host around...

22 Jun 2006, 12:34 AM
#8
wickedklown avatar

wickedklown

Zen Follower

Join Date:
Aug 2005
Posts:
370
Plugin Contributions:
0

Re: Google Analytics update

well it seems to be working, however i dont see any of my sales being shown on the google page.....

anyone else having this issue?

Super Orders2
Info at a glance
export email address
encrypted master pass
quick updates
recover carts
order Tracking
Tabbed products lite - admin edition
Hosted with sashbox.net <- best host around...

25 Jun 2006, 9:19 PM
#9
besheer avatar

besheer

New Zenner

Join Date:
Nov 2004
Posts:
69
Plugin Contributions:
0

Re: Google Analytics update

You have to set it up as an "e-commerce" site. It's hidden somewhere in the Google Analytics settings.

14 Jul 2006, 9:41 AM
#10
pauls avatar

pauls

Zen Follower

Join Date:
Feb 2006
Location:
UK
Posts:
300
Plugin Contributions:
0

Re: Google Analytics update

Is the last </HEAD> tag in the code for step #2 required? Seems to me that that places a second closing head tag, surely not correct?

Having added all of the above, I placed an order and although ganalytics states its 'receiving data' no amount of visits by me to the site are showing up in Google Analytics? Only thing I did different to the above was use the overrides folder for this file ```
includes/templates/template_default/tpl_checkout_success_default.php

includes/templates/template_default/templates/MYSTLE/tpl_checkout_success_default.php

15 Jul 2006, 8:25 AM
#11
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Google Analytics update

Pauls:

I placed the file here
includes/templates/template_default/templates/MYSTLE/tpl_checkout_success_default.php is this correct?

This would be more accurate:
includes/templates/**MYSTYLE/**templates/tpl_checkout_success_default.php

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

1 Aug 2006, 7:58 AM
#12
pstarling avatar

pstarling

New Zenner

Join Date:
Sep 2005
Location:
New Zealand
Posts:
92
Plugin Contributions:
0

Re: Google Analytics update

DrByte you said:

DrByte:

The more effective way to do the step you mentioned above for "includes/templates/your-template/common/html_header.php" is to create a new file called:
includes/templates/YOURTEMPLATE/jscript/jscript_google_analytics.php

... and put the code you suggested above into that file instead.

This will make upgrading Zen Cart easier because it won't have touched the html_header.php core file.

Makes perfect sence but how does Zen Cart call the file > includes/templates/YOURTEMPLATE/jscript/jscript_google_analytics.php that I have just created?

Do I need a line of code some where to call the file?

1 Aug 2006, 9:30 PM
#13
lawman avatar

lawman

Zen Follower

Join Date:
Mar 2006
Posts:
102
Plugin Contributions:
0

Re: Google Analytics update

I loose my footer when I paste the code for step #4 (Edit
includes/templates/template_default/tpl_checkout_success_default.php
At the very bottom add..."

Should it should be placed directly after the following line?

<h3 id="checkoutSuccessThanks" class="centeredContent"><?php echo TEXT_THANKS_FOR_SHOPPING; ?></h3>

</div>
2 Aug 2006, 7:03 AM
#14
dantheman avatar

dantheman

New Zenner

Join Date:
May 2005
Location:
Toronto, Ontario, Canada
Posts:
41
Plugin Contributions:
0

Re: Google Analytics update

<?php $ga_orders_id = $db->Execute("select orders_id from " . TABLE_ORDERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "' order by date_purchased desc limit 1"); $ga_utm_t = $db->Execute("select order_total , order_tax, delivery_city, delivery_state, delivery_country from " . TABLE_ORDERS . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "'"); $ga_utm_t_delivery_country = $db->Execute("select countries_iso_code_2 from " . TABLE_COUNTRIES . " where countries_name = '" . $ga_utm_t->fields['delivery_country'] . "'"); $ga_utm_t_delivery_state = $db->Execute("select zone_code from " . TABLE_ZONES . " where zone_name = '" . $ga_utm_t->fields['delivery_state'] . "'"); $ga_utm_t_ship = $db->Execute("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "' && class = 'ot_shipping'"); $ga_utm_i = $db->Execute("select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $ga_orders_id->fields['orders_id'] . "' order by products_name"); //$ga_utm_i_category = $db->Execute("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $ga_utm_i->fields['products_id'] . "'"); //$ga_utm_i_category_name = $db->Execute("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $ga_utm_i_category->fields['categories_id'] . "'"); $ga_utm_i_array = array(); while (!$ga_utm_i->EOF) { $ga_utm_i_array[] = array('product_id' => $ga_utm_i->fields['products_id'], 'name' => $ga_utm_i->fields['products_name'], 'price' => $ga_utm_i->fields['final_price'], 'quantity' => $ga_utm_i->fields['products_quantity'], //'category' => $ga_utm_i_category_name->fields['categories_name'] ); $ga_utm_i->MoveNext(); } ?> <form style="display:none;" name="utmform"> <textarea id="utmtrans"> UTM:T|<?php echo $ga_orders_id->fields['orders_id'] . '|' . "zencart" . '|' . $ga_utm_t->fields['order_total'] . '|' . $ga_utm_t->fields['order_tax'] . '|' . substr($ga_utm_t_ship->fields['value'], 0, 4) . '|' . $ga_utm_t->fields['delivery_city'] . '|' . $ga_utm_t_delivery_country->fields['countries_iso_code_2'] . '|' . $ga_utm_t_delivery_state->fields['zone_code']; ?> <?php $ga_utm_i_array_displayed = array(); for ($i=0, $n=sizeof($ga_utm_i_array); $i<$n; $i++) { if (!in_array($ga_utm_i_array[$i]['products_id'], $ga_utm_i_array_displayed)) { echo ' UTM:I|' . $ga_orders_id->fields['orders_id'] . '|' . $ga_utm_i_array[$i]['product_id'] . '|' . $ga_utm_i_array[$i]['name'] . '||' . sprintf("%01.2f", $ga_utm_i_array[$i]['price']) . '|' . $ga_utm_i_array[$i]['quantity']; } } ?>

For some reason, the code above is not working properly, for me anyway.

It fails to pass the following data to Google Analytics (E-commerce section): City, State, Country & Category.

This is what the output looks like:

UTM:T|4081|Main Store|5.00|2.00|1.00|||
UTM:I|4081|185|Widget||5.00|1

While according to Google, it could look like this:

UTM:T|4081|Main Store|5.00|2.00|1.00|Toronto|Ontario|Canada
UTM:I|4081|185|Widget|Widgets & Things|5.00|1

Am I missing something?  It seems some of the code is commented out, but un-commenting it has no effect...

Also, Google seems to ignore the submitted data most of the time, it only registered a few transactions, others are not there...

Please help!

Dan G.

<https://www.NotebookSolutions.ca>

Dan G.

Notebook Solutions Inc.

http://www.notebooksolutions.ca

*Whoever said that money can’t buy happiness simply didn’t know where to go shopping.

  • Sydney J. Harris*
2 Aug 2006, 3:42 PM
#15
lawman avatar

lawman

Zen Follower

Join Date:
Mar 2006
Posts:
102
Plugin Contributions:
0

Re: Google Analytics update

^^^ same here... it was working for me but hasn't picked up a sale over the past week. I removed it for now - at least I got my footer back

9 Aug 2006, 1:09 PM
#16
pauls avatar

pauls

Zen Follower

Join Date:
Feb 2006
Location:
UK
Posts:
300
Plugin Contributions:
0

Re: Google Analytics update

Google analytics works for me using the settings above, however I don't get any data on any sales, so something is not quite right at my end of things either. Other than the lack of sales reports the analytics is superb ... just wish I could make the sales show up too :(

20 Aug 2006, 8:32 AM
#17
a_berezin avatar

a_berezin

Deceased

Join Date:
Aug 2004
Location:
Saint Petersburg, Russia
Posts:
1,782
Plugin Contributions:
5

Re: Google Analytics update

NOTE: We are sorry that Andrew is no longer with us.
We are grateful for all his contributions to the Zen Cart community.