Jump to content

Google Analytics Conversion Tracking


datex

Recommended Posts

Heres the exact code I have at the end of complete.tpl:

 


{php}
$orderid = $this->get_template_vars('orderid');
$userid = $_SESSION["uid"];

$result = select_query("tblclients","city, state, country",array("id"=>$userid));
$data = mysql_fetch_array($result);
$city = $data["city"];
$state = $data["state"];
$country = $data["country"];
$this->assign('city',$city);
$this->assign('state',$state);
$this->assign('country',$country);

$result = select_query("tblhosting","packageid",array("orderid"=>$orderid));
$data = mysql_fetch_array($result);
$packageid = $data["packageid"];
$result = select_query("tblproducts","name, type",array("id"=>$packageid));
$data = mysql_fetch_array($result);
$name = $data["name"];
$type = $data["type"];
$this->assign('name',$name);
$this->assign('type',$type);
$this->assign('packageid',$packageid);
{/php}

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'XX-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'MYDOMAINNAME.COM']);
_gaq.push(['_trackPageview']);
_gaq.push(["_addTrans",
               "{$orderid}",
               "",

               "{$amount}",
               "0",
               "0",
               "{$city}",
               "{$state}",
               "{$country}"
]);
_gaq.push(["_addItem",
               "{$orderid}",
               "{$packageid}",
               "{$name}",
               "{$type}",
               "{$amount}",
               "1"
]);
_gaq.push(['_trackTrans']);
{literal}
(function() {
   var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
   ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
   var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
{/literal}
</script>

 

EDIT: attached a screenshot of our GA ecommerce overview showing that it is working.

GA.jpg

Edited by laszlof
Link to comment
Share on other sites

I have tried implementing the above code in complete.tpl

 

<link rel="stylesheet" type="text/css" href="templates/orderforms/cart/style.css" />

<p align="center" class="cartheading">{$LANG.orderconfirmation}</p>

<p>{$LANG.orderreceived}</p>

<div class="cartbox">

<p align="center"><strong>{$LANG.ordernumberis} {$ordernumber}</strong></p>

</div>

<p>{$LANG.orderfinalinstructions}</p>

{if $invoiceid && !$ispaid}

<div class="errorbox">{$LANG.ordercompletebutnotpaid}</div>

<p align="center"><a href="viewinvoice.php?id={$invoiceid}" target="_blank">{$LANG.invoicenumber}{$invoiceid}</a></p>

{/if}

{if $ispaid}

<!-- Enter any HTML code which needs to be displayed once a user has completed the checkout of their order here - for example conversion tracking and affiliate tracking scripts -->

{/if}

<p align="center"><a href="clientarea.php">{$LANG.ordergotoclientarea}</a></p>

{php}

$orderid = $this->get_template_vars('orderid');

$userid = $_SESSION["uid"];

$result = select_query("tblclients","city, state, country",array("id"=>$userid));

$data = mysql_fetch_array($result);

$city = $data["city"];

$state = $data["state"];

$country = $data["country"];

$this->assign('city',$city);

$this->assign('state',$state);

$this->assign('country',$country);

$result = select_query("tblhosting","packageid",array("orderid"=>$orderid));

$data = mysql_fetch_array($result);

$packageid = $data["packageid"];

$result = select_query("tblproducts","name, type",array("id"=>$packageid));

$data = mysql_fetch_array($result);

$name = $data["name"];

$type = $data["type"];

$this->assign('name',$name);

$this->assign('type',$type);

$this->assign('packageid',$packageid);

{/php}

<script type="text/javascript">

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);

_gaq.push(['_setDomainName', MyOwnDomainName.eu]);

_gaq.push(['_trackPageview']);

_gaq.push(["_addTrans",

"{$orderid}",

"",

"{$amount}",

"0",

"0",

"{$city}",

"{$state}",

"{$country}"

]);

_gaq.push(["_addItem",

"{$orderid}",

"{$packageid}",

"{$name}",

"{$type}",

"{$amount}",

"1"

]);

_gaq.push(['_trackTrans']);

{literal}

(function() {

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

})();

{/literal}

</script>

 

The only code I am able to find at the source for: https://www.myowndomain.eu/service/cart.php?a=complete is the below from the footer - should I not be able to se more?

 

<scripttype="text/javascript">

 

 

var _gaq = _gaq || [];

 

_gaq.push(['_setAccount', 'UA-XXXXXXXX-X]);

 

 

_gaq.push(['_trackPageview']);

 

 

(function() {

 

 

var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

 

 

ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

 

 

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

 

})();

 

 

 

</script>

Link to comment
Share on other sites

Are you sure you're editing the correct complete.tpl that goes with your selected orderform template?

 

I was thinking about the same. In the backend I have checked "Cart" - and I'm editing \templates\orderforms\cart\complete.tpl

 

But should I not be able to see some of the code in the page when I'm checking out?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated