PDA

View Full Version : google conversion script at the end of complete.tpl instead in if



thomask
01-29-10, 01:36 PM
Welcome.

We use web20cart as order template and we use google adwords. We have google conversion script at the end of the complete.tpl file but there's small problem with amount of order.

/ We'd like to use conversion when pro-forma invoice is generated, not when client makes payment so we don't want to have this code between {ifpad} at the middle of complete.tpl file /

Our complete.tpl file looks like this: (in this case conversion works correct with stable value=1)



<link rel="stylesheet" type="text/css" href="templates/orderforms/web20cart/style.css" />
<h2>{$LANG.orderconfirmation}</h2>
<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">Faktura pro forma {$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>

{literal}
<!-- Google Code for Zakup Conversion Page -->
<script type="text/javascript">
<!--
var google_conversion_id = XXXXXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "XXXXXXXXXXXXXX";
var google_conversion_value = 1;
//-->
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
{/literal}


The problem is when we'd like to use variable $amount, whole script just doesn't work.
We tried with {php}{/php} {html}{/html} where the var $amount is, nothing helps.
Any idea how to solve this problem?



<link rel="stylesheet" type="text/css" href="templates/orderforms/web20cart/style.css" />
<h2>{$LANG.orderconfirmation}</h2>
<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">Faktura pro forma {$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>

{literal}
<!-- Google Code for Zakup Conversion Page -->
<script type="text/javascript">
<!--
var google_conversion_id = XXXXXXXX;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "XXXXXXXXXXX";
var google_conversion_value = 1;
if $amount {
google_conversion_value = {$amount};
}
//-->
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt=""
src="http://www.googleadservices.com/pagead/conversion/XXXXXXXXXXX/?value={$amount}&amp;label=XXXXXXXXXXXX&amp;guid=ON&amp;script =0"/>
</div>
</noscript>
{/literal}

kmm2908
05-01-10, 03:09 AM
Hi thomask

I'm in early days with whmcs but my coding experience tells me that your reference to $amount in the middle of the JavaScript is not going to work. JavaScript code referencing php variable?


if $amount {
google_conversion_value = {$amount};
}

Something like this was suggested by Matt:


{php}
$orderid = $this->get_template_vars('orderid');
$result = select_query("tblorders","amount",array("id"=>$orderid));
$data = mysql_fetch_array($result);
$amount = $data["amount"];
$this->assign('amount',$amount);
{/php}


This will get the order value from the database then you can reference amount in your JavaScript code.

Or use php inside {php} tags to reference the php variable $amount.

Matt's code referenced from thread here:
http://forum.whmcs.com/showthread.php?t=9002&highlight=analytics thread #14

Hope this helps :)

kmm2908
05-01-10, 03:19 AM
or maybe you were trying to reference the smarty/template variable, not php, sorry. :oops:

I think then you need to come out of {literal} tag for the variable reference to work. Something like this:


if ({/literal}$amount{literal}) {
google_conversion_value = {/literal}$amount{literal};
}

Maybe someone with more whmcs experience can confirm this for us both? :)

kmm2908
05-01-10, 03:20 AM
Also found this helped thomask:
http://wiki.whmcs.com/Template_Syntax