Forum Moderators: buckworks & skibum

Message Too Old, No Replies

Tracking code

What is the proper syntax for inserting PHP dynamic variable?

         

dave741

9:53 am on Apr 6, 2005 (gmt 0)

10+ Year Member



Google Conversion Tracking Guide recommends this for inserting PHP dynamic variable this:

<!-- Google Code for Purchase Conversion Page -->
<script language="JavaScript" type="text/javascript">
<!--
var google_conversion_id = 1234567890;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "666666";
if (<? echo $totalValue?>) {
var google_conversion_value = <? echo $totalValue?>
}

var google_conversion_label = "Purchase";
//-->
</script>
<script language="JavaScript"
src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0
src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=<? echo
$totalValue?>&label=Purchase&script=0">
</noscript>

Let's say that
$totalValue = 5689

It means that you receive this:

if (5689) {
var google_conversion_value = 5689}

I do not think that this part of code makes sense. What is the proper syntax for inserting PHP dynamic variable?

Jack_Hughes

3:22 pm on Apr 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



semi-colons?

<? echo $totalValue;?>

I am certainly no expert in php.

inasisi

3:44 pm on Apr 6, 2005 (gmt 0)

10+ Year Member




if (<? echo $totalValue?>wink {
var google_conversion_value = <? echo $totalValue?>
}

You're having Javascript to do the if condition. Instead have php to do the if condition as follows

<?if ($totalValue ){
echo "var google_conversion_value = $totalValue";
}?>

With this code you would get "var google_conversion_value = 5689" if the totalValue is some number other than 0. Otherwise nothing get's output.

dave741

3:58 pm on Apr 6, 2005 (gmt 0)

10+ Year Member



upps

This
if (<? echo $totalValue?>) {
var google_conversion_value = <? echo $totalValue?>
}

causing this

if (5689) {
var google_conversion_value = 5689}

seems to work - I can see 5689 in my reports.

I have also noticed that the default settings (without using PHP variable) is this:

if (1) {
var google_conversion_value = 1;
}