VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Questions VM 1.1 ( the only active board for the old version) => Topic started by: Gary on September 08, 2008, 15:06:02 pm

Title: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Gary on September 08, 2008, 15:06:02 pm
I am not finding this information anywhere?

I need some way of tracking which sales are coming from our PPC efforts....

Any suggestions?

Thanks

Gary
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Gary on September 20, 2008, 21:04:45 pm
I need to set up conversion tracking and would REALLY appreciate it if someone could suggest a method that WORKS as we have already wasted a couple of hundred pounds on Adwords and NEED to find out whats going on!!!

Thanks

Gary
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on September 21, 2008, 10:52:40 am
From Joomla! website:
http://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,1233/Itemid,35/
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Gary on September 25, 2008, 12:29:22 pm
I am really fed up with Virtuemart now. The forum is practically dead.

I understand the whole community thing, but when you put days, weeks and months into something and then hit a hurdle that you cant overcome, its really annoying :(

I have a company managing our adwords campaigns, its costing us money, yet we cant track what sales comes through adwords.

Is there a way to track CONVERSIONS that ACTUALLY works???

Thanks to anyone that bothers to reply.....

Gary
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Michelle on September 25, 2008, 19:16:32 pm
Gary:
I am with you on the pain of tracking Google Adwords to sales - I myself stopped and found other ways to drive sales.  I spent almost $5000 on Google adword campaigns over a 8 month period - until I realized everytime you do anything they tell you - to increase your spend limit - I also found that people were out there just generating click throughs in order to get their commission. 

I personally would spend your money elsewhere....on banner ads or something else -I learned my lesson on Google Adwords.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on September 26, 2008, 10:43:12 am
Is there a way to track CONVERSIONS that ACTUALLY works???
Simplest way is to add the Google tracking code to the Thanks for ordering template - checkout.thankyou.tpl.php  - then you track sales and not site visits or click fraudsters. Combine this with Google Analitics and you will have more data.

You may not get responses here if those who read your message have no experience of your issue. And all those who have working sites don't visit the forum or look in every couple of months or so.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: samoht on September 29, 2008, 17:12:58 pm
Thanks for this info Kelvyn!
Simplest way is to add the Google tracking code to the Thanks for ordering template - checkout.thankyou.tpl.php  -

I assume that you can put the tracking code anywhere - even though there is no <head> on the template?

Also, this will help Google analyze the sales - but I am still confused about setting up a goal/funnel in GA?
I tried entering chechout.thankyou and checkout.result as goal urls but they did not show up?
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on September 30, 2008, 10:34:52 am
I assume that you can put the tracking code anywhere - even though there is no <head> on the template?
I put the adword tracking code after the line:
Code: [Select]
<?php echo $VM_LANG->_('PHPSHOP_EMAIL_SENDTO') .": <strong>"$user->user_email '</strong>'?><br />
</p>

For analytics I publish the module to the Joomla template so it is run on every page. Have not done much with it as I leave the client to analyse & run their own marketing.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Azzam on October 20, 2008, 14:59:02 pm
Thanks for the update I have added my personal persepective over at the wowjoomla.com blog which you can see here:

http://wowjoomla.com/WowJoomla-News/2008/10/20/virtuemart-joomla-e-commerce-and-google-conversion-tracking.html

I may need to create a plugin that is able to do the purpose mentioned in the post, hopefully others will benefit from it when created.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on October 20, 2008, 16:02:00 pm
There is now a module available for this - Google Analytics 4 Virtuemart (http://joomlaxtc.com/index.php?page=shop.product_details&flypage=flypage_new.tpl&product_id=31&category_id=2&option=com_virtuemart&Itemid=70)
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: machabeus on October 20, 2008, 16:09:22 pm
and it works ok for me :)
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Bob53207 on February 24, 2009, 17:51:19 pm
I assume that you can put the tracking code anywhere - even though there is no <head> on the template?

I did exactly as instructed and my AdWord conversion tracking is still not working.  Any ideas?

stpatricksirisht-shirts.com
J1.5.8 VM 1.1.3
I put the adword tracking code after the line:
Code: [Select]
<?php echo $VM_LANG->_('PHPSHOP_EMAIL_SENDTO') .": <strong>"$user->user_email '</strong>'?><br />
</p>

For analytics I publish the module to the Joomla template so it is run on every page. Have not done much with it as I leave the client to analyse & run their own marketing.

Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: cinos on March 18, 2009, 17:51:06 pm
I was wondering. Where abouts is the page for user registration?

I would quite like to see the conversion rate between people who click on my ads and those that then register with the site.

Don't suppose someone could point out to me where the relevent file is, and where possible, where the code should go?
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: cinos on March 18, 2009, 17:52:45 pm
Basically I would like to the put the code in whatever page displays the thankyou for registering bit. (After they've clicked the link in the sent email)
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on March 19, 2009, 10:49:22 am
Turn on VM debug on the site and you will see which files are involved at each step. It will not be a simple "page".
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: cinos on March 19, 2009, 10:59:44 am
Thanks for the help though.  :)
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: cinos on March 19, 2009, 11:17:52 am
Unfortunately the debug idea did not work.

When I got to the Activation Complete page there was no debug window at the bottom and no information telling me which files were being used for the page.

Thanks anyway, are there any other ways that I can find out?
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on March 23, 2009, 12:08:57 pm
Acivation by email is handled in Joomla's com_user component so that is the area you will need to look at. The "activated" text string is REG_ACTIVATE_COMPLETE which is called by components/com_user/controller.php so maybe the analytics code could be inserted there.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: cinos on March 23, 2009, 14:06:43 pm
Cheers jenkinhill.

I tried putting the code in the obvious places but it seems that the google code just breaks everything in there. Ideally the code needs to be specifically in an area that handles the registration since I obviously don't want to be recording conversions for people who are just logging in.

With just a quick scan of how the code is laid out, it could be that I'm on to a lost cause here.

Thanks anyway though.  ;)
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: bemovi on March 30, 2009, 22:51:40 pm
I'm trying to use the AdWords code in get_final_confirmation.tpl.php
I am redirecting buyers to PayPal so I assumed this would be the best place to insert the code instead of checkout.thankyou.tpl.php
Does this make any sense?
Where should I place the code in get_final_confirmation.tpl.php?
Thanks a bunch
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on March 31, 2009, 00:04:08 am
I'd put the code in the footer/debug position of the J! template and set final_confirmation as a goal in Analytics.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: samparker89 on August 07, 2009, 10:46:49 am
Hi All,

Just adding a piece of info to this forum that i feel may help. I have succesfully added the conversion code to my thankyou page with no problems by using an iframe. I just inserted this code after the closing php tag and it worked:

<iframe src="/google-cpc.htm" width="5" height="5"
frameborder="0" scrolling="no" name="Google"></iframe>

Obviously you will need to create a page with your google code in and link to it through iframe. I think inserting this iframe on any page would work.

I am just a beginner so if what i am saying is wrong then please feel free to tell me!

Cheers
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Jason Farmer on March 12, 2010, 11:57:18 am
I believe that whatever you do here will be a fudge and will be inaccurate unless you are taking payments on your site yourself.

Google Analytics needs to be in a page that is displayed to the customer (so the js can read the clients cookie etc) so using paypal ipn is a non starter.

Using paypal, sagepay forms etc , or cheques where customers are leaving your site to pay on another.

You have the choice of either

paypal return page is set in Virtuemart...Store...List payment methods...Paypal ... Configuration... extra payment info. mine is
Code: [Select]
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"),edit: I'll come back to this as I work it out... :)

the relevant php file is found at /administrator/components/com_virtuemart/html/checkout.result.php

It already does a job in verifying that the order_id is valid and that the status is confirmed or pending(!) and says thankyou if all is kosher.

Paypal gives some sample PDT code that can be used here (https://www.paypal.com/us/cgi-bin/webscr?cmd=p/xcl/rec/pdt-code)...
Code: [Select]
<?php
// read the post from PayPal system and add 'cmd'
$req 'cmd=_notify-synch';

$tx_token $_GET['tx'];
$auth_token "GX_sTf5bW3wxRfFEbgofs88nQxvMQ7nsI8m21rzNESnl_79ccFTWj2aPgQ0";
$req .= "&tx=$tx_token&at=$auth_token";

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " strlen($req) . "\r\n\r\n";
$fp fsockopen ('www.paypal.com'80$errno$errstr30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp$header $req);
// read the body data
$res '';
$headerdone false;
while (!
feof($fp)) {
$line fgets ($fp1024);
if (
strcmp($line"\r\n") == 0) {
// read the header
$headerdone true;
}
else if (
$headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines explode("\n"$res);
$keyarray = array();
if (
strcmp ($lines[0], "SUCCESS") == 0) {
for (
$i=1$i<count($lines);$i++){
list(
$key,$val) = explode("="$lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$firstname $keyarray['first_name'];
$lastname $keyarray['last_name'];
$itemname $keyarray['item_name'];
$amount $keyarray['payment_gross'];

echo (
"<p><h3>Thank you for your purchase!</h3></p>");

echo (
"<b>Payment Details</b><br>\n");
echo (
"<li>Name: $firstname $lastname</li>\n");
echo (
"<li>Item: $itemname</li>\n");
echo (
"<li>Amount: $amount</li>\n");
echo (
"");
}
else if (
strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}

}

fclose ($fp);

?>


Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br> You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>

google analytics gives this code for tracking transactions...
Code: [Select]
<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">
try{
  var pageTracker = _gat._getTracker("UA-xxxxx-x");
  pageTracker._trackPageview();
  pageTracker._addTrans(
      "1234", // order ID - required
      "Womens Apparel", // affiliation or store name
      "11.99", // total - required
      "1.29", // tax
      "15.00", // shipping
      "San Jose", // city
      "California", // state or province
      "USA" // country
    );
 

   // add item might be called for every item in the shopping cart
   // where your ecommerce engine loops through each item in the cart and
   // prints out _addItem for each
   pageTracker._addItem(
      "1234", // order ID - necessary to associate item with transaction
      "DD44", // SKU/code - required
      "T-Shirt", // product name
      "Olive Medium", // category or variation
      "11.99", // unit price - required
      "1" // quantity - required
   );

   pageTracker._trackTrans(); //submits transaction to the Analytics servers
} catch(err) {}
</script>





Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Jason Farmer on March 20, 2010, 23:25:56 pm

This requires a new checkout.result.php (just about rewritten) in .../administrator/components/com_virtuemart/html
Code: [Select]
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
* PayPal IPN Result Checker
*
* @version $Id: checkout.result.php 1394 2008-05-04 19:05:15Z soeren_nb $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
mm_showMyFileName__FILE__ );
global 
$db$vmLogger$VM_LANG;

function 
preg ($m) {
return '/{'.$m.'}/ix';
}
$valid=true;

if( !isset( 
$_REQUEST["order_id"] ) || empty( $_REQUEST["order_id"] )) {
echo $VM_LANG->_('VM_CHECKOUT_ORDERIDNOTSET');
$valid=false;
} else
{

// order_id is set - this is a paypal transaction...
// validate the order_id...
include( CLASSPATH"payment/ps_paypal.cfg.php" );
$values=array();
$values['order_id']= intvalvmGet$_REQUEST"order_id" ));
$values['user_id']=$auth["user_id"];

$sql =<<<HEREDOC
SELECT order_status,order_total,order_currency 
FROM #__{vm}_orders 
WHERE #__{vm}_orders.user_id={user_id}
AND #__{vm}_orders.order_id={order_id}
HEREDOC;

$sql=preg_replace(array_map("preg",array_keys($values)),array_map("mysql_escape_string",$values),$sql);
$db->query($sql);

if ($db->next_record()){
$values['order_status'] = $db->f("order_status");
if($values['order_status'] == PAYPAL_VERIFIED_STATUS || $values['order_status'] == PAYPAL_PENDING_STATUS) {
printf('         <img src="%simages/button_ok.png" align="middle" alt="%s" border="0" />',
VM_THEMEURL,$VM_LANG->_('VM_CHECKOUT_SUCCESS'));
printf(' <h2>%s</h2>',$VM_LANG->_('PHPSHOP_PAYPAL_THANKYOU'));

// echo('<pre> $_GET <br/>');
// print_r($_GET);
// echo("</pre>");


// check we've got PDT switched on...
if( !isset( $_GET['tx'] ) || empty( $_GET['tx'] )) {
//PDT is not switched on...
//Are we expecting it to be on?
if(PAYPAL_PDT_AUTH!=""){$vmLogger->err("Paypal Data Transfer unavailable.",false);$valid=false;}
} else
{
// PDT is switched on...
// read the post from PayPal system and add 'cmd'
$req 'cmd=_notify-synch';
$tx_token vmGet($_GET,'tx');

$req .= "&tx=$tx_token&at=".PAYPAL_PDT_AUTH;

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " strlen($req) . "\r\n\r\n";
$fp fsockopen (PAYPAL_URL80$errno$errstr30);
// If possible, securely post back to paypal using HTTPS
// Your PHP server will need to be SSL enabled
// $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
$vmLogger->err("Paypal Data Transfer Http error.",false);
$valid=false;
// HTTP ERROR
} else {
fputs ($fp$header $req);
// read the body data
$res '';
$headerdone false;
while (!feof($fp)) {
$line fgets ($fp1024);
if (strcmp($line"\r\n") == 0) {
// read the header
$headerdone true;
}
else if ($headerdone)
{
// header has been read. now read the contents
$res .= $line;
}
}

// parse the data
$lines explode("\n"$res);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1$i<count($lines);$i++){
list($key,$val) = explode("="$lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// echo('<pre> $keyarray <br/>');
// print_r($keyarray);
// echo("</pre>");

$fraud_state=false;
if (PAYPAL_EMAIL!=$keyarray['receiver_email']){$fraud_state=true;$vmLogger->err("Fraud? receiver_email corrupt : ".$values['txn_id']);}
if ($db->f("order_total")!=$keyarray['mc_gross']){$fraud_state=true;$vmLogger->err("Fraud? payment_amount corrupt : ".$values['txn_id']." ".$db->f("order_total")." != ".$keyarray['mc_gross']);}
if ($db->f("order_currency")!=$keyarray['mc_currency']){$fraud_state=true;$vmLogger->err("Fraud? payment_currency corrupt : ".$values['txn_id']." ".$db->f("order_currency")." != ".$keyarray['mc_currency']);}



//bung this lot into the database....
## 
## Table structure for table `#__{vm}_paypal`
## 

$db->query"CREATE TABLE IF NOT EXISTS `#__{vm}_paypal` (
  type char(3) NOT NULL,
txn_id char(20) NOT NULL,
txn_type char(39),
    created_date timestamp,
    payment_date timestamp,
    user_id int(11),
order_id int(11),
order_status char(1),
payment_status char(50),
mc_gross decimal(10,2),
mc_fee decimal(10,2),
    mc_currency char(3),
    tax decimal(10,2),
    shipping decimal(10,2),
    handling_amount decimal(10,2),
    payment_type char(30),
    payer_email char(127),
    protection_eligibility char(20),
    payer_status char(20),
    first_name char(64),
    last_name char(64),
    address_name char(128),
    address_status char(10),
    address_street char(200),
    address_city char(40),
    address_state char(40),
    address_zip char(20),
    address_country char(64),
    address_country_code char(2),
    payer_business_name char(127),
    pending_reason char(64),
    transaction_subject char(64),
    item_name char(64),
    item_number char(64),
    quantity int(11),
    residence_country char(64),
    business char(64),
    receiver_email char(127),
    receiver_id char(64),
    payer_id char(64),
    invoice char(64),
    charset char(64),
    custom char(64),
    payment_gross int(11),
    payment_fee int(11),

  PRIMARY KEY  (`txn_id`,created_date),
  KEY `idx_paypal_txn_id` (`txn_id`),
  KEY `idx_paypal_order_id` (`order_id`)
) TYPE=MyISAM COMMENT='Paypal transactions are stored here'; "
);

$sql_insert=<<<HEREDOC
INSERT INTO `#__{vm}_paypal`
(`type`,
`txn_id`,
`txn_type`,
`created_date`,
`payment_date`,
`user_id`,
`order_id`,
`order_status`,
`payment_status`,
`mc_gross`,
`mc_fee`,
`mc_currency`,
`tax`,
`shipping`,
`handling_amount`,
`payment_type`,
`payer_email`,
`protection_eligibility`,
`payer_status`,
`first_name`,
`last_name`,
`address_name`,
`address_status`,
`address_street`,
`address_city`,
`address_state`,
`address_zip`,
`address_country`,
`address_country_code`,
`payer_business_name`,
`pending_reason`,
`transaction_subject`,
`item_name`,
`item_number`,
`quantity`,
`residence_country`,
`business`,
`receiver_email`,
`receiver_id`,
`payer_id`,
`invoice`,
`charset`,
`custom`,
`payment_gross`,
`payment_fee`)
VALUES
(
"{type}",
"{txn_id}",
"{txn_type}",
current_timestamp,
"{payment_date}",
"{user_id}",
"{order_id}",
"{order_status}",
"{payment_status}",
"{mc_gross}",
"{mc_fee}",
"{mc_currency}",
"{tax}",
"{shipping}",
"{handling_amount}",
"{payment_type}",
"{payer_email}",
"{protection_eligibility}",
"{payer_status}",
"{first_name}",
"{last_name}",
"{address_name}",
"{address_status}",
"{address_street}",
"{address_city}",
"{address_state}",
"{address_zip}",
"{address_country}",
"{address_country_code}",
"{payer_business_name}",
"{pending_reason}",
"{transaction_subject}",
"{item_name}",
"{item_number}",
"{quantity}",
"{residence_country}",
"{business}",
"{receiver_email}",
"{receiver_id}",
"{payer_id}",
"{invoice}",
"{charset}",
"{custom}",
"{payment_gross}",
"{payment_fee}"
);
HEREDOC;

$sql_check=<<<HEREDOC
SELECT count(*) as check_count from #__{vm}_paypal 
WHERE type="PDT" AND txn_id ="{txn_id}";
HEREDOC;


$values=array_merge($values,$keyarray);
$values['payment_date']=strtotime($values['payment_date']);
$values['type']="PDT";
$sql=preg_replace(array_map("preg",array_keys($values)),array_map("mysql_escape_string",$values),$sql_insert);
$db->query($sql);

$sql=preg_replace(array_map("preg",array_keys($values)),array_map("mysql_escape_string",$values),$sql_check);
$db->query($sql);
$db->next_record();
if(intval($db->f("check_count"))<>1){
$fraud_state=true;
$vmLogger->err("Fraud? Same txn_id as a previous PDT transaction : ".$values['txn_id']);
}

if ($keyarray['payment_status']=="Completed"||$keyarray['payment_status']=="Pending"){
// Pending could be an echeck or any delayed transaction -- but this is our one chance to report it to google...
if ($fraud_state){
$valid=false;
}else{
// there is no need to update the order_status here as the IPN notify script will do that asynchronously and more reliably...
require_once( CLASSPATH"ps_google.php" );
ps_google::process_conversion$values['order_id'] );

}
}else{
$valid=false;
}
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
$vmLogger->err("PDT FAIL ".join("\r\n",$lines),false);
$valid=false;
}else {
$vmLogger->err("PDT unrecognised return ".join("\r\n",$lines),false);
$valid=false;
}
}
}
fclose ($fp);



} else {
$vmLogger->err("Paypal PDT not checked as Order Status corrupt? :".$db->f("order_status"),false);
$valid=false;
printf('         <img src="%simages/button_cancel.png" align="middle" alt="%s" border="0" />',
VM_THEMEURL,$VM_LANG->_('VM_CHECKOUT_FAILURE'));
printf(' <h2>%s</h2>',$VM_LANG->_('PHPSHOP_PAYPAL_ERROR'));
}

printf('<br /><p><a href="index.php?option=com_virtuemart&page=account.order_details&order_id=%s">%s</a></p>',
$values['order_id'], $VM_LANG->_('PHPSHOP_ORDER_LINK'));
} else {
$vmLogger->err("Order not found :"$values['order_id']. " for user ".$values["user_id"] . " ",false);
echo $VM_LANG->_('VM_CHECKOUT_ORDERNOTFOUND') . '!';
$valid=false;
}

If($valid){
$firstname $keyarray['first_name'];
$lastname $keyarray['last_name'];
$itemname $keyarray['item_name'];
$amount $keyarray['mc_gross'];

echo ("<h3>Thank you for your purchase!</h3>\n");

echo ("<b>Payment Details</b><br>\n");
echo ("<ul><li>Name: $firstname $lastname</li>\n");
echo ("<li>Item: $itemname</li>\n");
echo ("<li>Amount: $amount</li></ul>\n");
echo ("");
echo "Your transaction has been completed, and a receipt for your purchase has been emailed to you.<br>";

}

echo "You may log into your account at <a href='https://www.paypal.com'>www.paypal.com</a> to view details of this transaction.<br>";
}
?>

which uses a new ps_google.php and ps_google.cfg.php and some new values in ps_paypal.cfg.php

new values in ps_paypal.cfg.php in .../administrator/components/com_virtuemart/classes/payment
Code: [Select]
define ('PAYPAL_URL', 'www.paypal.com'); // just to make it easier switching in and out of the sandbox...
// this token is available from Profile - Website Payment Preferences
define ('PAYPAL_PDT_AUTH',"5KK_UpU_qwertyuiopgfghjkfghjkjke_etc");


ps_google.cfg.php in .../administrator/components/com_virtuemart/classes
Code: [Select]
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 

define ('GOOGLE_ID''UA-123456-1');

?>

ps_google.php in .../administrator/components/com_virtuemart/classes
Code: [Select]
<?php
if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
* Post conversion to google using ga.js
*
* @version $Id: ps_google.php 1394 2008-05-04 19:05:15Z soeren_nb $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/

class ps_google {
function preg ($m) {return '/{'.$m.'}/ix';}
    function process_conversion($order_id) {
        global 
$VM_LANG$vmLogger;
        
/* init the database */
        
$google_db =& new ps_DB;
        include(
CLASSPATH."ps_google.cfg.php");
        
        
$valid true;
       
$google_order=<<<HEREDOC
       
       <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">
try{
  var pageTracker = _gat._getTracker("{GOOGLE_ID}");
  
  pageTracker._addTrans(
      "{order_id}", // order ID - required
      "{vendor_name}", // affiliation or store name
      "{order_total}", // total - required
      "{order_tax}", // tax
      "{order_shipping}", // shipping
      "{city}", // city
      "{state}", // state or province
      "{country}" // country
    );
 
{google_lines}



   pageTracker._trackTrans(); //submits transaction to the Analytics servers
} catch(err) {}
</script>
HEREDOC;
$google_lines=array();
   
// add item might be called for every item in the shopping cart
   // where your ecommerce engine loops through each item in the cart and
   // prints out _addItem for each 

   
$google_line=<<<HEREDOC

   pageTracker._addItem(
      "{order_id}", // order ID - necessary to associate item with transaction
      "{order_item_sku}", // SKU/code - required
      "{order_item_name}", // product name
      "{product_attribute}", // category or variation
      "{product_item_price}", // unit price - required
      "{product_quantity}" // quantity - required
   );
HEREDOC;


        
$sql_order =<<<HEREDOC
SELECT o.order_total,
o.order_tax,
o.order_shipping,
u.city,
u.state,
u.country,
(select vendor_name from #__{vm}_vendor v where v.vendor_id=o.vendor_id LIMIT 1) as vendor_name
FROM #__{vm}_orders o
LEFT OUTER JOIN  #__{vm}_order_user_info u
ON o.order_id=u.order_id
WHERE o.order_id="{order_id}";
HEREDOC;

           
$sql_lines =<<<HEREDOC
     SELECT
`#__{vm}_order_item`.`order_item_sku`,
`#__{vm}_order_item`.`order_item_name`,
`#__{vm}_order_item`.`product_quantity`,
`#__{vm}_order_item`.`product_item_price`,
`#__{vm}_order_item`.`product_attribute`
FROM `#__{vm}_order_item`
WHERE `#__{vm}_order_item`.`order_id` ="{order_id}"
ORDER BY `#__{vm}_order_item`.`order_item_id`;
HEREDOC;


        
$values=array();
        
$values['GOOGLE_ID']=GOOGLE_ID;
        
$values['order_id']=$order_id;
        
$config=$values;
        
$sql=preg_replace(array_map(array("ps_google","preg"),array_keys($values)),array_map("mysql_escape_string",$values),$sql_order);
$google_db->query($sql);
        if (!
$google_db->next_record()) {
$vmLogger->err"ORDER NOT FOUND :".$order_id );
$valid=false;
        }else{
        
$values=array_merge($values,(array) $google_db->getCurrentRow());
        

        
$google_order=preg_replace(array_map(array("ps_google","preg"),array_keys($values)),$values,$google_order);
        

        
$sql=preg_replace(array_map(array("ps_google","preg"),array_keys($values)),array_map("mysql_escape_string",$values),$sql_lines);
        
$google_db->query($sql);
        
while ($google_db->next_record()){
        
$values=array_merge($config,(array) $google_db->getCurrentRow());
        
$google_lines[]=preg_replace(array_map(array("ps_google","preg"),array_keys($values)),array_map("mysql_escape_string",$values),$google_line);
        
}
        

        
$values=$config;
        
$values['google_lines']=join("\r\n",$google_lines);
        
$google_order=preg_replace(array_map(array("ps_google","preg"),array_keys($values)),$values,$google_order);
        
echo $google_order;
        }
        return 
$valid;   
    }
}
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Camiband on May 30, 2010, 17:59:09 pm
Could someone provde the step by step instructions needed to access the checkout.thankyou.tpl.php mentioned below:

Simplest way is to add the Google tracking code to the Thanks for ordering template - checkout.thankyou.tpl.php  - then you track sales and not site visits or click fraudsters.

Thanks.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on May 30, 2010, 18:47:27 pm
Could someone provde the step by step instructions needed to access the checkout.thankyou.tpl.php mentioned

Use FTP - the template is at
/components/com_virtuemart/themes/default/templates/pages/checkout.thankyou.tpl.php

download it, make a copy (for backup), edit the original using a good plain text editor & upload the new version with FTP.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Camiband on June 01, 2010, 22:14:44 pm
Looks simple enough, except that I haven't used FTP before.  Is there free FTP software that I can download or is FTP part of Joomla/Virtuemart?  You assistance is appreciated.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on June 02, 2010, 18:22:34 pm
If you have never used FTP then how have you installed security updates? All Joomla versions before 1.5.18 have known security issues.

A good open source FTP client is at http://filezilla-project.org/
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Camiband on June 11, 2010, 17:08:14 pm
My wife set up our site about 7 months ago through someone who provided little support.  The version we uses is OurJoomla! 1.5.10 Production/Stable.  Do I have a problem?

I've kind of come her web person by accident.  I do have FTP installed now  and I was about to follow your instructions regarding the  page: /components/com_virtuemart/themes/default/templates/pages/checkout.thankyou.tpl.php .  However I need further clarification.  Is this the "submit order" page or a Thank you page that Paypal checkout sends a customer back to after payment.  I noticed that this  option in Paypal is not clicked and when I put through a test order I was not redirected to a "Thank You" page on my site.  First things first I guess...how do I set up the Thank you page in Virtuemart.  thanks for your help, I realize these are very basic questions.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on June 11, 2010, 17:47:56 pm
First upgrade Joomla ASAP. All versions before 1.5.18 have security issues and many have been hacked.

If you are really a beginner in all this then rather than edit the files you could simply install a module for use with Analytics.

I use Google Analytics 4 Virtuemart (http://www.joomlaxtc.com/index.php?option=com_virtuemart&page=shop.product_details&flypage=flypage_new.tpl&product_id=31&Itemid=70) - it is not expensive, and does the job.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Camiband on June 25, 2010, 15:16:07 pm
jenkinhill,

I am about to create the code to insert into the "checkout.thankyou.tpl.php" page as you suggested.  However, when I create the code Google asks for the "appropriate dynamic variable" (such as Total_Cost).  What is the dynamic variable for the page that will give me the "total order" as indicated on the Virtuemart Purchase Order?  Thanks.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on June 25, 2010, 21:06:47 pm
At a guess you should run VirtueMart in debug mode to display the steps/variables.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Camiband on June 27, 2010, 19:16:14 pm
How do you run Virtuemart in the debug mode?
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: jenkinhill on June 27, 2010, 23:43:45 pm
http://virtuemart.net/documentation/User_Manual/Administrator_Tutorial.html   - bottom of section 4.1.1. Global
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: NeliusH on June 29, 2010, 20:40:21 pm
Hi,

I'm a bit perplexed by the complexity of this all.
The normal google tracking code is so simple to install, why is this e-commerce code so complex.

Isn't there someone how just has a simple snippet of code that work with VM.

I tried putting the google sample code into the extra payment field in payment methods>configuration.

It works and shows in analytics e-commerce tracking, but only gives the values as mentioned in the script.

I know I have to change these values, but don't know the proper ones to work with the VM cart or checkout.

Is there any one that can help me on this one?

best,
Harald

P.S.
This is the Google sample code I pasted into the extra payment field:
Code: [Select]
<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">
try{
  var pageTracker = _gat._getTracker("UA-xxxxx-x");
  pageTracker._trackPageview();
  pageTracker._addTrans(
      "1234",            // order ID - required
      "Womens Apparel",  // affiliation or store name
      "11.99",           // total - required
      "1.29",            // tax
      "15.00",           // shipping
      "San Jose",        // city
      "California",      // state or province
      "USA"              // country
    );
 
 
   // add item might be called for every item in the shopping cart
   // where your ecommerce engine loops through each item in the cart and
   // prints out _addItem for each 
   pageTracker._addItem(
      "1234",           // order ID - necessary to associate item with transaction
      "DD44",           // SKU/code - required
      "T-Shirt",        // product name
      "Olive Medium",   // category or variation
      "11.99",          // unit price - required
      "1"               // quantity - required
   );
 
   pageTracker._trackTrans(); //submits transaction to the Analytics servers
} catch(err) {}
</script>
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: beltoforion on June 29, 2010, 20:57:28 pm
Gary, did you solve the google analytics issue?

Cinos there are two ways you can do this in my understanding.

1. copy the link of your register button and paste it into google analytics tracking.
2. create an thank you for registering article and give that link to google analytics.
Title: Re: Virtuemart conversion tracking with Google Analytics - HOW??
Post by: Camiband on June 30, 2010, 15:18:28 pm
From what I understand, and its not much, the client needs to be automatically returned to the thank you checkout page.  However, I've been told that this is a dynamically created page specific to a clients order. That creates a question: In Paypal you can select the option: "Auto Return for PayPal Payments" which would automatically redirect all customers with a paypal account (not perfect but better than nothing) back to my website and conceivable pick up the ecommerce tracking by Google Does anybody know how I can determine what URL should be inserted for the dynamically created page?  Is it even possible?  If not then what's the point of this whole thread?