New Zenner
- Join Date:
- Mar 2007
- Location:
- NJ
- Posts:
- 68
- Plugin Contributions:
- 0
Google Analytics Integration
I agree - please keep an interest and support of your mod. I'm very grateful for it and appreciate the help and work you have done.
:clap:
Views: 225,787
New Zenner
I agree - please keep an interest and support of your mod. I'm very grateful for it and appreciate the help and work you have done.
:clap:
Zen Follower
I just signed up for Google Analytics. My question is: What's the difference between this mod and just directly inserting the google tracking script code into the template/common/html_header.php file?
Totally Zenned
davemehta:
I just signed up for Google Analytics. My question is: What's the difference between this mod and just directly inserting the google tracking script code into the template/common/html_header.php file?
There is no difference (the mod makes it easier without the need to "touch code" from within the Admin).
By the way, I would recommend that if you are going to insert the code yourself, then don't insert it into the header file. I would recommend inserting it into the "tpl_main_page.php" found in the "common" folder (includes/templates/[your template]/common ).
That is the better place to put it (and the spot that the Simple Google Analytics inserts it).
I have inserted the Google Analytics code (along with e-com tracking and conversion tracking) on older carts just by pasting into the bottom as indicated here. Again, the mod provided makes it a bit easier. (Why not take the "easy route")?
Deceased
davemehta:
What's the difference between this mod and just directly inserting the google tracking script code into the template/common/html_header.php file?
If you "directly inserting the google tracking script code" in template/common/tpl_footer.php:
Totally Zenned
a_berezin:
If you "directly inserting the google tracking script code" in template/common/tpl_footer.php:
- You can't use page names in Google Analytics (you can use only title for a name of page if you add some code to tracking script);
- You should add in a tracking script ssl checking;
- You can't track e-commerce transactions;
Actually, you can track all of the following by inserting code (into two different files) into the tpl_footer.php file AND /includes/modules/pages/checkout_success/header_php.php
(again, this works perfectly, but it may be much easier / faster to use the mod). I listed the code below to do it all (if you must insert by hand). I have been using it on a few Zen installs for over 6 months now with no problems.
To do all of the above and PLUS add "Google Conversion Tracking" as well to the mix, the following code should be inserted at the bottom of the tpl_footer.php (or tpl_main_page just above the closing </BODY> tag)
Keep in mind that the "xxxxxxx" shown in all areas below represents where your own Google ID would go (generated from within Google).
Also keep in mind that if you would like to actually track the "conversion value" (to get more accurate cost data for PPC reporting) then you would replace
if (1.0) {
google_conversion_value = 1.0;
}
with
if (echo $zv_order_total_cd) {
google_conversion_value = echo $zv_order_total_cd;
}
Ok, on with the code again, inserted at the bottom of the tpl_footer.php (or tpl_main_page just above the closing </BODY> tag)
<!-- Tracking -->
<?php // If page is SSL then use Secure Code
if($_SERVER['HTTPS']=='on'){
?>
<!-- Google Analytics -->
<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
<!-- /Google Analytics -->
<?php
if ($_GET['main_page']=="checkout_success") { // if transaction is a successful purchase then record the order details
?>
<!-- Google Analytics E-Commerce Tracking (must go below standard Analytics code)-->
<body onLoad="javascript:__utmSetTrans()">
<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|<?php echo $zv_orders_id ?>||<?php echo $zv_order_total_cd ?>|<?php echo $zv_order_tax ?>|0.00|<?php echo $zv_order_city ?>|<?php echo $zv_order_state ?>|<?php echo $zv_order_country ?>
<?php // Loop through products purchased to track in Google (these come from the "cart_orders_products TABLE)
//sku = "products_model"; productname = "products_name"; category = ""; price = "final_price"; quantity = "products_quantity"
$products_displayed_google = array();
for ($i=0, $n=sizeof($products_array_google); $i<$n; $i++) {
if (!in_array($products_array_google[$i]['id'], $products_displayed_google)) {
echo 'UTM:I|' . $zv_orders_id . '|' . $products_array_google[$i]['model'] . '|' . $products_array_google[$i]['text'] . '||' . $products_array_google[$i]['price'] . '|' . $products_array_google[$i]['quantity'];
$products_displayed_google[] = $products_array_google[$i]['id'];
}
}
?>
</textarea>
</form>
<!-- /Google Analytics E-Commerce Tracking -->
<!-- Google Code for purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "FFFFFF";
if (1.0) {
var google_conversion_value = 1.0;
}
var google_conversion_label = "purchase";
//-->
</script>
<script language="JavaScript" src="https://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src="https://www.googleadservices.com/pagead/conversion/xxxxxxxxxx/?value=<?php echo $zv_order_total_cd ?>&label=purchase&script=0">
</noscript>
<?php } //End if main page is "checkout_success"?>
<?php // Else use Non-Secure Code
} else {
?>
<!-- Google Analytics -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
<!-- /Google Analytics -->
<?php } ?>
<!-- / Tracking -->
The above code does the following:
Checks whether or not the page is a Secure page and then uses the appropriate code based on that check (secure or not secure)
Inserts Google Analytics Tracking
Inserts Google E-Commerce Tracking
Inserts Google Conversion Tracking.
Then, insert the following code into the /includes/modules/pages/checkout_success/header_php.php file just below the following line $zv_order_total_cd = $orders->fields['order_total']; (approximately line # 74.
// Added the below field for Google Analytics E-commerce Tracking (in the footer file)
$zv_order_tax = $orders->fields['order_tax'];
$zv_order_city = $orders->fields['delivery_city'];
$zv_order_state = $orders->fields['delivery_state'];
$zv_order_country = $orders->fields['delivery_country'];
// Google Analytics Tracking (This can be removed and not harm anything)
//Altered code below to accomdate additional fields that Google Analytics can Track
$products_query = "select products_id, products_name, products_model,products_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . $zv_orders_id . "'
order by products_name";
$products_google = $db->Execute($products_query);
//********************Google codes**************************
while (!$products_google->EOF) {
$products_array_google[] = array('id' => $products_google->fields['products_id'],
'text' => $products_google->fields['products_name'],
'model' => $products_google->fields['products_model'],
'price' => $products_google->fields['products_price'],
'quantity' => $products_google->fields['products_quantity']);
$products_google->MoveNext();
}
//*************************End Google Codes*******************
// End Google Analytics Code
Everything Google offers for the most part and then some. It can be done, just requires more steps to complete. :smile:
New Zenner
<!-- Tracking --> <?php // If page is SSL then use Secure Code if($_SERVER['HTTPS']=='on'){ ?> <!-- Google Analytics --> <script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-xxxxxx-x"; urchinTracker(); </script>econcepts:
Actually, you can track all of the following by inserting code (into two different files) into the tpl_footer.php file AND /includes/modules/pages/checkout_success/header_php.php
(again, this works perfectly, but it may be much easier / faster to use the mod). I listed the code below to do it all (if you must insert by hand). I have been using it on a few Zen installs for over 6 months now with no problems.
To do all of the above and PLUS add "Google Conversion Tracking" as well to the mix, the following code should be inserted at the bottom of the tpl_footer.php (or tpl_main_page just above the closing </BODY> tag)
Keep in mind that the "xxxxxxx" shown in all areas below represents where your own Google ID would go (generated from within Google).
Also keep in mind that if you would like to actually track the "conversion value" (to get more accurate cost data for PPC reporting) then you would replace
if (1.0) {
google_conversion_value = 1.0;
}with
if (echo $zv_order_total_cd) {
google_conversion_value = echo $zv_order_total_cd;
}Ok, on with the code again, inserted at the bottom of the tpl_footer.php (or tpl_main_page just above the closing </BODY> tag)
<!-- /Google Analytics -->
<?php
if ($_GET['main_page']=="checkout_success") { // if transaction is a successful purchase then record the order details
?>
<!-- Google Analytics E-Commerce Tracking (must go below standard Analytics code)-->
<body onLoad="javascript:__utmSetTrans()">
<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|<?php echo $zv_orders_id ?>||<?php echo $zv_order_total_cd ?>|<?php echo $zv_order_tax ?>|0.00|<?php echo $zv_order_city ?>|<?php echo $zv_order_state ?>|<?php echo $zv_order_country ?>
<?php // Loop through products purchased to track in Google (these come from the "cart_orders_products TABLE)
//sku = "products_model"; productname = "products_name"; category = ""; price = "final_price"; quantity = "products_quantity"
$products_displayed_google = array();
for ($i=0, $n=sizeof($products_array_google); $i<$n; $i++) {
if (!in_array($products_array_google[$i]['id'], $products_displayed_google)) {
echo 'UTM:I|' . $zv_orders_id . '|' . $products_array_google[$i]['model'] . '|' . $products_array_google[$i]['text'] . '||' . $products_array_google[$i]['price'] . '|' . $products_array_google[$i]['quantity'];
$products_displayed_google[] = $products_array_google[$i]['id'];
}
}
?>
</textarea>
</form>
<!-- /Google Analytics E-Commerce Tracking -->
<!-- Google Code for purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = xxxxxxxxxx;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "FFFFFF";
if (1.0) {
var google_conversion_value = 1.0;
}
var google_conversion_label = "purchase";
//-->
</script>
<script language="JavaScript" src="https://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0 src="https://www.googleadservices.com/pagead/conversion/xxxxxxxxxx/?value=<?php echo $zv_order_total_cd ?>&label=purchase&script=0">
</noscript>
<?php } //End if main page is "checkout_success"?>
<?php // Else use Non-Secure Code
} else {
?>
<!-- Google Analytics -->
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxx-x";
urchinTracker();
</script>
<!-- /Google Analytics -->
<?php } ?>
<!-- / Tracking -->
>
> 1) Checks whether or not the page is a Secure page and then uses the appropriate code based on that check (secure or not secure)
>
> 2) Inserts Google Analytics Tracking
>
> 3) Inserts Google E-Commerce Tracking
>
> 4) Inserts Google Conversion Tracking.
>
>
> Then, insert the following code into the /includes/modules/pages/checkout_success/header_php.php file just below the following line **$zv_order_total_cd = $orders->fields['order_total'];** (approximately line # 74.
>
> ```php
// Added the below field for Google Analytics E-commerce Tracking (in the footer file)
$zv_order_tax = $orders->fields['order_tax'];
$zv_order_city = $orders->fields['delivery_city'];
$zv_order_state = $orders->fields['delivery_state'];
$zv_order_country = $orders->fields['delivery_country'];
// Google Analytics Tracking (This can be removed and not harm anything)
//Altered code below to accomdate additional fields that Google Analytics can Track
$products_query = "select products_id, products_name, products_model,products_price, products_quantity from " . TABLE_ORDERS_PRODUCTS . "
where orders_id = '" . $zv_orders_id . "'
order by products_name";
$products_google = $db->Execute($products_query);
//********************Google codes**************************
while (!$products_google->EOF) {
$products_array_google[] = array('id' => $products_google->fields['products_id'],
'text' => $products_google->fields['products_name'],
'model' => $products_google->fields['products_model'],
'price' => $products_google->fields['products_price'],
'quantity' => $products_google->fields['products_quantity']);
$products_google->MoveNext();
}
//*************************End Google Codes*******************
// End Google Analytics Code
```Everything Google offers for the most part and then some. It can be done, just requires more steps to complete. :smile:
Thank you for the incredible step by step!
I'm having one issue though -
I don't see line:
**$zv_order_total_cd = $orders->fields['order_total'];
under
**/includes/modules/pages/checkout_success/header_php.php
I am using the latest version of zen cart.... could you advise? :)
thanks!
Totally Zenned
shaitaan:
Thank you for the incredible step by step!
I'm having one issue though -
I don't see line:
**$zv_order_total_cd = $orders->fields['order_total'];
under
**/includes/modules/pages/checkout_success/header_php.php
I am using the latest version of zen cart.... could you advise? :)
thanks!
Good point. The line I mentioned was from an older install of Zen. The line in newest versions of Zen that you will want to look for is in the same file but falls around line #54 and reads as follows:
$orders_id = $zv_orders_id;
In newer versions of Zen I used the simple Google analytics mod as it does not require any "code prep" to get it working. Then I include Conversion Tracking on my own. If you want to manually insert it, the code I provided here will work still.
Make sure you also include the following line (to get the order total) if it is not already present as well.
** $zv_order_total_cd = $orders->fields['order_total'];**
New Zenner
Been surfing through this thread, tried to d/l the mod from the first post with no luck. I would love to get google analytics running on my site without hand inputting all the coding myself, so, where can I find this download, and does it include a simple read me.txt.
Totally Zenned
RobVox:
Been surfing through this thread, tried to d/l the mod from the first post with no luck. I would love to get google analytics running on my site without hand inputting all the coding myself, so, where can I find this download, and does it include a simple read me.txt.
Download from here:
http://www.zen-cart.com/index.php?main_page=product_contrib_info&cPath=40_47&products_id=412
What version of Zen are you running?
New Zenner
The current version: 1.3.7
If I read that right, this mod is only good on 1.3.6???
And, is this version Andrew's or Cuda's, or is there a difference? What I was reading made it sound like Andrew's was the easier to use and install, also allowing of admin controls?
Thanks for the help!
Totally Zenned
RobVox:
The current version: 1.3.7
If I read that right, this mod is only good on 1.3.6???
And, is this version Andrew's or Cuda's, or is there a difference? What I was reading made it sound like Andrew's was the easier to use and install, also allowing of admin controls?
Thanks for the help!
As I have gathered from reading the forums, a version was started by Andrew sometime ago I believe. It was taken over by Cuda somewhere along the line, or he created his own version, not sure which (if you read the forums you'll see some discussion regarding this).
As a result, Andrew no longer supports it (and says he won't). The version I pointed you to is "the" version in use now by most (supported by Cuda). I have it working on a 1.3.7 cart just fine.
New Zenner
I had the good folks over at OpenSourceHosting install this for me, and it shows up in Admin just fine. I entered my account number and everything, but Google still says I haven't installed the Analytics code. When I go to my page and view the source, I don't find any of the google code. Is there something else I need to do?
Totally Zenned
antieuclid:
I had the good folks over at OpenSourceHosting install this for me, and it shows up in Admin just fine. I entered my account number and everything, but Google still says I haven't installed the Analytics code. When I go to my page and view the source, I don't find any of the Google code. Is there something else I need to do?
Are you SURE they installed it correctly? There are a few items that need to be installed, and just because it is showing up in the Admin OK doesn't mean they got it all.
Make sure they made the proper adjustments to the tpl_main_page.php file etc... (and if you are using a custom template, those adjustments need to go in THAT template section. Not the classic or default one).
Totally Zenned
econcepts:
As I have gathered from reading the forums, a version was started by Andrew sometime ago I believe. It was taken over by Cuda somewhere along the line, or he created his own version, not sure which (if you read the forums you'll see some discussion regarding this).
As a result, Andrew no longer supports it (and says he won't). The version I pointed you to is "the" version in use now by most (supported by Cuda). I have it working on a 1.3.7 cart just fine.
This is not correct. This thread is in support of Andrew's version. Cuda copied Andrew's code and released it with a minor change as another version and which is supported in another thread. I do not believe Andrew has stated he would quit developing or supporting his mod version. And not sure how the numbers were generated to make the statement that Cuda's version is used by most? If you wish to learn about or discuss Cuda's version please do that in the other thread.
I use Andrew's version with Zen Cart 1.37 and it works just fine.
Woody
Totally Zenned
a_berezin:
If you "directly inserting the google tracking script code" in template/common/tpl_footer.php:
- You can't use page names in Google Analytics (you can use only title for a name of page if you add some code to tracking script);
- You should add in a tracking script ssl checking;
- You can't track e-commerce transactions;
econcepts:
Actually, you can track all of the following by inserting code (into two different files) into the tpl_footer.php file AND /includes/modules/pages/checkout_success/header_php.php
econcepts-
So the code patch you posted will track PayPal ecommerce transactions/conversions? How does that work if customer does not always wait to be redirected to the Zen Cart checkout_success page after making payment on PayPal site or when proper redirection does not occur?
Woody
Totally Zenned
Woodymon:
This is not correct. This thread is in support of Andrew's version. Cuda copied Andrew's code and released it with a minor change as another version and which is supported in another thread. I do not believe Andrew has stated he would quit developing or supporting his mod version. And not sure how the numbers were generated to make the statement that Cuda's version is used by most? If you wish to learn about or discuss Cuda's version please do that in the other thread.
I use Andrew's version with Zen Cart 1.37 and it works just fine.
Woody
Thanks for the Insight Woody. I read a post between you and Andrew that I could have sworn said he was not supporting it (he must have been talking about the other version).
I just read this about 2 weeks ago. Thanks for the clarification.
Totally Zenned
Woodymon:
econcepts-
So the code patch you posted will track PayPal ecommerce transactions/conversions? How does that work if customer does not always wait to be redirected to the Zen Cart checkout_success page after making payment on PayPal site or when proper redirection does not occur?
Woody
This isn't exactly a "code patch". The code I posted was code I always used before there was ever a plug-in version.
I track with it: Conversion, Analytics, Ecommerce, and Goals.
For PayPal, the only time you can ever track a conversion is if the user actually "clicks" that darned button at the end of their PayPal experience. Also keep in mind, that in order to track conversions, they must have first come from a Paid Search ad (which is the only thing "Conversions" track).
So, to answer it in short, the code I have there to track conversion will track PayPal sales if:
Does that answer your question?
Totally Zenned
Woodymon:
econcepts-
So the code patch you posted will track PayPal ecommerce transactions/conversions? How does that work if customer does not always wait to be redirected to the Zen Cart checkout_success page after making payment on PayPal site or when proper redirection does not occur?
Woody
Woody,
I thought I post my experience with Google Analytics here and hopefully this is not off topic.
I am using the Google Analytics instruction located here: http://www.zen-cart.com/forum/showthread.php?t=25233&highlight=google+analytics&page=4
However, I am using the optimized code posted on previous page of the link above which is post #30.
My Google Ecommerce data collects data about every single sales that terminated at checkout_success page. This is contrary to the post that said on sales from PPC are tracked. In fact the only sale that is not tracked right now are the ones where our customers use Google Checkout. Google provided instruction on how to do this but you know I am not savvy enough to do it :) Also, I am not sure if it's a feature with Paypal Express Checkout or what, but every single sale we've had since implementing Paypal Express Checkout is tracked by google analytics which means they all returned back to checkout_success. Perhaps that's an automatic process.
I have not update to Andrew's or eConcept's version yet. I will read up on it to see if there are added benefit to upgrading to either version.
Isaac.
Totally Zenned
Trying to keep this as basic as possible so I can understand...
When we refer to PayPal , we need to be specific as to which PayPal payment module/process:
So as I understand Isaac reported Google Analytics is properly recording the Zen Cart based transaction when payment is made through PPEC, but not with IPN module.
Are there any solutions available for Zen Cart merchants to track IPN based communications?
And with the latest ZC PayPal IPN module now supporting PDT (Payment Data Transfer) are there solutions available for those types of communications?
Woody
Totally Zenned
Woodymon:
So as I understand Isaac reported Google Analytics is properly recording the Zen Cart based transaction when payment is made through PPEC, but not with IPN module.
Woody,
Actually, mine works flawlessly with both IPN and PPEC is just that we don't offer IPN on our website anymore so I didn't want to make a comment that it works for us since I haven't use IPN for about 2 months now. It's my understanding that the limitation of sales not being recorded if the customer did not return to checkout_success has been removed in 1.3.7 implementation of IPN. I could be wrong about this but that's my understanding.
To be clear, the version of the google analytics I am using support tracking all data including all sales generated EXCEPT for when the customer uses Google Checkout (it doesn't record the sale nor does it track it in Google Adwords as a conversion). This is not a technical problem, I just don't know how to integrate the code on the login page and shopping cart which is where they need to be for Google Checkout to function right.
Isaac.
Fields marked required must be completed.
Tell staff why this post should be reviewed.