Solved

Using PHP inside of Javacript - Google Conversion Tracking

Posted on 2008-10-07
2
182 Views
Last Modified: 2013-12-12
I'm attempting to use a google conversion tool. It requires me to drop some google code into one of my web pages.  

What I want to know is if it is possible or not to use php inside of javascript.

I have something like this.
<!-- Google Code for Purchase Conversion Page -->

<script language="JavaScript" type="text/javascript">

<!--

var google_conversion_id = 9999999999;

var google_conversion_language = "en_US";

var google_conversion_format = "3";

var google_conversion_color = "ffffff";

if (<?=$order_amount;?>) {

  var google_conversion_value = <?=$order_amount;?>;

}

var google_conversion_label = "8zZ1dfa41DmKj-Aw";

//-->

</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/9999999/?value=<?=$order_amount;?>&amp;label=8zZ1CK3431DDmKj-Aw&amp;script=0"/>

</noscript>
 

Each place I put <?=$order_amount;?> is what I'm concerned about.  Will this work?

Open in new window

0
Comment
Question by:cstormer
  • 2
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22663088
>>What I want to know is if it is possible or not to use php inside of javascript.
That should work ok. The Google code requires just "plain" javascript, but the php code you supplied is  executed on the server and the value of $amount should be seen in the javascript code only, not the php.

NOTE: for it work, the file containing the code you posted above should be a .php file, not a .js file.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22668847
glad to help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Permalink issue in Wordpress archive 1 32
php string masking 4 27
is this a cms? 8 32
javascript date picker in php while loop 5 20
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now